/// <summary>
        ///     Retrieve access token for the configured "client_id", specified scope and resource
        /// </summary>
        /// <param name="parameters">Custom grant parameters</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Access token</returns>
        /// <exception cref="TokenEndpointException">Exception during token endpoint communication</exception>
        public async Task <string> GetTokenAsync(ResourceScopedAccessGrantParameters parameters,
                                                 CancellationToken token = default(CancellationToken))
        {
            var result = await _customGrantTokenClient
                         .GetTokenInternalAsync(GetPostParams(parameters), new[] { parameters.Scope }, token)
                         .ConfigureAwait(false);

            return(result.Item1);
        }
예제 #2
0
        /// <summary>
        ///     Retrieve access token for the configured "client_id" and specified scopes. Request to the server is only performed
        ///     if matching valid token is not in the cache
        /// </summary>
        /// <param name="scopes">OAuth2 scopes to request</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Access token</returns>
        /// <exception cref="TokenEndpointException">Exception during token endpoint communication</exception>
        public Task <string> GetTokenAsync(string[] scopes, CancellationToken token = default(CancellationToken))
        {
            var cacheKey = string.Join(":", _partialCacheKey, ScopeHelper.ToScopeString(scopes));

            return(_cache.GetOrCreateAsync(cacheKey,
                                           ct => _customGrantTokenClient.GetTokenInternalAsync(new List <KeyValuePair <string, string> >(), scopes,
                                                                                               ct),
                                           token));
        }