| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | using Google.Apis.Auth.OAuth2.Responses; |
| | using Google.Apis.Json; |
| | using Google.Apis.Logging; |
| | using Google.Apis.Requests.Parameters; |
| | using Google.Apis.Responses; |
| | using Google.Apis.Util; |
| | using System; |
| | using System.Net.Http; |
| | using System.Net.Http.Headers; |
| | using System.Text; |
| | using System.Threading; |
| | using System.Threading.Tasks; |
| |
|
| | namespace Google.Apis.Auth.OAuth2.Requests |
| | { |
| | internal static class RequestExtensions |
| | { |
| | |
| | |
| | |
| | internal static async Task<HttpResponseMessage> PostJsonAsync( |
| | this object request, HttpClient httpClient, string url, CancellationToken cancellationToken) |
| | { |
| | var httpRequest = new HttpRequestMessage(HttpMethod.Post, url) |
| | { |
| | Content = new StringContent(NewtonsoftJsonSerializer.Instance.Serialize(request), Encoding.UTF8, "application/json") |
| | }; |
| |
|
| | return await httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | internal static async Task<TResponse> PostJsonAsync<TResponse>( |
| | this object request, HttpClient httpClient, string url, CancellationToken cancellationToken) |
| | { |
| | var response = await request.PostJsonAsync(httpClient, url, cancellationToken).ConfigureAwait(false); |
| | if (!response.IsSuccessStatusCode) |
| | { |
| | var serviceHost = new Uri(url).Host; |
| | var error = await response.DeserializeErrorAsync(serviceHost, NewtonsoftJsonSerializer.Instance).ConfigureAwait(false); |
| | throw new GoogleApiException(serviceHost) |
| | { |
| | Error = error, |
| | HttpStatusCode = response.StatusCode |
| | }; |
| | } |
| | return await NewtonsoftJsonSerializer.Instance.DeserializeAsync<TResponse>( |
| | await response.Content.ReadAsStreamAsync().ConfigureAwait(false), cancellationToken).ConfigureAwait(false); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | internal static async Task<TokenResponse> PostJsonAsync( |
| | this object request, HttpClient httpClient, string url, |
| | IClock clock, ILogger logger, CancellationToken cancellationToken) |
| | { |
| | var response = await request.PostJsonAsync(httpClient, url, cancellationToken).ConfigureAwait(false); |
| | return await TokenResponse.FromHttpResponseAsync(response, clock, logger).ConfigureAwait(false); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | internal static async Task<TokenResponse> PostFormAsync(this object request, HttpClient httpClient, |
| | string url, AuthenticationHeaderValue authenticationHeaderValue, |
| | IClock clock, ILogger logger, CancellationToken taskCancellationToken) |
| | { |
| | var httpRequest = new HttpRequestMessage(HttpMethod.Post, url) |
| | { |
| | Content = ParameterUtils.CreateFormUrlEncodedContent(request) |
| | }; |
| | if (authenticationHeaderValue is not null) |
| | { |
| | httpRequest.Headers.Authorization = authenticationHeaderValue; |
| | } |
| |
|
| | var response = await httpClient.SendAsync(httpRequest, taskCancellationToken).ConfigureAwait(false); |
| | return await TokenResponse.FromHttpResponseAsync(response, clock, logger).ConfigureAwait(false); |
| | } |
| | } |
| | } |
| |
|