示例#1
0
        /// <inheritdoc/>
        public async Task <TokenResponse> RequestClientAccessToken(
            string clientName = AccessTokenManagementDefaults.DefaultTokenClientName,
            ClientAccessTokenParameters parameters = null,
            CancellationToken cancellationToken    = default)
        {
            _logger.LogDebug("Requesting client access token for client: {client}", clientName);

            parameters ??= new ClientAccessTokenParameters();

            var requestDetails = await _configService.GetClientCredentialsRequestAsync(clientName, parameters);

#if NET5_0
            requestDetails.Options.TryAdd(AccessTokenManagementDefaults.AccessTokenParametersOptionsName, parameters);
#elif NETCOREAPP3_1
            requestDetails.Properties[AccessTokenManagementDefaults.AccessTokenParametersOptionsName] = parameters;
#endif

            if (!string.IsNullOrWhiteSpace(parameters.Resource))
            {
                requestDetails.Resource.Add(parameters.Resource);
            }

            var httpClient = _httpClientFactory.CreateClient(AccessTokenManagementDefaults.BackChannelHttpClientName);
            return(await httpClient.RequestClientCredentialsTokenAsync(requestDetails, cancellationToken));
        }
示例#2
0
        /// <inheritdoc/>
        public async Task <TokenResponse> RequestClientAccessToken(string clientName = AccessTokenManagementDefaults.DefaultTokenClientName)
        {
            var requestDetails = await _configService.GetClientCredentialsRequestAsync(clientName);

            return(await _httpClient.RequestClientCredentialsTokenAsync(requestDetails));
        }