Table of Contents

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

source IChannelAccessTokenSource

The token issuer (in production, JwtAssertionTokenSource).

refreshMargin TimeSpan?

How far ahead of expiry to re-issue. Defaults to 5 minutes, to absorb clock skew and issuance latency.

allowedHosts IEnumerable<string>

Hosts the token may be attached to. When unspecified, Default (api / api-data) is used.

clock Func<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

uri Uri

The target URI to get an access token for.

additionalAuthenticationContext Dictionary<string, object>

Additional authentication context to pass to the authentication library.

cancellationToken CancellationToken

The cancellation token for the task

Returns

Task<string>

A Task that holds the access token to use for the request.