Table of Contents

Class CredentialTokenCacheTokenProvider

Namespace
Arc4u.OAuth2.TokenProvider
Assembly
Arc4u.OAuth2.AspNetCore.dll

An ITokenProvider for user name and password credentials. The token is cached (key: authority, scope, user and a hash of the password) and requested again through the ICredentialTokenProvider registered as CredentialDirect when it is missing or expires in less than one minute.

[Export("Credential", typeof(ITokenProvider))]
public class CredentialTokenCacheTokenProvider : ITokenProvider
Inheritance
CredentialTokenCacheTokenProvider
Implements
Inherited Members

Constructors

CredentialTokenCacheTokenProvider(ITokenCache, ILogger<CredentialTokenCacheTokenProvider>, IServiceProvider, IOptionsMonitor<AuthorityOptions>)

An ITokenProvider for user name and password credentials. The token is cached (key: authority, scope, user and a hash of the password) and requested again through the ICredentialTokenProvider registered as CredentialDirect when it is missing or expires in less than one minute.

public CredentialTokenCacheTokenProvider(ITokenCache tokenCache, ILogger<CredentialTokenCacheTokenProvider> logger, IServiceProvider container, IOptionsMonitor<AuthorityOptions> authorities)

Parameters

tokenCache ITokenCache

The token cache.

logger ILogger<CredentialTokenCacheTokenProvider>

The logger.

container IServiceProvider

The service provider used to resolve the ICredentialTokenProvider.

authorities IOptionsMonitor<AuthorityOptions>

The named authority options.

Fields

ProviderName

The key (Credential) under which the provider is registered.

public const string ProviderName = "Credential"

Field Value

string

Methods

CreateBasicTokenInfoAsync(IKeyValueSettings, CredentialsResult)

Requests a token for the credentials from the CredentialDirect ICredentialTokenProvider, without using the cache.

protected ValueTask<Result<TokenInfo>> CreateBasicTokenInfoAsync(IKeyValueSettings settings, CredentialsResult credential)

Parameters

settings IKeyValueSettings

The provider settings.

credential CredentialsResult

The user credentials.

Returns

ValueTask<Result<TokenInfo>>

The token, or a failed result when the credential token provider is not registered or the request fails.

GetTokenAsync(IKeyValueSettings?, object?)

Acquires a token for a user/password credential, caching it by user + authority + scope.

The credential is taken from platformParameters when it is a CredentialsResult (the path used by BasicAuthenticationMiddleware, which extracts it from the request); otherwise it is built from the User/Password keys present in settings (the client-token scenario path).

public ValueTask<Result<TokenInfo>> GetTokenAsync(IKeyValueSettings? settings, object? platformParameters)

Parameters

settings IKeyValueSettings
platformParameters object

Returns

ValueTask<Result<TokenInfo>>