Class OpenIddictTokenManager<TToken>
Provides methods allowing to manage the tokens stored in the store.
Inheritance
Namespace: OpenIddict.Core
Assembly: cs.temp.dll.dll
Syntax
public class OpenIddictTokenManager<TToken> : IOpenIddictTokenManager where TToken : class
Type Parameters
Name | Description |
---|---|
TToken | The type of the Token entity. |
Remarks
Applications that do not want to depend on a specific entity type can use the non-generic
Constructors
OpenIddictTokenManager(IOpenIddictTokenCache<TToken>, ILogger<OpenIddictTokenManager<TToken>>, IOptionsMonitor<OpenIddictCoreOptions>, IOpenIddictTokenStoreResolver)
Declaration
public OpenIddictTokenManager(IOpenIddictTokenCache<TToken> cache, ILogger<OpenIddictTokenManager<TToken>> logger, IOptionsMonitor<OpenIddictCoreOptions> options, IOpenIddictTokenStoreResolver resolver)
Parameters
Type | Name | Description |
---|---|---|
IOpenIddictTokenCache<TToken> | cache | |
ILogger<OpenIddictTokenManager<TToken>> | logger | |
IOptionsMonitor<OpenIddictCoreOptions> | options | |
IOpenIddictTokenStoreResolver | resolver |
Properties
Cache
Gets the cache associated with the current manager.
Declaration
protected IOpenIddictTokenCache<TToken> Cache { get; }
Property Value
Type | Description |
---|---|
IOpenIddictTokenCache<TToken> |
Logger
Gets the logger associated with the current manager.
Declaration
protected ILogger Logger { get; }
Property Value
Type | Description |
---|---|
ILogger |
Options
Gets the options associated with the current manager.
Declaration
protected IOptionsMonitor<OpenIddictCoreOptions> Options { get; }
Property Value
Type | Description |
---|---|
IOptionsMonitor<OpenIddictCoreOptions> |
Store
Gets the store associated with the current manager.
Declaration
protected IOpenIddictTokenStore<TToken> Store { get; }
Property Value
Type | Description |
---|---|
IOpenIddictTokenStore<TToken> |
Methods
CountAsync(CancellationToken)
Determines the number of tokens that exist in the database.
Declaration
public virtual ValueTask<long> CountAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Int64> | A |
CountAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>>, CancellationToken)
Determines the number of tokens that match the specified query.
Declaration
public virtual ValueTask<long> CountAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IQueryable<TToken>, IQueryable<TResult>> | query | The query to execute. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Int64> | A |
Type Parameters
Name | Description |
---|---|
TResult | The result type. |
CreateAsync(TToken, CancellationToken)
Creates a new token.
Declaration
public virtual ValueTask CreateAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask | A |
CreateAsync(OpenIddictTokenDescriptor, CancellationToken)
Creates a new token based on the specified descriptor.
Declaration
public virtual ValueTask<TToken> CreateAsync(OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
OpenIddictTokenDescriptor | descriptor | The token descriptor. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<TToken> | A |
DeleteAsync(TToken, CancellationToken)
Removes an existing token.
Declaration
public virtual ValueTask DeleteAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token to delete. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask | A |
FindAsync(String, String, CancellationToken)
Retrieves the tokens corresponding to the specified subject and associated with the application identifier.
Declaration
public virtual IAsyncEnumerable<TToken> FindAsync(string subject, string client, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | subject | The subject associated with the token. |
System.String | client | The client associated with the token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TToken> | The tokens corresponding to the subject/client. |
FindAsync(String, String, String, CancellationToken)
Retrieves the tokens matching the specified parameters.
Declaration
public virtual IAsyncEnumerable<TToken> FindAsync(string subject, string client, string status, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | subject | The subject associated with the token. |
System.String | client | The client associated with the token. |
System.String | status | The token status. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TToken> | The tokens corresponding to the criteria. |
FindAsync(String, String, String, String, CancellationToken)
Retrieves the tokens matching the specified parameters.
Declaration
public virtual IAsyncEnumerable<TToken> FindAsync(string subject, string client, string status, string type, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | subject | The subject associated with the token. |
System.String | client | The client associated with the token. |
System.String | status | The token status. |
System.String | type | The token type. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TToken> | Tokens corresponding to the criteria. |
FindByApplicationIdAsync(String, CancellationToken)
Retrieves the list of tokens corresponding to the specified application identifier.
Declaration
public virtual IAsyncEnumerable<TToken> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | identifier | The application identifier associated with the tokens. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TToken> | The tokens corresponding to the specified application. |
FindByAuthorizationIdAsync(String, CancellationToken)
Retrieves the list of tokens corresponding to the specified authorization identifier.
Declaration
public virtual IAsyncEnumerable<TToken> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | identifier | The authorization identifier associated with the tokens. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TToken> | The tokens corresponding to the specified authorization. |
FindByIdAsync(String, CancellationToken)
Retrieves a token using its unique identifier.
Declaration
public virtual ValueTask<TToken> FindByIdAsync(string identifier, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | identifier | The unique identifier associated with the token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<TToken> | A |
FindByReferenceIdAsync(String, CancellationToken)
Retrieves the list of tokens corresponding to the specified reference identifier. Note: the reference identifier may be hashed or encrypted for security reasons.
Declaration
public virtual ValueTask<TToken> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | identifier | The reference identifier associated with the tokens. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<TToken> | A |
FindBySubjectAsync(String, CancellationToken)
Retrieves the list of tokens corresponding to the specified subject.
Declaration
public virtual IAsyncEnumerable<TToken> FindBySubjectAsync(string subject, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | subject | The subject associated with the tokens. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TToken> | The tokens corresponding to the specified subject. |
GetApplicationIdAsync(TToken, CancellationToken)
Retrieves the optional application identifier associated with a token.
Declaration
public virtual ValueTask<string> GetApplicationIdAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
GetAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>>, CancellationToken)
Executes the specified query and returns the first element.
Declaration
public virtual ValueTask<TResult> GetAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IQueryable<TToken>, IQueryable<TResult>> | query | The query to execute. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<TResult> | A |
Type Parameters
Name | Description |
---|---|
TResult | The result type. |
GetAsync<TState, TResult>(Func<IQueryable<TToken>, TState, IQueryable<TResult>>, TState, CancellationToken)
Executes the specified query and returns the first element.
Declaration
public virtual ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<TToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IQueryable<TToken>, TState, IQueryable<TResult>> | query | The query to execute. |
TState | state | The optional state. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<TResult> | A |
Type Parameters
Name | Description |
---|---|
TState | The state type. |
TResult | The result type. |
GetAuthorizationIdAsync(TToken, CancellationToken)
Retrieves the optional authorization identifier associated with a token.
Declaration
public virtual ValueTask<string> GetAuthorizationIdAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
GetCreationDateAsync(TToken, CancellationToken)
Retrieves the creation date associated with a token.
Declaration
public virtual ValueTask<DateTimeOffset?> GetCreationDateAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Nullable<System.DateTimeOffset>> | A |
GetExpirationDateAsync(TToken, CancellationToken)
Retrieves the expiration date associated with a token.
Declaration
public virtual ValueTask<DateTimeOffset?> GetExpirationDateAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Nullable<System.DateTimeOffset>> | A |
GetIdAsync(TToken, CancellationToken)
Retrieves the unique identifier associated with a token.
Declaration
public virtual ValueTask<string> GetIdAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
GetPayloadAsync(TToken, CancellationToken)
Retrieves the payload associated with a token.
Declaration
public virtual ValueTask<string> GetPayloadAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
GetPropertiesAsync(TToken, CancellationToken)
Retrieves the additional properties associated with a token.
Declaration
public virtual ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<ImmutableDictionary<System.String, JsonElement>> | A |
GetRedemptionDateAsync(TToken, CancellationToken)
Retrieves the redemption date associated with a token.
Declaration
public virtual ValueTask<DateTimeOffset?> GetRedemptionDateAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Nullable<System.DateTimeOffset>> | A |
GetReferenceIdAsync(TToken, CancellationToken)
Retrieves the reference identifier associated with a token. Note: depending on the manager used to create the token, the reference identifier may be hashed for security reasons.
Declaration
public virtual ValueTask<string> GetReferenceIdAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
GetStatusAsync(TToken, CancellationToken)
Retrieves the status associated with a token.
Declaration
public virtual ValueTask<string> GetStatusAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
GetSubjectAsync(TToken, CancellationToken)
Retrieves the subject associated with a token.
Declaration
public virtual ValueTask<string> GetSubjectAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
GetTypeAsync(TToken, CancellationToken)
Retrieves the token type associated with a token.
Declaration
public virtual ValueTask<string> GetTypeAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
HasStatusAsync(TToken, String, CancellationToken)
Determines whether a given token has the specified status.
Declaration
public virtual ValueTask<bool> HasStatusAsync(TToken token, string status, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
System.String | status | The expected status. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Boolean> |
|
HasTypeAsync(TToken, String, CancellationToken)
Determines whether a given token has the specified type.
Declaration
public virtual ValueTask<bool> HasTypeAsync(TToken token, string type, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
System.String | type | The expected type. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Boolean> |
|
ListAsync(Nullable<Int32>, Nullable<Int32>, CancellationToken)
Executes the specified query and returns all the corresponding elements.
Declaration
public virtual IAsyncEnumerable<TToken> ListAsync(int? count = default(int? ), int? offset = default(int? ), CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int32> | count | The number of results to return. |
System.Nullable<System.Int32> | offset | The number of results to skip. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TToken> | All the elements returned when executing the specified query. |
ListAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>>, CancellationToken)
Executes the specified query and returns all the corresponding elements.
Declaration
public virtual IAsyncEnumerable<TResult> ListAsync<TResult>(Func<IQueryable<TToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IQueryable<TToken>, IQueryable<TResult>> | query | The query to execute. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TResult> | All the elements returned when executing the specified query. |
Type Parameters
Name | Description |
---|---|
TResult | The result type. |
ListAsync<TState, TResult>(Func<IQueryable<TToken>, TState, IQueryable<TResult>>, TState, CancellationToken)
Executes the specified query and returns all the corresponding elements.
Declaration
public virtual IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<TToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<IQueryable<TToken>, TState, IQueryable<TResult>> | query | The query to execute. |
TState | state | The optional state. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TResult> | All the elements returned when executing the specified query. |
Type Parameters
Name | Description |
---|---|
TState | The state type. |
TResult | The result type. |
ObfuscateReferenceIdAsync(String, CancellationToken)
Obfuscates the specified reference identifier so it can be safely stored in a database. By default, this method returns a simple hashed representation computed using SHA256.
Declaration
protected virtual ValueTask<string> ObfuscateReferenceIdAsync(string identifier, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | identifier | The client identifier. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.String> | A |
PopulateAsync(TToken, OpenIddictTokenDescriptor, CancellationToken)
Populates the token using the specified descriptor.
Declaration
public virtual ValueTask PopulateAsync(TToken token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
OpenIddictTokenDescriptor | descriptor | The descriptor. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask | A |
PopulateAsync(OpenIddictTokenDescriptor, TToken, CancellationToken)
Populates the specified descriptor using the properties exposed by the token.
Declaration
public virtual ValueTask PopulateAsync(OpenIddictTokenDescriptor descriptor, TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
OpenIddictTokenDescriptor | descriptor | The descriptor. |
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask | A |
PruneAsync(DateTimeOffset, CancellationToken)
Removes the tokens that are marked as invalid or whose attached authorization is no longer valid.
Only tokens created before the specified threshold
are removed.
Declaration
public virtual ValueTask PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.DateTimeOffset | threshold | The date before which tokens are not pruned. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask | A |
TryRedeemAsync(TToken, CancellationToken)
Tries to redeem a token.
Declaration
public virtual ValueTask<bool> TryRedeemAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token to redeem. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Boolean> |
|
TryRejectAsync(TToken, CancellationToken)
Tries to reject a token.
Declaration
public virtual ValueTask<bool> TryRejectAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token to reject. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Boolean> |
|
TryRevokeAsync(TToken, CancellationToken)
Tries to revoke a token.
Declaration
public virtual ValueTask<bool> TryRevokeAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token to revoke. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask<System.Boolean> |
|
UpdateAsync(TToken, CancellationToken)
Updates an existing token.
Declaration
public virtual ValueTask UpdateAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token to update. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask | A |
UpdateAsync(TToken, OpenIddictTokenDescriptor, CancellationToken)
Updates an existing token.
Declaration
public virtual ValueTask UpdateAsync(TToken token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token to update. |
OpenIddictTokenDescriptor | descriptor | The descriptor used to update the token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
ValueTask | A |
ValidateAsync(TToken, CancellationToken)
Validates the token to ensure it's in a consistent state.
Declaration
public virtual IAsyncEnumerable<ValidationResult> ValidateAsync(TToken token, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TToken | token | The token. |
CancellationToken | cancellationToken | The |
Returns
Type | Description |
---|---|
IAsyncEnumerable<ValidationResult> | The validation error encountered when validating the token. |