/// <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> RequestArbitraryTokenTokenAsync(
            this HttpMessageInvoker client, ArbitraryTokenTokenRequest request, CancellationToken cancellationToken = default)
        {
            var clone = request.Clone <TokenRequest>();

            clone.Parameters.AddRequired(OidcConstants.TokenRequest.GrantType, "arbitrary_token");
            clone.Parameters.AddOptional(OidcConstants.TokenRequest.Scope, request.Scope);
            clone.Parameters.AddOptional("subject", request.Subject);
            clone.Parameters.AddOptional("arbitrary_claims", request.ArbitraryClaims);
            clone.Parameters.AddOptional("access_token_lifetime", request.AccessTokenLifetime.ToString());
            clone.Parameters.AddOptional("arbitrary_amrs", request.ArbitraryAmrs);
            clone.Parameters.AddOptional("arbitrary_audiences", request.ArbitraryAudiences);
            clone.Parameters.AddOptional("custom_payload", request.CustomPayload);

            return(await client.RequestTokenAsync(clone, cancellationToken));
        }
Пример #2
0
        public async Task <TokenResponse> RequestArbitraryTokenAsync(HttpClient httpClient, ArbitraryTokenTokenRequestV2 request)
        {
            var arbitraryTokenTokenRequest = new ArbitraryTokenTokenRequest
            {
                Address             = request.Address,
                Subject             = request.Subject,
                ClientId            = request.ClientId,
                ClientSecret        = request.ClientSecret,
                AccessTokenLifetime = request.AccessTokenLifetime
            };


            if (request.CustomPayload != null)
            {
                // TODO custom payload needs to be an array.
                arbitraryTokenTokenRequest.CustomPayload = _serializer.Serialize(request.CustomPayload);
            }
            if (request.Scope != null)
            {
                arbitraryTokenTokenRequest.Scope = string.Join(" ", request.Scope);
            }
            if (request.ArbitraryAudiences != null)
            {
                arbitraryTokenTokenRequest.ArbitraryAudiences = _serializer.Serialize(request.ArbitraryAudiences);
            }
            if (request.ArbitraryAmrs != null)
            {
                arbitraryTokenTokenRequest.ArbitraryAmrs = _serializer.Serialize(request.ArbitraryAmrs);
            }
            if (request.ArbitraryClaims != null)
            {
                arbitraryTokenTokenRequest.ArbitraryClaims = _serializer.Serialize(request.ArbitraryClaims);
            }


            var result = await httpClient.RequestArbitraryTokenTokenAsync(arbitraryTokenTokenRequest);

            return(result);
        }
Пример #3
0
        public async Task <TokenResponse> RequestArbitraryTokenAsync(HttpClient httpClient, ArbitraryTokenTokenRequest request)
        {
            var result = await httpClient.RequestArbitraryTokenTokenAsync(request);

            return(result);
        }