Class SessionKeyTicketStore
Wraps the session store of the authentication cookie so the ticket it hands back carries its own session key as the SessionKey claim.
public sealed class SessionKeyTicketStore : ITicketStore
- Inheritance
-
SessionKeyTicketStore
- Implements
- Inherited Members
Remarks
With a session store, the cookie holds only the session key and the ticket lives in the store. The cookie handler reads the key out of the cookie but does not put it on the principal it returns, so nothing downstream of authentication (in particular a Blazor circuit, which only sees the principal) can tell which session it belongs to. Stamping the key when the ticket is read lets that code ask the store whether the session still exists: sign-out removes it, and so does its expiry. The key is stamped on every read, so the sessions created before this store was added carry it too.
The claim is never persisted: it is removed from the ticket before it is stored or renewed, and a stale value is replaced on every read. The stored ticket is never modified, as a copy is stamped. The claim must never be sent to a browser: see AuthenticationStateClaimsSerializer.
AddAppPrincipalCircuitRevalidation wraps the session store of the cookie with it. Only applications with Blazor circuits get the
claim: an MVC or Razor Pages application has no use for it.
Constructors
SessionKeyTicketStore(ITicketStore)
Initializes a new instance of the SessionKeyTicketStore class.
public SessionKeyTicketStore(ITicketStore inner)
Parameters
innerITicketStoreThe store that keeps the tickets.
Exceptions
- ArgumentNullException
inneris null.
Properties
Inner
Gets the store this one wraps.
public ITicketStore Inner { get; }
Property Value
Methods
RemoveAsync(string)
Remove the identity associated with the given key.
public Task RemoveAsync(string key)
Parameters
keystringThe key associated with the identity.
Returns
RemoveAsync(string, HttpContext, CancellationToken)
Remove the identity associated with the given key.
public Task RemoveAsync(string key, HttpContext httpContext, CancellationToken cancellationToken)
Parameters
keystringThe key associated with the identity.
httpContextHttpContextThe HttpContext associated with the current request.
cancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
RemoveAsync(string, CancellationToken)
Remove the identity associated with the given key.
public Task RemoveAsync(string key, CancellationToken cancellationToken)
Parameters
keystringThe key associated with the identity.
cancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
RenewAsync(string, AuthenticationTicket)
Tells the store that the given identity should be updated.
public Task RenewAsync(string key, AuthenticationTicket ticket)
Parameters
keystringticketAuthenticationTicket
Returns
RenewAsync(string, AuthenticationTicket, HttpContext, CancellationToken)
Tells the store that the given identity should be updated.
public Task RenewAsync(string key, AuthenticationTicket ticket, HttpContext httpContext, CancellationToken cancellationToken)
Parameters
keystringticketAuthenticationTickethttpContextHttpContextcancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
RenewAsync(string, AuthenticationTicket, CancellationToken)
Tells the store that the given identity should be updated.
public Task RenewAsync(string key, AuthenticationTicket ticket, CancellationToken cancellationToken)
Parameters
keystringticketAuthenticationTicketcancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
RetrieveAsync(string)
Retrieves an identity from the store for the given key.
public Task<AuthenticationTicket?> RetrieveAsync(string key)
Parameters
keystringThe key associated with the identity.
Returns
- Task<AuthenticationTicket>
The identity associated with the given key, or
nullif not found.
RetrieveAsync(string, HttpContext, CancellationToken)
Retrieves an identity from the store for the given key.
public Task<AuthenticationTicket?> RetrieveAsync(string key, HttpContext httpContext, CancellationToken cancellationToken)
Parameters
keystringThe key associated with the identity.
httpContextHttpContextThe HttpContext associated with the current request.
cancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
- Task<AuthenticationTicket>
The identity associated with the given key, or
nullif not found.
RetrieveAsync(string, CancellationToken)
Retrieves an identity from the store for the given key.
public Task<AuthenticationTicket?> RetrieveAsync(string key, CancellationToken cancellationToken)
Parameters
keystringThe key associated with the identity.
cancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
- Task<AuthenticationTicket>
The identity associated with the given key, or
nullif not found.
StoreAsync(AuthenticationTicket)
Store the identity ticket and return the associated key.
public Task<string> StoreAsync(AuthenticationTicket ticket)
Parameters
ticketAuthenticationTicketThe identity information to store.
Returns
StoreAsync(AuthenticationTicket, HttpContext, CancellationToken)
Store the identity ticket and return the associated key.
public Task<string> StoreAsync(AuthenticationTicket ticket, HttpContext httpContext, CancellationToken cancellationToken)
Parameters
ticketAuthenticationTicketThe identity information to store.
httpContextHttpContextThe HttpContext associated with the current request.
cancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
StoreAsync(AuthenticationTicket, CancellationToken)
Store the identity ticket and return the associated key.
public Task<string> StoreAsync(AuthenticationTicket ticket, CancellationToken cancellationToken)
Parameters
ticketAuthenticationTicketThe identity information to store.
cancellationTokenCancellationTokenThe CancellationToken used to propagate notifications that the operation should be canceled.
Returns
Wrap(CookieAuthenticationOptions)
Wraps the session store of options, if it has one and it is not already wrapped.
public static void Wrap(CookieAuthenticationOptions options)
Parameters
optionsCookieAuthenticationOptionsThe cookie options.
Exceptions
- ArgumentNullException
optionsis null.
Wrap(ITicketStore)
Wraps store, unless it is already a SessionKeyTicketStore.
public static SessionKeyTicketStore Wrap(ITicketStore store)
Parameters
storeITicketStoreThe store to wrap.
Returns
- SessionKeyTicketStore
A SessionKeyTicketStore over
store.
Exceptions
- ArgumentNullException
storeis null.