Class RefreshingChannelAccessTokenProvider
- Namespace
- Line.OpenApi.ChannelAccessToken
- Assembly
- Line.OpenApi.ChannelAccessToken.dll
An Microsoft.Kiota.Abstractions.Authentication.IAccessTokenProvider that issues and caches a short-lived channel access token (v2.1 / JWT) at runtime and re-issues it as expiry approaches.
Design section 7:
- Placed in this package (Line.OpenApi.ChannelAccessToken) rather than Core, to avoid a reverse dependency.
- Allowed hosts are injectable/extensible rather than hard-coded (returns an empty string on the negative path).
- Prevents duplicate issuance under concurrent refresh (SemaphoreSlim + double-check).
public sealed class RefreshingChannelAccessTokenProvider : IAccessTokenProvider, IDisposable
- Inheritance
-
RefreshingChannelAccessTokenProvider
- Implements
-
IAccessTokenProvider
- Inherited Members
Constructors
RefreshingChannelAccessTokenProvider(IChannelAccessTokenSource, TimeSpan?, IEnumerable<string>?, Func<DateTimeOffset>?)
public RefreshingChannelAccessTokenProvider(IChannelAccessTokenSource source, TimeSpan? refreshMargin = null, IEnumerable<string>? allowedHosts = null, Func<DateTimeOffset>? clock = null)
Parameters
sourceIChannelAccessTokenSourceThe token issuer (in production, JwtAssertionTokenSource).
refreshMarginTimeSpan?How far ahead of expiry to re-issue. Defaults to 5 minutes, to absorb clock skew and issuance latency.
allowedHostsIEnumerable<string>Hosts the token may be attached to. When unspecified, Default (api / api-data) is used.
clockFunc<DateTimeOffset>Time source (replaceable in tests). Defaults to UtcNow.
Properties
AllowedHostsValidator
Returns the Microsoft.Kiota.Abstractions.Authentication.IAccessTokenProvider.AllowedHostsValidator for the provider.
public AllowedHostsValidator AllowedHostsValidator { get; }
Property Value
- AllowedHostsValidator
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetAuthorizationTokenAsync(Uri, Dictionary<string, object>?, CancellationToken)
This method is called by the Microsoft.Kiota.Abstractions.Authentication.BaseBearerTokenAuthenticationProvider class to get the access token.
public Task<string> GetAuthorizationTokenAsync(Uri uri, Dictionary<string, object>? additionalAuthenticationContext = null, CancellationToken cancellationToken = default)
Parameters
uriUriThe target URI to get an access token for.
additionalAuthenticationContextDictionary<string, object>Additional authentication context to pass to the authentication library.
cancellationTokenCancellationTokenThe cancellation token for the task