Class FileTicketStore
- Namespace
- Arc4u.OAuth2.TicketStore
- Assembly
- Arc4u.OAuth2.AspNetCore.Authentication.dll
An ITicketStore that keeps each authentication ticket in a file ({guid}.bin) of the directory configured in
StorePath, 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 directory. It is meant
for a single instance application.
public class FileTicketStore : ITicketStore
- Inheritance
-
FileTicketStore
- Implements
- Inherited Members
Remarks
A file 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 file is deleted.
Constructors
FileTicketStore(ILogger<FileTicketStore>, IOptionsMonitor<FileTicketStoreOptions>, IDataProtectionProvider)
Initializes a new instance of the FileTicketStore class.
public FileTicketStore(ILogger<FileTicketStore> logger, IOptionsMonitor<FileTicketStoreOptions> options, IDataProtectionProvider dataProtectionProvider)
Parameters
loggerILogger<FileTicketStore>The logger.
optionsIOptionsMonitor<FileTicketStoreOptions>The options giving the directory of the tickets.
dataProtectionProviderIDataProtectionProviderThe Data Protection provider that encrypts the tickets.
Exceptions
- ArgumentNullException
The store path or
dataProtectionProvideris 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
keystringThe key associated with the identity.
Returns
RenewAsync(string, AuthenticationTicket)
Tells the store that the given identity should be updated.
public Task RenewAsync(string key, AuthenticationTicket ticket)
Parameters
keystringticketAuthenticationTicket
Returns
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
keyholds 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
keystringThe key associated with the identity.
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.