internal static async Task <TokenResponse> RequestTokenAsync(this HttpMessageInvoker client, ProtocolRequest request, CancellationToken cancellationToken = default) { if (!request.Parameters.TryGetValue(OidcConstants.TokenRequest.ClientId, out _)) { if (request.ClientId.IsMissing()) { throw new InvalidOperationException("client_id is missing"); } } request.Prepare(); request.Method = HttpMethod.Post; HttpResponseMessage response; try { response = await client.SendAsync(request, cancellationToken).ConfigureAwait(false); } catch (Exception ex) { return(ProtocolResponse.FromException <TokenResponse>(ex)); } return(await ProtocolResponse.FromHttpResponseAsync <TokenResponse>(response).ConfigureAwait(false)); }
internal static async Task <IdentityModel.Client.IdentityModelExtensions.TokenResponse> RequestTokenAsync(this HttpMessageInvoker client, ProtocolRequest request, CancellationToken?cancellationToken) { request.Prepare(); request.Method = HttpMethod.Post; HttpResponseMessage response; try { response = await client.SendAsync(request, cancellationToken.HasValue?cancellationToken.Value : new CancellationToken()).ConfigureAwait(false); } catch (Exception ex) { return(ProtocolResponse.FromException <IdentityModel.Client.IdentityModelExtensions.TokenResponse>(ex)); } return(await ProtocolResponse.FromHttpResponseAsync <IdentityModel.Client.IdentityModelExtensions.TokenResponse>(response).ConfigureAwait(false)); }
internal static async Task <TokenResponse> RequestTokenAsync(this HttpMessageInvoker client, ProtocolRequest request, CancellationToken cancellationToken = default) { request.Prepare(); request.Method = HttpMethod.Post; HttpResponseMessage response; try { response = await client.SendAsync(request, cancellationToken).ConfigureAwait(); } catch (Exception ex) { return(ProtocolResponse.FromException <TokenResponse>(ex)); } return(await ProtocolResponse.FromHttpResponseAsync <TokenResponse>(response).ConfigureAwait()); }