Table of Contents

Interface IOpenIddictTokenManager

Namespace
OpenIddict.Abstractions
Assembly
OpenIddict.Abstractions.dll

Provides methods allowing to manage the tokens stored in the store. Note: this interface is not meant to be implemented by custom managers, that should inherit from the generic OpenIddictTokenManager class. It is primarily intended to be used by services that cannot easily depend on the generic token manager. The actual token entity type is automatically determined at runtime based on the OpenIddict core options.

public interface IOpenIddictTokenManager

Methods

CountAsync(CancellationToken)

Determines the number of tokens that exist in the database.

ValueTask<long> CountAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<long>

A ValueTask that can be used to monitor the asynchronous operation, whose result returns the number of tokens in the database.

CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>>, CancellationToken)

Determines the number of tokens that match the specified query.

ValueTask<long> CountAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)

Parameters

query Func<IQueryable<object>, IQueryable<TResult>>

The query to execute.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<long>

A ValueTask that can be used to monitor the asynchronous operation, whose result returns the number of tokens that match the specified query.

Type Parameters

TResult

The result type.

CreateAsync(OpenIddictTokenDescriptor, CancellationToken)

Creates a new token based on the specified descriptor.

ValueTask<object> CreateAsync(OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)

Parameters

descriptor OpenIddictTokenDescriptor

The token descriptor.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<object>

A ValueTask that can be used to monitor the asynchronous operation, whose result returns the token.

CreateAsync(object, CancellationToken)

Creates a new token.

ValueTask CreateAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask

A ValueTask that can be used to monitor the asynchronous operation.

DeleteAsync(object, CancellationToken)

Removes an existing token.

ValueTask DeleteAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token to delete.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask

A ValueTask that can be used to monitor the asynchronous operation.

FindAsync(string, string, string, string, CancellationToken)

Retrieves the tokens matching the specified parameters.

IAsyncEnumerable<object> FindAsync(string subject, string client, string status, string type, CancellationToken cancellationToken = default)

Parameters

subject string

The subject associated with the token.

client string

The client associated with the token.

status string

The token status.

type string

The token type.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<object>

The tokens corresponding to the criteria.

FindAsync(string, string, string, CancellationToken)

Retrieves the tokens matching the specified parameters.

IAsyncEnumerable<object> FindAsync(string subject, string client, string status, CancellationToken cancellationToken = default)

Parameters

subject string

The subject associated with the token.

client string

The client associated with the token.

status string

The token status.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<object>

The tokens corresponding to the criteria.

FindAsync(string, string, CancellationToken)

Retrieves the tokens corresponding to the specified subject and associated with the application identifier.

IAsyncEnumerable<object> FindAsync(string subject, string client, CancellationToken cancellationToken = default)

Parameters

subject string

The subject associated with the token.

client string

The client associated with the token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<object>

The tokens corresponding to the subject/client.

FindByApplicationIdAsync(string, CancellationToken)

Retrieves the list of tokens corresponding to the specified application identifier.

IAsyncEnumerable<object> FindByApplicationIdAsync(string identifier, CancellationToken cancellationToken = default)

Parameters

identifier string

The application identifier associated with the tokens.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<object>

The tokens corresponding to the specified application.

FindByAuthorizationIdAsync(string, CancellationToken)

Retrieves the list of tokens corresponding to the specified authorization identifier.

IAsyncEnumerable<object> FindByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken = default)

Parameters

identifier string

The authorization identifier associated with the tokens.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<object>

The tokens corresponding to the specified authorization.

FindByIdAsync(string, CancellationToken)

Retrieves a token using its unique identifier.

ValueTask<object?> FindByIdAsync(string identifier, CancellationToken cancellationToken = default)

Parameters

identifier string

The unique identifier associated with the token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<object>

A ValueTask that can be used to monitor the asynchronous operation, whose result returns the token corresponding to the unique identifier.

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.

ValueTask<object?> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken = default)

Parameters

identifier string

The reference identifier associated with the tokens.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<object>

A ValueTask that can be used to monitor the asynchronous operation, whose result returns the tokens corresponding to the specified reference identifier.

FindBySubjectAsync(string, CancellationToken)

Retrieves the list of tokens corresponding to the specified subject.

IAsyncEnumerable<object> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default)

Parameters

subject string

The subject associated with the tokens.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<object>

The tokens corresponding to the specified subject.

GetApplicationIdAsync(object, CancellationToken)

Retrieves the optional application identifier associated with a token.

ValueTask<string?> GetApplicationIdAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the application identifier associated with the token.

GetAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>>, CancellationToken)

Executes the specified query and returns the first element.

ValueTask<TResult?> GetAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)

Parameters

query Func<IQueryable<object>, IQueryable<TResult>>

The query to execute.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<TResult>

A ValueTask that can be used to monitor the asynchronous operation, whose result returns the first element returned when executing the query.

Type Parameters

TResult

The result type.

GetAsync<TState, TResult>(Func<IQueryable<object>, TState, IQueryable<TResult>>, TState, CancellationToken)

Executes the specified query and returns the first element.

ValueTask<TResult?> GetAsync<TState, TResult>(Func<IQueryable<object>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)

Parameters

query Func<IQueryable<object>, TState, IQueryable<TResult>>

The query to execute.

state TState

The optional state.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<TResult>

A ValueTask that can be used to monitor the asynchronous operation, whose result returns the first element returned when executing the query.

Type Parameters

TState

The state type.

TResult

The result type.

GetAuthorizationIdAsync(object, CancellationToken)

Retrieves the optional authorization identifier associated with a token.

ValueTask<string?> GetAuthorizationIdAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the authorization identifier associated with the token.

GetCreationDateAsync(object, CancellationToken)

Retrieves the creation date associated with a token.

ValueTask<DateTimeOffset?> GetCreationDateAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<DateTimeOffset?>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the creation date associated with the specified token.

GetExpirationDateAsync(object, CancellationToken)

Retrieves the expiration date associated with a token.

ValueTask<DateTimeOffset?> GetExpirationDateAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<DateTimeOffset?>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the expiration date associated with the specified token.

GetIdAsync(object, CancellationToken)

Retrieves the unique identifier associated with a token.

ValueTask<string?> GetIdAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the unique identifier associated with the token.

GetPayloadAsync(object, CancellationToken)

Retrieves the payload associated with a token.

ValueTask<string?> GetPayloadAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the payload associated with the specified token.

GetPropertiesAsync(object, CancellationToken)

Retrieves the additional properties associated with a token.

ValueTask<ImmutableDictionary<string, JsonElement>> GetPropertiesAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<ImmutableDictionary<string, JsonElement>>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns all the additional properties associated with the token.

GetRedemptionDateAsync(object, CancellationToken)

Retrieves the redemption date associated with a token.

ValueTask<DateTimeOffset?> GetRedemptionDateAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<DateTimeOffset?>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the redemption date associated with the specified token.

GetReferenceIdAsync(object, 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.

ValueTask<string?> GetReferenceIdAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the reference identifier associated with the specified token.

GetStatusAsync(object, CancellationToken)

Retrieves the status associated with a token.

ValueTask<string?> GetStatusAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the status associated with the specified token.

GetSubjectAsync(object, CancellationToken)

Retrieves the subject associated with a token.

ValueTask<string?> GetSubjectAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the subject associated with the specified token.

GetTypeAsync(object, CancellationToken)

Retrieves the token type associated with a token.

ValueTask<string?> GetTypeAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<string>

A ValueTask<TResult> that can be used to monitor the asynchronous operation, whose result returns the token type associated with the specified token.

HasStatusAsync(object, string, CancellationToken)

Determines whether a given token has the specified status.

ValueTask<bool> HasStatusAsync(object token, string status, CancellationToken cancellationToken = default)

Parameters

token object

The token.

status string

The expected status.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<bool>

true if the token has the specified status, false otherwise.

HasTypeAsync(object, ImmutableArray<string>, CancellationToken)

Determines whether a given token has any of the specified types.

ValueTask<bool> HasTypeAsync(object token, ImmutableArray<string> types, CancellationToken cancellationToken = default)

Parameters

token object

The token.

types ImmutableArray<string>

The expected types.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<bool>

true if the token has any of the specified types, false otherwise.

HasTypeAsync(object, string, CancellationToken)

Determines whether a given token has the specified type.

ValueTask<bool> HasTypeAsync(object token, string type, CancellationToken cancellationToken = default)

Parameters

token object

The token.

type string

The expected type.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<bool>

true if the token has the specified type, false otherwise.

ListAsync(int?, int?, CancellationToken)

Executes the specified query and returns all the corresponding elements.

IAsyncEnumerable<object> ListAsync(int? count = null, int? offset = null, CancellationToken cancellationToken = default)

Parameters

count int?

The number of results to return.

offset int?

The number of results to skip.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<object>

All the elements returned when executing the specified query.

ListAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>>, CancellationToken)

Executes the specified query and returns all the corresponding elements.

IAsyncEnumerable<TResult> ListAsync<TResult>(Func<IQueryable<object>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)

Parameters

query Func<IQueryable<object>, IQueryable<TResult>>

The query to execute.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<TResult>

All the elements returned when executing the specified query.

Type Parameters

TResult

The result type.

ListAsync<TState, TResult>(Func<IQueryable<object>, TState, IQueryable<TResult>>, TState, CancellationToken)

Executes the specified query and returns all the corresponding elements.

IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<object>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)

Parameters

query Func<IQueryable<object>, TState, IQueryable<TResult>>

The query to execute.

state TState

The optional state.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<TResult>

All the elements returned when executing the specified query.

Type Parameters

TState

The state type.

TResult

The result type.

PopulateAsync(OpenIddictTokenDescriptor, object, CancellationToken)

Populates the specified descriptor using the properties exposed by the token.

ValueTask PopulateAsync(OpenIddictTokenDescriptor descriptor, object token, CancellationToken cancellationToken = default)

Parameters

descriptor OpenIddictTokenDescriptor

The descriptor.

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask

A ValueTask that can be used to monitor the asynchronous operation.

PopulateAsync(object, OpenIddictTokenDescriptor, CancellationToken)

Populates the token using the specified descriptor.

ValueTask PopulateAsync(object token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)

Parameters

token object

The token.

descriptor OpenIddictTokenDescriptor

The descriptor.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask

A ValueTask that can be used to monitor the asynchronous operation.

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.

ValueTask<long> PruneAsync(DateTimeOffset threshold, CancellationToken cancellationToken = default)

Parameters

threshold DateTimeOffset

The date before which tokens are not pruned.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<long>

The number of tokens that were removed.

RevokeByAuthorizationIdAsync(string, CancellationToken)

Revokes all the tokens associated with the specified authorization identifier.

ValueTask<long> RevokeByAuthorizationIdAsync(string identifier, CancellationToken cancellationToken = default)

Parameters

identifier string

The authorization identifier associated with the tokens.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<long>

The number of tokens associated with the specified authorization that were marked as revoked.

TryRedeemAsync(object, CancellationToken)

Tries to redeem a token.

ValueTask<bool> TryRedeemAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token to redeem.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<bool>

true if the token was successfully redemeed, false otherwise.

TryRejectAsync(object, CancellationToken)

Tries to reject a token.

ValueTask<bool> TryRejectAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token to reject.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<bool>

true if the token was successfully redemeed, false otherwise.

TryRevokeAsync(object, CancellationToken)

Tries to revoke a token.

ValueTask<bool> TryRevokeAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token to revoke.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask<bool>

true if the token was successfully revoked, false otherwise.

UpdateAsync(object, OpenIddictTokenDescriptor, CancellationToken)

Updates an existing token.

ValueTask UpdateAsync(object token, OpenIddictTokenDescriptor descriptor, CancellationToken cancellationToken = default)

Parameters

token object

The token to update.

descriptor OpenIddictTokenDescriptor

The descriptor used to update the token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask

A ValueTask that can be used to monitor the asynchronous operation.

UpdateAsync(object, CancellationToken)

Updates an existing token.

ValueTask UpdateAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token to update.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

ValueTask

A ValueTask that can be used to monitor the asynchronous operation.

ValidateAsync(object, CancellationToken)

Validates the token to ensure it's in a consistent state.

IAsyncEnumerable<ValidationResult> ValidateAsync(object token, CancellationToken cancellationToken = default)

Parameters

token object

The token.

cancellationToken CancellationToken

The CancellationToken that can be used to abort the operation.

Returns

IAsyncEnumerable<ValidationResult>

The validation error encountered when validating the token.