Table of Contents

Class CacheTicketStore

Namespace
Arc4u.OAuth2.TicketStore
Assembly
Arc4u.OAuth2.AspNetCore.Authentication.dll

An ITicketStore that keeps the authentication tickets in an Arc4u cache. Each ticket is stored under a key made of KeyPrefix and a new guid, encrypted with Data Protection (purpose DataProtectionPurpose): a ticket carries the user's access, id and refresh tokens, which must not be readable by whoever can read the cache.

public class CacheTicketStore : ITicketStore
Inheritance
CacheTicketStore
Implements
Inherited Members

Remarks

An entry that cannot be unprotected (written in clear by a previous version, or under a key ring that no longer exists) reads as no ticket: the user signs in again, and the entry is removed so its tokens leave the cache at once.

Constructors

CacheTicketStore(ILogger<CacheTicketStore>, ICacheContext, IOptionsMonitor<CacheTicketStoreOptions>, IDataProtectionProvider)

Initializes a new instance of the CacheTicketStore class.

public CacheTicketStore(ILogger<CacheTicketStore> logger, ICacheContext cacheContext, IOptionsMonitor<CacheTicketStoreOptions> options, IDataProtectionProvider dataProtectionProvider)

Parameters

logger ILogger<CacheTicketStore>

The logger.

cacheContext ICacheContext

The context giving access to the registered caches.

options IOptionsMonitor<CacheTicketStoreOptions>

The options giving the name of the cache and the key prefix. When the cache does not exist, the default cache is used.

dataProtectionProvider IDataProtectionProvider

The Data Protection provider that encrypts the tickets. All the instances of the application must share its key ring.

Exceptions

ArgumentNullException

The cache name, the key prefix or dataProtectionProvider is null.

ArgumentException

The Data Protection purpose is empty.

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

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

Remarks

The ticket of another user is never overwritten: that would hand that session to whoever holds the cookie (session fixation).

Exceptions

InvalidOperationException

The session key holds the ticket of another user; the stored ticket is left unchanged.

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.

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.