public async Task <IActionResult> RefreshToken([FromForm] Request.RefreshTokenRequest refreshRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } HttpClient client = new HttpClient(); IdentityModel.Client.RefreshTokenRequest tokenRequest = new IdentityModel.Client.RefreshTokenRequest { Address = Discovery.LoginEndpoint, ClientId = refreshRequest.Client_id, ClientSecret = "bsd", RefreshToken = refreshRequest.RefreshToken, GrantType = "refresh_token" }; var response = await client.RequestRefreshTokenAsync(tokenRequest); //var tokenClient = new TokenClient(Discovery.LoginEndpoint, refreshRequest.Client_id,"bsd"); //var response = tokenClient.RequestRefreshTokenAsync(refreshRequest.RefreshToken).Result; if (response.HttpStatusCode != System.Net.HttpStatusCode.OK || response.IsError) { return(BadRequest(response.Error)); } return(Ok(response.Json)); }
/// <summary> /// Sends a token request using the refresh_token grant type. /// </summary> /// <param name="client">The client.</param> /// <param name="request">The request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public static async Task <TokenResponse> RequestRefreshTokenAsync(this HttpMessageInvoker client, RefreshTokenRequest request, CancellationToken cancellationToken = default) { var clone = request.Clone(); clone.Parameters.AddRequired(OidcConstants.TokenRequest.GrantType, OidcConstants.GrantTypes.RefreshToken); clone.Parameters.AddRequired(OidcConstants.TokenRequest.RefreshToken, request.RefreshToken); clone.Parameters.AddOptional(OidcConstants.TokenRequest.Scope, request.Scope); return(await client.RequestTokenAsync(clone, cancellationToken).ConfigureAwait(false)); }