Esempio n. 1
0
        private async Task <RefreshTokenResponse> GetNewTokenAsync(CancellationToken cancellationToken)
        {
            //TODO URI
            string identityToken = await _tokenContainer.GetIdentityTokenAsync();

            string refreshToken = await _tokenContainer.GetRefreshToken();

            string json = JsonConvert.SerializeObject(new
            {
                identityToken,
                refreshToken
            });

            var req = new HttpRequestMessage(HttpMethod.Post, "http://drone02.hive.loc:5000/api/auth/refreshToken")
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            };

            HttpResponseMessage response = await base.SendAsync(req, cancellationToken);

            if (response.IsSuccessStatusCode)
            {
                return(JsonConvert.DeserializeObject <RefreshTokenResponse>(await response.Content.ReadAsStringAsync()));
            }

            await _tokenContainer.Logout();

            throw new HttpResponseException(response);
        }
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            string identityToken = await _tokenContainer.GetIdentityTokenAsync();

            request.Headers.UpdateBearerToken(identityToken);
            return(await base.SendAsync(request, cancellationToken));
        }