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
localStorageServiceILocalStorageServiceThe local storage service to use for storing and retrieving tokens.
jsRuntimeIJSRuntimeThe JS runtime to use for interop calls.
windowInteropITokenWindowInteropThe 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
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
settingsIKeyValueSettingsThe settings to be used for getting the token.
platformParametersobjectThe 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
AuthorityorRedirectUrlvalue 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
settingsIKeyValueSettingsThe settings, which are not used.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- ValueTask
A task that completes when the token is removed.