Table of Contents

Class OidcClientIdentityModelTokenProvider

Namespace
Arc4u.OAuth2.Client.Authentication.TokenProvider
Assembly
Arc4u.OAuth2.Client.Authentication.dll

An ITokenProvider for a client application using Duende.IdentityModel.OidcClient. The tokens are kept in the secure cache; an expired access token is renewed with the refresh token, and the user is logged in through the browser when there is no valid refresh token. The access token is refreshed when it expires in less than ForceRefreshTimeoutTimeSpan, and the refresh token is assumed valid for RefreshTokenLifetime.

[Export("OidcClientIdentityModel", typeof(ITokenProvider))]
[Shared]
public class OidcClientIdentityModelTokenProvider : ISignOutTokenProvider, ITokenProvider
Inheritance
OidcClientIdentityModelTokenProvider
Implements
Inherited Members

Constructors

OidcClientIdentityModelTokenProvider(OidcClientOptions, TokenRefreshInfo, ISecureCache, IOptionsMonitor<ApiExtraContextAuthenticationOption>, IOptionsMonitor<OidcClientAuthenticationOptions>, ILogger<OidcClientIdentityModelTokenProvider>?)

An ITokenProvider for a client application using Duende.IdentityModel.OidcClient. The tokens are kept in the secure cache; an expired access token is renewed with the refresh token, and the user is logged in through the browser when there is no valid refresh token. The access token is refreshed when it expires in less than ForceRefreshTimeoutTimeSpan, and the refresh token is assumed valid for RefreshTokenLifetime.

public OidcClientIdentityModelTokenProvider(OidcClientOptions options, TokenRefreshInfo tokensInfo, ISecureCache secureCache, IOptionsMonitor<ApiExtraContextAuthenticationOption> apiExtraContextOption, IOptionsMonitor<OidcClientAuthenticationOptions> authenticationOptions, ILogger<OidcClientIdentityModelTokenProvider>? logger = null)

Parameters

options OidcClientOptions

The OidcClient options.

tokensInfo TokenRefreshInfo

The access and refresh tokens of the user.

secureCache ISecureCache

The secure cache in which the tokens are persisted.

apiExtraContextOption IOptionsMonitor<ApiExtraContextAuthenticationOption>

The extra parameters added to the authorization (front channel) and token (back channel) requests.

authenticationOptions IOptionsMonitor<OidcClientAuthenticationOptions>

The client authentication options, giving the refresh threshold and the refresh token lifetime.

logger ILogger<OidcClientIdentityModelTokenProvider>

The logger of the secure-cache failures. Optional: nothing is logged when no logger is registered.

Fields

TokenProviderName

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

public const string TokenProviderName = "OidcClientIdentityModel"

Field Value

string

Methods

GetTokenAsync(IKeyValueSettings?, object?)

Gets the access token of the user, refreshing it or logging the user in when necessary.

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

Parameters

settings IKeyValueSettings

The provider settings. They are not used.

platformParameters object

Not used.

Returns

ValueTask<Result<TokenInfo>>

The access token, or a failed result when the login failed. When the refresh of the token fails, the user is logged in again.

SignOutAsync(IKeyValueSettings, CancellationToken)

Cancels a login in progress, removes the tokens from memory and from the secure cache, then logs the user out of the authority. The logout (in the browser) is skipped when no tokens existed: the user did not sign in with this provider. It is bounded by LoginTimeout. A failure of the secure cache or of the logout is logged: the other steps are done anyway.

public ValueTask SignOutAsync(IKeyValueSettings settings, CancellationToken cancellationToken)

Parameters

settings IKeyValueSettings

The provider settings, which are not used.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

ValueTask

A task that completes when the user is logged out.