Class DapperPersistedGrantStore
- Namespace
- Fdyay.IdentityServer.Dapper.Stores
- Assembly
- Fdyay.IdentityServer.Dapper.dll
Dapper-backed persisted grant store.
public sealed class DapperPersistedGrantStore : IPersistedGrantStore
- Inheritance
-
DapperPersistedGrantStore
- Implements
- Inherited Members
Constructors
DapperPersistedGrantStore(IDbConnectionFactory)
Creates a grant store over the PersistedGrants table.
public DapperPersistedGrantStore(IDbConnectionFactory connectionFactory)
Parameters
connectionFactoryIDbConnectionFactoryOpens a connection for each operation and supplies the dialect's upsert.
Methods
GetAllAsync(PersistedGrantFilter, CancellationToken)
Gets all grants matching the filter.
public Task<IEnumerable<PersistedGrant>> GetAllAsync(PersistedGrantFilter filter, CancellationToken cancellationToken = default)
Parameters
filterPersistedGrantFiltercancellationTokenCancellationToken
Returns
Remarks
Reads the PersistedGrants rows matching every field the filter sets (subject, session, client, type),
expired and consumed ones included. No match is an empty sequence.
Exceptions
- ArgumentNullException
filteris null.- ArgumentException
filtersets none of its fields.
GetAsync(string, CancellationToken)
Gets a grant by key, or null if not found.
public Task<PersistedGrant?> GetAsync(string key, CancellationToken cancellationToken = default)
Parameters
keystringcancellationTokenCancellationToken
Returns
Remarks
Reads the PersistedGrants row whose GrantKey matches. A miss returns null. Expired and consumed
rows are returned as stored; deciding whether they can still be redeemed is the caller's.
Exceptions
- ArgumentException
keyis null or empty.
RemoveAllAsync(PersistedGrantFilter, CancellationToken)
Removes all grants matching the filter.
public Task RemoveAllAsync(PersistedGrantFilter filter, CancellationToken cancellationToken = default)
Parameters
filterPersistedGrantFiltercancellationTokenCancellationToken
Returns
Remarks
Deletes the PersistedGrants rows matching every field the filter sets (subject, session, client, type).
No match deletes nothing and is not an error.
Exceptions
- ArgumentNullException
filteris null.- ArgumentException
filtersets none of its fields, which would otherwise delete every grant.
RemoveAsync(string, CancellationToken)
Removes a grant by key.
public Task RemoveAsync(string key, CancellationToken cancellationToken = default)
Parameters
keystringcancellationTokenCancellationToken
Returns
Remarks
Deletes the PersistedGrants row whose GrantKey matches. A miss deletes nothing and is not an error.
Exceptions
- ArgumentException
keyis null or empty.
StoreAsync(PersistedGrant, CancellationToken)
Stores a grant.
public Task StoreAsync(PersistedGrant grant, CancellationToken cancellationToken = default)
Parameters
grantPersistedGrantcancellationTokenCancellationToken
Returns
Remarks
Upserts the PersistedGrants row keyed by GrantKey (the grant's Key):
an existing row is overwritten in full, which is how consuming a grant records its ConsumedTime.
Exceptions
- ArgumentNullException
grantis null.
TryConsumeAsync(string, DateTime, CancellationToken)
Marks a grant consumed at consumedTime, unless it is gone or consumed already.
public Task<bool> TryConsumeAsync(string key, DateTime consumedTime, CancellationToken cancellationToken = default)
Parameters
keystringThe grant's key.
consumedTimeDateTimeWhen it was consumed, written to ConsumedTime.
cancellationTokenCancellationTokenCancels the write.
Returns
- Task<bool>
True when this call consumed the grant; false when it was gone or another call had consumed it.
Remarks
The same guarantee as TryRemoveAsync(string, CancellationToken) for a one-time refresh token, which is consumed rather than removed so that a later presentation is recognised as a replay. The in-memory, Dapper and data-protecting stores consume in one step; this default reads, checks and writes back, as consuming did before 0.176.0.
Exceptions
- ArgumentException
keyis null or empty.
TryRemoveAsync(string, CancellationToken)
Removes a grant by key, saying whether this call is the one that removed it.
public Task<bool> TryRemoveAsync(string key, CancellationToken cancellationToken = default)
Parameters
keystringThe grant's key.
cancellationTokenCancellationTokenCancels the removal.
Returns
Remarks
What makes a one-time grant — an authorization code, a refresh token deleted on use — redeemable once when two requests present it at the same moment: both may read it, and only the one whose removal took it goes on. Ours (security), 0.176.0; Duende's store has no such member and its callers read, then remove.
The in-memory, Dapper and data-protecting stores take the grant in one step. This default, for a store of a host's own written before 0.176.0, reads and then removes — correct, and as open to the race as every store was before; a store that can delete and count the rows deleted in one statement should implement it.
Exceptions
- ArgumentException
keyis null or empty.