public async Task <AjaxResult <CustomTokenResponse> > RefreshToken(RefreshTokensRequest refreshTokensRequest) { AjaxResult <CustomTokenResponse> ajaxResponse = new AjaxResult <CustomTokenResponse>("刷新Token成功"); HttpClient refreshTokenClient = HttpClientFactory.CreateClient("Identityserver4Client"); var refreshTokenResponse = await refreshTokenClient.RequestRefreshTokenAsync(new RefreshTokenRequest { Address = refreshTokenClient.BaseAddress + "connect/token", ClientId = "mobileAppClient", ClientSecret = "mobile app secrect", RefreshToken = refreshTokensRequest.RefreshToken }); if (refreshTokenResponse.IsError) { ajaxResponse.Success = false; ajaxResponse.Content = refreshTokenResponse.Error; return(ajaxResponse); } var idToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.IdToken); var expiresAt = DateTime.UtcNow + TimeSpan.FromSeconds(refreshTokenResponse.ExpiresIn); var tokens = new[] { new AuthenticationToken { Name = OpenIdConnectParameterNames.IdToken, Value = idToken }, new AuthenticationToken { Name = OpenIdConnectParameterNames.AccessToken, Value = refreshTokenResponse.AccessToken }, new AuthenticationToken { Name = OpenIdConnectParameterNames.RefreshToken, Value = refreshTokenResponse.RefreshToken }, new AuthenticationToken { Name = "expires_at", Value = expiresAt.ToString("o", CultureInfo.InvariantCulture) } }; var authenticationInfo = await HttpContext.AuthenticateAsync(HybridConsts.LocalApi.AuthenticationScheme); authenticationInfo.Properties.StoreTokens(tokens); //// 登录 //await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, // authenticationInfo.Principal, authenticationInfo.Properties); //await HttpContext.SignInAsync(HybridConsts.LocalApi.AuthenticationScheme, authenticationInfo.Principal, authenticationInfo.Properties); await HttpContext.SignInAsync(authenticationInfo.Principal, authenticationInfo.Properties); ajaxResponse.Result = new CustomTokenResponse { AccessToken = refreshTokenResponse.AccessToken, RefreshToken = refreshTokenResponse.RefreshToken, ExpiresIn = refreshTokenResponse.ExpiresIn, IdentityToken = refreshTokenResponse.IdentityToken, TokenType = refreshTokenResponse.TokenType }; return(ajaxResponse); }
public async Task RefreshTokensAsync(RefreshTokensRequest request) { await EnsureInGroupAsync(request); var response = await _service.RefreshTokensAsync(request); SendGroupResponse(response); }
public async Task <GetTokensResponse> RefreshTokensAsync(RefreshTokensRequest request) { EnsureOAuthLoginClientExistence(request); var tokenClient = new TokenClient(GetOAuthEndpointUri("token").AbsoluteUri, request.OAuthClient.ClientId, request.OAuthClient.ClientSecret); var result = await tokenClient.RequestRefreshTokenAsync(request.RefreshToken); var response = CreateTokenResponse(request, result, request.RedirectUriOnSuccess, request.RedirectUriOnFailure); return(response); }
public RefreshTokensRequestHandler(Request request, ClientConnection clientConnection, ITokensService tokensService) { this.request = (RefreshTokensRequest)request; this.clientConnection = clientConnection; this.tokensService = tokensService; }
public async Task <HttpResponseMessage> RefreshTokensAsync(RefreshTokensRequest request) { var response = await _service.RefreshTokensAsync(request); return(Request.CreateResponse(response)); }
public async Task <RefreshTokensResponse> RefreshTokens(RefreshTokensRequest request) { return(await PostAsync <RefreshTokensRequest, RefreshTokensResponse>( request, CreateUri(HydraServices.AuthService1, HydraMethods.RefreshTokens))); }