public AccessTokenResponse GetAccessToken(string[] scopes, bool forceRefresh = false)
        {
            _log.LogInformation($"Getting token via {_cred.GetType()} for {string.Join(',', scopes)}");
            var b        = _cred.GetToken(new Azure.Core.TokenRequestContext(scopes), CancellationToken.None);
            var resource = ScopeUtil.GetResourceFromScope(scopes);

            return(new AccessTokenResponse(resource, b.Token, b.ExpiresOn));
        }
        public async Task <AccessTokenResponse> GetAccessTokenAsync(string[] scopes, bool forceRefresh = false)
        {
            // todo: parse the token for expiration? dunno
            var resource = ScopeUtil.GetResourceFromScope(scopes);

            _log.LogTrace($"Fetching access token via MSI for {resource} ({string.Join(',', scopes)}); forcedRefresh: {forceRefresh}");
            return(new AccessTokenResponse(resource, await _tokenProvider.GetAccessTokenAsync(resource, forceRefresh), DateTimeOffset.UtcNow.AddHours(1)));
        }
Ejemplo n.º 3
0
        public AccessTokenResponse GetAccessToken(string[] scopes, bool forceRefresh = false)
        {
            var resource = ScopeUtil.GetResourceFromScope(scopes);

            _log.LogTrace($"Fetching access token via CLI for {resource} ({string.Join(',', scopes)}); forcedRefresh: {forceRefresh}");
            // todo: make sure i'm not missing something here
            if (!_tokens.ContainsKey(resource) || forceRefresh)
            {
                _tokens.AddOrUpdate(resource, x => GetToken(resource), (y, z) => GetToken(resource));
            }
            return(_tokens.GetOrAdd(resource, x => GetToken(resource)));
        }