Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [AllowAnonymous]
- [HttpPost("refresh")]
- public async Task<ActionResult<object>> HandleRefresh([FromBody] RefreshRequest req)
- {
- if (req.RefreshToken == "") {
- return BadRequest();
- }
- using (var client = new HttpClient())
- {
- var uri = new Uri($"https://{_oktaOptions.Value.OktaDomain}/oauth2/{_oktaOptions.Value.AuthorizationServerId}/v1/token");
- var content = new FormUrlEncodedContent(new[] {
- new KeyValuePair<string, string>("grant_type", "refresh_token"),
- new KeyValuePair<string, string>("scope", "offline_access openid"),
- new KeyValuePair<string, string>("client_id", _oktaOptions.Value.ClientId),
- new KeyValuePair<string, string>("client_secret", _oktaOptions.Value.ClientSecret),
- new KeyValuePair<string, string>("refresh_token", req.RefreshToken)
- });
- var request = new HttpRequestMessage
- {
- Method = HttpMethod.Post,
- RequestUri = uri,
- Headers = {
- { "Accept", "application/json" },
- },
- Content = content
- };
- var response = await client.SendAsync(request);
- if (response.IsSuccessStatusCode) {
- return Ok(response.Content.ReadAsStringAsync().Result);
- }
- return BadRequest(response.Content.ReadAsStringAsync().Result);
- }
- }
- }
Add Comment
Please, Sign In to add comment