public async Task <Response <Token> > RefreshTokenAsync() { string refreshToken = await httpContextAccessor.HttpContext.GetTokenAsync(OpenIdConnectParameterNames.RefreshToken); TokenResponse res = await client.RequestRefreshTokenAsync(new RefreshTokenRequest() { Address = "connect/token", ClientId = clientSettings.WebClientForUser.ClientId, ClientSecret = clientSettings.WebClientForUser.ClientSecret, RefreshToken = refreshToken }); Response <Token> response = null; if (res.IsError) { response = await res.GetResponseAsync <Token>(true, "TokenService/RefreshTokenAsync", "Refresh token alinirken beklenmedik bir hata ile karşılaşıldı"); logger.LogResponse(response); return(response); } Token result = mapper.Map <Token>(res); response = Response <Token> .Success(result, (int)res.HttpStatusCode); logger.LogResponse(response); return(response); }
public async Task <Response <Token> > RequestPasswordTokenAsync(LoginViewModel model) { TokenResponse tokenResponse = await client.RequestPasswordTokenAsync(new() { Address = "connect/token", ClientId = clientSettings.WebClientForUser.ClientId, ClientSecret = clientSettings.WebClientForUser.ClientSecret, UserName = model.UserName, Password = model.Password }); Response <Token> response = null; if (tokenResponse.IsError) { response = await tokenResponse.GetResponseAsync <Token>(true, "IdentityService/RequestPasswordTokenAsync", "Token alınırken beklenmedik bir hata ile karşılaşıldı"); logger.LogResponse(response); return(response); } Token result = mapper.Map <Token>(tokenResponse); response = Response <Token> .Success(result, (int)tokenResponse.HttpStatusCode); logger.LogResponse(response); return(response); }
public async Task <Response <string> > ConnectTokenAsync() { Response <string> response = null; ClientAccessToken currentToken = await clientAccessTokenCache.GetAsync("WebClientToken"); if (currentToken is not null) { response = Response <string> .Success(currentToken.AccessToken, StatusCodes.Status200OK); logger.LogResponse(response); return(response); } TokenResponse res = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest() { Address = "connect/token", ClientId = clientSettings.WebClient.ClientId, ClientSecret = clientSettings.WebClient.ClientSecret, Scope = "IdentityServerApi" }); if (res.IsError) { response = await res.GetResponseAsync <string>(true, "TokenService/ConnectTokenAsync", "Token alınırken beklenmedik bir hata ile karşılaşıldı"); logger.LogResponse(response); return(response); } await clientAccessTokenCache.SetAsync("WebClientToken", res.AccessToken, res.ExpiresIn); response = Response <string> .Success(res.AccessToken, (int)res.HttpStatusCode); logger.LogResponse(response); return(response); }