Class TokenCacheExtension
- Namespace
- Arc4u.OAuth2.Extensions
- Assembly
- Arc4u.OAuth2.dll
Registers the TokenCacheOptions.
public static class TokenCacheExtension
- Inheritance
-
TokenCacheExtension
- Inherited Members
Methods
AddNamedTokenCache(IServiceCollection, string, IConfigurationSection, string?)
Registers named TokenCacheOptions from a configuration section holding CacheName and MaxTime. A value that is not in the section is taken
from the fallbackName options, or from the default TokenCacheOptions when it is null.
public static void AddNamedTokenCache(this IServiceCollection services, string name, IConfigurationSection section, string? fallbackName = null)
Parameters
servicesIServiceCollectionThe service collection.
namestringThe name of the options, passed as
optionsNameto theITokenCache.sectionIConfigurationSectionThe section to read.
fallbackNamestringThe name of the options giving the values that are not in the section, or null for the default options.
Exceptions
- ConfigurationException
The
MaxTimeof the section is not greater than zero.
AddNamedTokenCache(IServiceCollection, string, string?, TimeSpan?, string?)
Registers named TokenCacheOptions. A value that is not given is taken, when the options are created, from the fallbackName options,
or from the default TokenCacheOptions when it is null.
public static void AddNamedTokenCache(this IServiceCollection services, string name, string? cacheName, TimeSpan? maxTime, string? fallbackName = null)
Parameters
servicesIServiceCollectionThe service collection.
namestringThe name of the options, passed as
optionsNameto theITokenCache.cacheNamestringThe name of the cache, or null to take the one of the fallback options.
maxTimeTimeSpan?The time after which a cached token is evicted, or null to take the one of the fallback options.
fallbackNamestringThe name of the options giving the values that are not given, or null for the default options.
Examples
services.AddNamedTokenCache("DownstreamApi", cacheName: "Redis", maxTime: TimeSpan.FromMinutes(10));
Exceptions
- ConfigurationException
maxTimeis not greater than zero.
AddSharedTokenCache(IServiceCollection, IConfiguration, string, string, IEnumerable<string>)
Registers the TokenCacheOptions shared by the entries of a section (for example Authentication:ClientTokens) from the
sectionName section, as named options name. A value that is not in the section is taken from the default TokenCacheOptions.
public static string? AddSharedTokenCache(this IServiceCollection services, IConfiguration configuration, string sectionName, string name, IEnumerable<string> entryKeys)
Parameters
servicesIServiceCollectionThe service collection.
configurationIConfigurationThe configuration.
sectionNamestringThe section holding the shared
CacheNameandMaxTime, for exampleAuthentication:ClientTokensCache; empty for none.namestringThe name of the shared options, reserved: no entry can have it.
entryKeysIEnumerable<string>The keys of the entries that use the shared options.
Returns
- string
name, or null whensectionNameis empty or the section does not exist (the entries then use the default options).
Exceptions
- ConfigurationException
An entry is named
name(ignoring case), or theMaxTimeof the section is not greater than zero.
AddTokenCache(IServiceCollection, IConfiguration, string)
Registers the token cache options from a configuration section.
public static void AddTokenCache(this IServiceCollection services, IConfiguration configuration, string sectionName = "Authentication:TokenCache")
Parameters
servicesIServiceCollectionThe service collection.
configurationIConfigurationThe configuration.
sectionNamestringThe section to bind. The default is
Authentication:TokenCache.MaxTimekeeps its default (50 minutes) when it is not in the section.
Examples
services.AddTokenCache(configuration);
Exceptions
AddTokenCache(IServiceCollection, Action<TokenCacheOptions>)
Registers the token cache options from code.
public static void AddTokenCache(this IServiceCollection services, Action<TokenCacheOptions> options)
Parameters
servicesIServiceCollectionThe service collection.
optionsAction<TokenCacheOptions>The action that configures the options.
Examples
services.AddTokenCache(o =>
{
o.CacheName = "Token";
o.MaxTime = TimeSpan.FromMinutes(30);
});
Exceptions
AddTokenCacheResolver(IServiceCollection)
Registers the TokenCacheResolver, once, as a singleton: it resolves the cache of the default or named TokenCacheOptions for
ApplicationCache and the token providers. AddTokenCache, AddJwtAuthentication, AddClientTokens, AddOnBehalfOf,
AddOnBehalfOfSettings and AddBasicAuthenticationSettings call it; call it yourself when you register ApplicationCache without them.
public static void AddTokenCacheResolver(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.