Class ClientTokensExtension
- Namespace
- Arc4u.OAuth2.Extensions
- Assembly
- Arc4u.OAuth2.AspNetCore.dll
Registers the unified Authentication:ClientTokens section: a single section where
heterogeneous client token scenarios coexist, each entry discriminated by its
Scenario property and projected into a named
SimpleKeyValueSettings.
public static class ClientTokensExtension
- Inheritance
-
ClientTokensExtension
- Inherited Members
Fields
TokenCacheOptionsName
The name of the TokenCacheOptions registered from the Authentication:ClientTokensCache section: the default token cache of every
client token entry. No entry can use this name as its key when the section exists.
public const string TokenCacheOptionsName = "ClientTokensCache"
Field Value
Properties
Scenario
Resolves an IClientTokenScenario from its discriminator (the
Scenario value), or null when none matches.
Defaults to DefaultScenario(string) (the built-in scenarios). A framework user can reconfigure it via SetScenarioResolver(Func<string, IClientTokenScenario?>) — typically by handling their own discriminators and delegating to DefaultScenario(string) for the rest.
public static Func<string, IClientTokenScenario?> Scenario { get; }
Property Value
Methods
AddClientTokens(IServiceCollection, IConfiguration, string, string)
Reads the sectionName section and registers a named
SimpleKeyValueSettings per entry, selecting the matching
IClientTokenScenario by the entry's discriminator through Scenario.
Nothing is registered when the section does not exist or is empty. An entry is registered only once per service collection.
public static void AddClientTokens(this IServiceCollection services, IConfiguration configuration, string sectionName = "Authentication:ClientTokens", string tokenCacheSectionName = "Authentication:ClientTokensCache")
Parameters
servicesIServiceCollectionThe service collection.
configurationIConfigurationThe configuration to read the section from, for example
builder.Configuration.sectionNamestringThe section to read. The default is
Authentication:ClientTokens.tokenCacheSectionNamestringThe optional section holding the TokenCacheOptions shared by every entry. The default is
Authentication:ClientTokensCache; an empty name turns it off. The token cache of an entry is resolved value by value: the entry's ownTokenCache, then this section, then the default TokenCacheOptions (Authentication:TokenCache).
Examples
builder.Services.AddClientTokens(builder.Configuration);
Exceptions
- ConfigurationException
An entry has no
Scenario, an unknown scenario, an empty authentication type, or is invalid for its scenario; aMaxTimeof a token cache is not greater than zero; or an entry is named TokenCacheOptionsName while the token cache section exists.
DefaultScenario(string)
public static IClientTokenScenario? DefaultScenario(string discriminator)
Parameters
discriminatorstring
Returns
SetScenarioResolver(Func<string, IClientTokenScenario?>)
Reconfigures the scenario resolver. Delegate to DefaultScenario(string) to keep the built-ins.
public static void SetScenarioResolver(Func<string, IClientTokenScenario?> resolver)
Parameters
resolverFunc<string, IClientTokenScenario>
Examples
ClientTokensExtension.SetScenarioResolver(discriminator => discriminator switch
{
"MyCustom" => new MyCustomScenario(),
_ => ClientTokensExtension.DefaultScenario(discriminator)
});