Table of Contents

Class SessionKeyTicketStore

Namespace
Arc4u.Blazor
Assembly
Arc4u.OAuth2.AspNetCore.Blazor.dll

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

inner ITicketStore

The store that keeps the tickets.

Exceptions

ArgumentNullException

inner is null.

Properties

Inner

Gets the store this one wraps.

public ITicketStore Inner { get; }

Property Value

ITicketStore

Methods

RemoveAsync(string)

Remove the identity associated with the given key.

public Task RemoveAsync(string key)

Parameters

key string

The key associated with the identity.

Returns

Task

RemoveAsync(string, HttpContext, CancellationToken)

Remove the identity associated with the given key.

public Task RemoveAsync(string key, HttpContext httpContext, CancellationToken cancellationToken)

Parameters

key string

The key associated with the identity.

httpContext HttpContext

The HttpContext associated with the current request.

cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

RemoveAsync(string, CancellationToken)

Remove the identity associated with the given key.

public Task RemoveAsync(string key, CancellationToken cancellationToken)

Parameters

key string

The key associated with the identity.

cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

RenewAsync(string, AuthenticationTicket)

Tells the store that the given identity should be updated.

public Task RenewAsync(string key, AuthenticationTicket ticket)

Parameters

key string
ticket AuthenticationTicket

Returns

Task

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

key string
ticket AuthenticationTicket
httpContext HttpContext
cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

RenewAsync(string, AuthenticationTicket, CancellationToken)

Tells the store that the given identity should be updated.

public Task RenewAsync(string key, AuthenticationTicket ticket, CancellationToken cancellationToken)

Parameters

key string
ticket AuthenticationTicket
cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task

RetrieveAsync(string)

Retrieves an identity from the store for the given key.

public Task<AuthenticationTicket?> RetrieveAsync(string key)

Parameters

key string

The key associated with the identity.

Returns

Task<AuthenticationTicket>

The identity associated with the given key, or null if 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

key string

The key associated with the identity.

httpContext HttpContext

The HttpContext associated with the current request.

cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<AuthenticationTicket>

The identity associated with the given key, or null if not found.

RetrieveAsync(string, CancellationToken)

Retrieves an identity from the store for the given key.

public Task<AuthenticationTicket?> RetrieveAsync(string key, CancellationToken cancellationToken)

Parameters

key string

The key associated with the identity.

cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<AuthenticationTicket>

The identity associated with the given key, or null if not found.

StoreAsync(AuthenticationTicket)

Store the identity ticket and return the associated key.

public Task<string> StoreAsync(AuthenticationTicket ticket)

Parameters

ticket AuthenticationTicket

The identity information to store.

Returns

Task<string>

The key that can be used to retrieve the identity later.

StoreAsync(AuthenticationTicket, HttpContext, CancellationToken)

Store the identity ticket and return the associated key.

public Task<string> StoreAsync(AuthenticationTicket ticket, HttpContext httpContext, CancellationToken cancellationToken)

Parameters

ticket AuthenticationTicket

The identity information to store.

httpContext HttpContext

The HttpContext associated with the current request.

cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The key that can be used to retrieve the identity later.

StoreAsync(AuthenticationTicket, CancellationToken)

Store the identity ticket and return the associated key.

public Task<string> StoreAsync(AuthenticationTicket ticket, CancellationToken cancellationToken)

Parameters

ticket AuthenticationTicket

The identity information to store.

cancellationToken CancellationToken

The CancellationToken used to propagate notifications that the operation should be canceled.

Returns

Task<string>

The key that can be used to retrieve the identity later.

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

options CookieAuthenticationOptions

The cookie options.

Exceptions

ArgumentNullException

options is null.

Wrap(ITicketStore)

Wraps store, unless it is already a SessionKeyTicketStore.

public static SessionKeyTicketStore Wrap(ITicketStore store)

Parameters

store ITicketStore

The store to wrap.

Returns

SessionKeyTicketStore

A SessionKeyTicketStore over store.

Exceptions

ArgumentNullException

store is null.