Exemple #1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var accessToken = await _tokenService.GetTokenAsync(cancellationToken); //GetAccessTokenViaTokenCredentialAsync(cancellationToken);

            _logger.LogInformation("accessToken : " + accessToken);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

            return(await base.SendAsync(request, cancellationToken).ConfigureAwait(false));
        }
        async Task <AccessToken> IAccessTokenService.GetTokenAsync(GenericXmlSecurityToken securityToken, CancellationToken cancellationToken)
        {
            var accessToken = GetCachedAccessTokenIfNotExpired();

            if (accessToken == null)
            {
                accessToken = await _tokenService.GetTokenAsync(securityToken, cancellationToken);

                TokenCache.Add(new CacheItem(GetCacheKey(), accessToken),
                               new CacheItemPolicy {
                    AbsoluteExpiration = DateTime.UtcNow + accessToken.ExpiresIn - _cacheClockSkew
                });
            }

            return(accessToken);
        }
Exemple #3
0
 /// <summary>
 /// Retrives an access token based on <see cref="Settings"/>
 /// </summary>
 /// <returns></returns>
 public async Task <AccessToken.AccessToken> GetAccessTokenAsync(
     GenericXmlSecurityToken securityToken,
     CancellationToken cancellationToken)
 {
     return(await _accessTokenService.GetTokenAsync(securityToken, cancellationToken));
 }