예제 #1
0
        /// <summary>
        /// Sends a token request using the client_credentials grant type.
        /// </summary>
        /// <param name="scope">The scope (space separated string).</param>
        /// <param name="parameters">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public Task <TokenResponse> RequestClientCredentialsTokenAsync(string scope = null, IDictionary <string, string> parameters = null, CancellationToken cancellationToken = default)
        {
            var request = new ClientCredentialsTokenRequest
            {
                Scope = scope
            };

            ApplyRequestParameters(request, parameters);

            return(_client().RequestClientCredentialsTokenAsync(request, cancellationToken));
        }
        /// <summary>
        /// Sends a token request using the client_credentials grant type.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static async Task <TokenResponse> RequestClientCredentialsTokenAsync(this HttpMessageInvoker client, ClientCredentialsTokenRequest request, CancellationToken cancellationToken = default)
        {
            var clone = request.Clone();

            clone.Parameters.AddRequired(OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.ClientCredentials);
            clone.Parameters.AddOptional(OidcConstants.TokenRequest.Scope, request.Scope);

            foreach (var resource in request.Resource)
            {
                clone.Parameters.AddRequired(OidcConstants.TokenRequest.Resource, resource, allowDuplicates: true);
            }

            return(await client.RequestTokenAsync(clone, cancellationToken).ConfigureAwait());
        }
        /// <summary>
        /// Sends a token request using the client_credentials grant type.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public static async Task <TokenResponse> RequestClientCredentialsTokenAsync(this HttpClient client, ClientCredentialsTokenRequest request, CancellationToken cancellationToken = default)
        {
            request.GrantType = OidcConstants.GrantTypes.ClientCredentials;

            request.Parameters.AddOptional(OidcConstants.TokenRequest.Scope, request.Scope);

            return(await client.RequestTokenAsync(request, cancellationToken));
        }