コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public StaticTokenCredential(string token)
        {
            Argument.AssertNotNull(token, nameof(token));

            _accessToken = JwtTokenParser.CreateAccessToken(token);
        }