Table of Contents

Class ClientTokenProvider

Namespace
Arc4u.OAuth2.TokenProvider
Assembly
Arc4u.OAuth2.Blazor.dll

An ITokenProvider for a Blazor WebAssembly application whose token is given by its server backend. The token is requested with a GET on the TokenRequestUrl of the settings, through the HttpClient named by HttpClientName (see AddAuthenticationCookie), and kept until it expires.

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

Constructors

ClientTokenProvider(IHttpClientFactory, ILogger<ClientTokenProvider>)

An ITokenProvider for a Blazor WebAssembly application whose token is given by its server backend. The token is requested with a GET on the TokenRequestUrl of the settings, through the HttpClient named by HttpClientName (see AddAuthenticationCookie), and kept until it expires.

public ClientTokenProvider(IHttpClientFactory httpClientFactory, ILogger<ClientTokenProvider> logger)

Parameters

httpClientFactory IHttpClientFactory

The factory of the HTTP clients.

logger ILogger<ClientTokenProvider>

The logger.

Fields

ProviderName

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

public const string ProviderName = "Client"

Field Value

string

Methods

GetTokenAsync(IKeyValueSettings?, object?)

Gets the token from the server backend, or the previous one when it is still valid.

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

Parameters

settings IKeyValueSettings

The settings giving HttpClientName and TokenRequestUrl.

platformParameters object

Not used.

Returns

ValueTask<Result<TokenInfo>>

The token, or a failed result when a setting is missing or the token cannot be obtained.

SignOutAsync(IKeyValueSettings, CancellationToken)

Forgets the token kept in memory, so the next call asks the server backend again. Signing out of the backend (its authentication cookie) is done by the application.

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, which is not used.

Returns

ValueTask

A completed ValueTask.