Class BlazorMsalTokenProvider
- Namespace
- Arc4u.OAuth2.TokenProvider
- Assembly
- Arc4u.OAuth2.Blazor.dll
Provides an implementation of ITokenProvider for Blazor applications using MSAL.
[Export("blazor", typeof(ITokenProvider))]
public class BlazorMsalTokenProvider : ISignOutTokenProvider, ITokenProvider
- Inheritance
-
BlazorMsalTokenProvider
- Implements
- Inherited Members
Constructors
BlazorMsalTokenProvider(IAccessTokenProvider, IApplicationContext, NavigationManager)
Initializes a new instance of the BlazorMsalTokenProvider class with the specified access token provider, application context and navigation manager.
public BlazorMsalTokenProvider(IAccessTokenProvider tokenProvider, IApplicationContext applicationContext, NavigationManager navigation)
Parameters
tokenProviderIAccessTokenProviderThe access token provider of the WebAssembly authentication, used for obtaining access tokens.
applicationContextIApplicationContextThe application context to use for getting the principal.
navigationNavigationManagerThe navigation manager used to redirect the user to the login page when the token cannot be obtained silently.
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.
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. The token is the one stored in the identity of the current principal when it is still valid, otherwise the one requested to the MSAL access token provider; a failed result is returned when no token is found. When the MSAL access token provider requires an interactive login, the current principal is cleared and the user is redirected to the login page.
Exceptions
- ArgumentNullException
Thrown when the settings parameter is null.
SignOutAsync(IKeyValueSettings, CancellationToken)
Clears the current principal, so its token (the BootstrapContext) is no longer used.
The MSAL tokens are managed by the authentication of the Blazor application: the application signs out with NavigateToLogout.
public ValueTask SignOutAsync(IKeyValueSettings settings, CancellationToken cancellationToken)
Parameters
settingsIKeyValueSettingsThe settings, which are not used.
cancellationTokenCancellationTokenThe cancellation token, which is not used.