Exemplo n.º 1
0
        public async Task RefreshToken(CancellationToken cancellationToken = default)
        {
            if (oauthResponse == null)
            {
                throw new ArgumentNullException(nameof(oauthResponse));
            }
            if (string.IsNullOrEmpty(oauthResponse.refresh_token))
            {
                throw new ArgumentNullException(nameof(oauthResponse.refresh_token));
            }
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, $"{EndPoint}/v1/public/auth/token");

            httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(new { refresh_token = oauthResponse.refresh_token }), Encoding.UTF8, "application/json");
            HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead, cancellationToken);

            if (!httpResponseMessage.IsSuccessStatusCode)
            {
                throw new HttpException((int)httpResponseMessage.StatusCode, await httpResponseMessage.Content.ReadAsStringAsync());
            }
            OauthResponse newOauth = JsonConvert.DeserializeObject <OauthResponse>(await httpResponseMessage.EnsureSuccessStatusCode().Content.ReadAsStringAsync());

            oauthResponse.refresh_token = newOauth.refresh_token;
            oauthResponse.access_token  = newOauth.access_token;
        }
Exemplo n.º 2
0
 public ChoTotApi(OauthResponse oauthResponse)
 {
     this.oauthResponse = oauthResponse;
 }