Class RefreshTokenProvider
- Namespace
- Arc4u.OAuth2.TokenProviders
- Assembly
- Arc4u.OAuth2.AspNetCore.Authentication.dll
The purpose of this token provider is to be used by Oidc one. It will refresh a token based on a refresh token and update the scoped TokenRefreshInfo. The Oidc token provider is responsible to get back an access token.
[Export(typeof(ITokenRefreshProvider))]
public class RefreshTokenProvider : ITokenRefreshProvider
- Inheritance
-
RefreshTokenProvider
- Implements
- Inherited Members
Constructors
RefreshTokenProvider(TokenRefreshInfo, IOptionsMonitor<OpenIdConnectOptions>, IOptions<OidcAuthenticationOptions>, IActivitySourceFactory, IOptionsMonitor<ApiExtraContextAuthenticationOption>, ILogger<RefreshTokenProvider>)
Initializes a new instance of the RefreshTokenProvider class.
public RefreshTokenProvider(TokenRefreshInfo refreshInfo, IOptionsMonitor<OpenIdConnectOptions> openIdConnectOptions, IOptions<OidcAuthenticationOptions> oidcOptions, IActivitySourceFactory activitySourceFactory, IOptionsMonitor<ApiExtraContextAuthenticationOption> extraContextOptions, ILogger<RefreshTokenProvider> logger)
Parameters
refreshInfoTokenRefreshInfoThe scoped access and refresh tokens of the user, updated by the refresh.
openIdConnectOptionsIOptionsMonitor<OpenIdConnectOptions>The options of the OpenID Connect scheme, giving the client id, the secret and the token endpoint.
oidcOptionsIOptions<OidcAuthenticationOptions>The OpenID Connect authentication options.
activitySourceFactoryIActivitySourceFactoryThe factory of the activity source used for telemetry.
extraContextOptionsIOptionsMonitor<ApiExtraContextAuthenticationOption>The extra parameters added to the token requests.
loggerILogger<RefreshTokenProvider>The logger.
Fields
ProviderName
The name (Refresh) of the provider.
public const string ProviderName = "Refresh"
Field Value
Methods
RefreshTokenAsync(CancellationToken)
Calls the token endpoint of the authority with the refresh_token grant and stores the new tokens in the scoped TokenRefreshInfo.
public Task<TokenRefreshInfo?> RefreshTokenAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<TokenRefreshInfo>
The updated TokenRefreshInfo.
Exceptions
- InvalidOperationException
There is no refresh token, or it is expired.
- HttpRequestException
The token endpoint does not answer with a success status code.