Exemple #1
0
        /// <summary>
        /// Sends a token request using the urn:ietf:params:oauth:grant-type:device_code grant type.
        /// </summary>
        /// <param name="deviceCode">The device code.</param>
        /// <param name="parameters">Extra parameters.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public Task <TokenResponse> RequestDeviceTokenAsync(string deviceCode, IDictionary <string, string> parameters = null, CancellationToken cancellationToken = default)
        {
            var request = new DeviceTokenRequest
            {
                DeviceCode = deviceCode
            };

            ApplyRequestParameters(request, parameters);

            return(_client().RequestDeviceTokenAsync(request, cancellationToken));
        }
        /// <summary>
        /// Sends a token request using the urn:ietf:params:oauth:grant-type:device_code 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> RequestDeviceTokenAsync(this HttpMessageInvoker client, DeviceTokenRequest request, CancellationToken cancellationToken = default)
        {
            var clone = request.Clone();

            clone.Parameters.AddRequired(OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.DeviceCode);
            clone.Parameters.AddRequired(OidcConstants.TokenRequest.DeviceCode, request.DeviceCode);

            return(await client.RequestTokenAsync(clone, cancellationToken).ConfigureAwait());
        }
Exemple #3
0
        /// <summary>
        /// Sends a token request using the urn:ietf:params:oauth:grant-type:device_code 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> RequestDeviceTokenAsync(this HttpMessageInvoker client, DeviceTokenRequest request, CancellationToken cancellationToken = default)
        {
            if (request.ClientId.IsMissing())
            {
                throw new ArgumentException("client_id is missing", "client_id");
            }

            request.GrantType = OidcConstants.GrantTypes.DeviceCode;

            request.Parameters.AddRequired(OidcConstants.TokenRequest.DeviceCode, request.DeviceCode);

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