示例#1
0
        public async Task <Result> RefreshTokenAsync()
        {
            try
            {
                var refreshToken = new RefreshTokenModel()
                {
                    RefreshToken = await _currentUser.GetAuthRefreshToken(),
                    Token        = await _currentUser.GetAuthToken()
                };
                var loginAsJson = JsonConvert.SerializeObject(refreshToken);

                var response = await httpClient.PostAsync("api/v1/OAuth/RefreshToken",
                                                          new StringContent(loginAsJson, Encoding.UTF8, "application/json"));

                var result = JsonConvert.DeserializeObject <AuthenticationResult>(await response.Content.ReadAsStringAsync());

                if (!response.IsSuccessStatusCode)
                {
                    return(Result.Failure(result.EnError, result.FaError));
                }

                await SetAuthentication(result.Token, result.RefreshToken);

                return(Result.Success());
            }
            catch (Exception)
            {
                return(CommonResults.InternalServerError("Internal Server Error", "سرور در حال بارگذاری می باشد"));
            }
        }