Table of Contents

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

services IServiceCollection

The service collection.

name string

The name of the options, passed as optionsName to the ITokenCache.

section IConfigurationSection

The section to read.

fallbackName string

The name of the options giving the values that are not in the section, or null for the default options.

Exceptions

ConfigurationException

The MaxTime of 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

services IServiceCollection

The service collection.

name string

The name of the options, passed as optionsName to the ITokenCache.

cacheName string

The name of the cache, or null to take the one of the fallback options.

maxTime TimeSpan?

The time after which a cached token is evicted, or null to take the one of the fallback options.

fallbackName string

The 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

maxTime is 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

services IServiceCollection

The service collection.

configuration IConfiguration

The configuration.

sectionName string

The section holding the shared CacheName and MaxTime, for example Authentication:ClientTokensCache; empty for none.

name string

The name of the shared options, reserved: no entry can have it.

entryKeys IEnumerable<string>

The keys of the entries that use the shared options.

Returns

string

name, or null when sectionName is empty or the section does not exist (the entries then use the default options).

Exceptions

ConfigurationException

An entry is named name (ignoring case), or the MaxTime of 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

services IServiceCollection

The service collection.

configuration IConfiguration

The configuration.

sectionName string

The section to bind. The default is Authentication:TokenCache. MaxTime keeps its default (50 minutes) when it is not in the section.

Examples

services.AddTokenCache(configuration);

Exceptions

ConfigurationException

CacheName is empty or MaxTime is not greater than zero.

AddTokenCache(IServiceCollection, Action<TokenCacheOptions>)

Registers the token cache options from code.

public static void AddTokenCache(this IServiceCollection services, Action<TokenCacheOptions> options)

Parameters

services IServiceCollection

The service collection.

options Action<TokenCacheOptions>

The action that configures the options.

Examples

services.AddTokenCache(o =>
{
    o.CacheName = "Token";
    o.MaxTime = TimeSpan.FromMinutes(30);
});

Exceptions

ConfigurationException

CacheName is empty or MaxTime is not greater than zero.

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

services IServiceCollection

The service collection.