public Task <ApiResponse <UserModel> > GetUserDataAsync() => _httpClient .CreateRequest() .ByResource(ProjectConstants.BaseUrl, $"/{UserApis.GetUser}") .WithMethod(HttpMethod.Get) .WithAuthorization(AuthTypes.Bearer, _authorizationHolder.GetLastSession().Token) .MakeRequestAsync() .ReadAsJsonAsync <ApiResponse <UserModel> >();
public Task <ApiResponse <AuthorizationResponse> > UpdateAuthorizationAsync() => _httpClient .CreateRequest() .ByResource(ProjectConstants.BaseUrl, $"/{AuthorizationApis.RefreshToten}") .WithMethod(HttpMethod.Post) .WithAuthorization(AuthTypes.Bearer, _authorizationHolder.GetLastSession().Token) .MakeRequestAsync() .ReadAsJsonAsync <ApiResponse <AuthorizationResponse> >();
public async Task UpdateSessionAsync(string sessionToken, CancellationToken token) { await Task.Delay(2000); if (!_authorizationHolder.GetLastSession().CanUpdate()) { throw new AuthorizationException(); } var tokenModel = new TokenModel { Token = "sdfsdfsdfs", ExpireAt = DateTimeOffset.Now.AddMinutes(30), CanBeUpdatedTill = DateTimeOffset.Now.AddDays(3) }; _authorizationUpdater.SaveSession(tokenModel); }
public async Task UpdateSessionAsync(string sessionToken, CancellationToken token) { if (!_authorizationHolder.GetLastSession().CanUpdate()) { throw new AuthorizationException(); } var response = await _authorizationApi.UpdateAuthorizationAsync(); token.ThrowIfCancellationRequested(); if (response.Status.IsFailure()) { throw new ServerUnhandledException(response.Message); } _authorizationUpdater.SaveSession(response.Result.TokenModel); }