Table of Contents

Class BlazorTokenProvider

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

Provides an implementation of ITokenProvider for Blazor applications.

[Export("blazor", typeof(ITokenProvider))]
public class BlazorTokenProvider : ISignOutTokenProvider, ITokenProvider
Inheritance
BlazorTokenProvider
Implements
Inherited Members

Constructors

BlazorTokenProvider(ILocalStorageService, IJSRuntime, ITokenWindowInterop)

Initializes a new instance of the BlazorTokenProvider class with the specified local storage service, JS runtime, and token window interop.

public BlazorTokenProvider(ILocalStorageService localStorageService, IJSRuntime jsRuntime, ITokenWindowInterop windowInterop)

Parameters

localStorageService ILocalStorageService

The local storage service to use for storing and retrieving tokens.

jsRuntime IJSRuntime

The JS runtime to use for interop calls.

windowInterop ITokenWindowInterop

The token window interop to use for opening a window.

Fields

ProviderName

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

public const string ProviderName = "blazor"

Field Value

string

Methods

GetTokenAsync(IKeyValueSettings?, object?)

Asynchronously retrieves an OAuth2 token: the one kept in the local storage when it is still valid, otherwise a new one obtained by opening the authority page in a window.

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

Parameters

settings IKeyValueSettings

The settings to be used for getting the token.

platformParameters object

The platform-specific parameters, if any (not used in this implementation).

Returns

ValueTask<Result<TokenInfo>>

A task representing the asynchronous operation, containing the requested TokenInfo if successful.

Exceptions

ArgumentNullException

Thrown when the settings parameter, its Values property, or the Authority or RedirectUrl value is missing.

UriFormatException

Thrown when the RedirectUrl from settings is not a valid URL.

InvalidOperationException

Thrown when no token is found after the window operation.

SignOutAsync(IKeyValueSettings, CancellationToken)

Signs out the user by removing the token from the local storage.

public ValueTask SignOutAsync(IKeyValueSettings settings, CancellationToken cancellationToken)

Parameters

settings IKeyValueSettings

The settings, which are not used.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

ValueTask

A task that completes when the token is removed.