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));
        }
 /// <summary>
 /// Initializes a new instance of <see cref="CommunicationTokenCredential"/> that automatically renews the token upon expiry or proactively prior to expiration to speed up the requests.
 /// </summary>
 /// <param name="tokenRefreshOptions">Options for how the token will be refreshed</param>
 public CommunicationTokenCredential(CommunicationTokenRefreshOptions tokenRefreshOptions)
 {
     Argument.AssertNotNull(tokenRefreshOptions, nameof(tokenRefreshOptions));
     _tokenCredential = new AutoRefreshTokenCredential(
         tokenRefreshOptions.TokenRefresher,
         tokenRefreshOptions.AsyncTokenRefresher ?? (cancellationToken => new ValueTask <string>(tokenRefreshOptions.TokenRefresher(cancellationToken))),
         tokenRefreshOptions.Token,
         tokenRefreshOptions.RefreshProactively);
 }
 /// <summary>
 /// Initializes a new instance of <see cref="CommunicationTokenCredential"/> that automatically renews the token upon expiry or proactively prior to expiration to speed up the requests.
 /// </summary>
 /// <param name="options">Options for how the token will be refreshed</param>
 public CommunicationTokenCredential(CommunicationTokenRefreshOptions options)
 {
     Argument.AssertNotNull(options, nameof(options));
     _tokenCredential = new AutoRefreshTokenCredential(options);
 }
 public AutoRefreshTokenCredential(CommunicationTokenRefreshOptions options)
     : this(options, null, null)
 {
 }