internal AutoRefreshTokenCredential( CommunicationTokenRefreshOptions options, Func <Action, TimeSpan, ThreadSafeRefreshableAccessTokenCache.IScheduledAction>?scheduler, Func <DateTimeOffset>?utcNowProvider) { if (options.InitialToken is null) { _accessTokenCache = new ThreadSafeRefreshableAccessTokenCache( Refresh, RefreshAsync, options.RefreshProactively, scheduler, utcNowProvider); } else { _accessTokenCache = new ThreadSafeRefreshableAccessTokenCache( Refresh, RefreshAsync, options.RefreshProactively, initialValue: JwtTokenParser.CreateAccessToken(options.InitialToken), scheduler, utcNowProvider); } AccessToken Refresh(CancellationToken cancellationToken) => JwtTokenParser.CreateAccessToken(options.TokenRefresher(cancellationToken)); async ValueTask <AccessToken> RefreshAsync(CancellationToken cancellationToken) => JwtTokenParser.CreateAccessToken(await options.AsyncTokenRefresher(cancellationToken).ConfigureAwait(false)); }
internal AutoRefreshTokenCredential( Func <CancellationToken, string> tokenRefresher, Func <CancellationToken, ValueTask <string> > asyncTokenRefresher, string?initialToken, bool refreshProactively, Func <Action, TimeSpan, ThreadSafeRefreshableAccessTokenCache.IScheduledAction>?scheduler, Func <DateTimeOffset>?utcNowProvider) { if (initialToken == null) { _accessTokenCache = new ThreadSafeRefreshableAccessTokenCache( Refresh, RefreshAsync, refreshProactively, scheduler, utcNowProvider); } else { _accessTokenCache = new ThreadSafeRefreshableAccessTokenCache( Refresh, RefreshAsync, refreshProactively, initialValue: JwtTokenParser.CreateAccessToken(initialToken), scheduler, utcNowProvider); } AccessToken Refresh(CancellationToken cancellationToken) => JwtTokenParser.CreateAccessToken(tokenRefresher(cancellationToken)); async ValueTask <AccessToken> RefreshAsync(CancellationToken cancellationToken) => JwtTokenParser.CreateAccessToken(await asyncTokenRefresher(cancellationToken).ConfigureAwait(false)); }
public StaticTokenCredential(string token) { Argument.AssertNotNull(token, nameof(token)); _accessToken = JwtTokenParser.CreateAccessToken(token); }