admin管理员组文章数量:1396114
I am working with OAuth in my ASP.NET API for a web app + mobile app, anyway lets use Google as an example here the user authenticates using the Google provider then Google calls my API and I issue a redirection to my web app / go back to mobile app.
When I authenticate with email using my own API, I typically send the refresh token and access token in API response, but since there is a redirection this is not allowed.
My question is: how do I handle sending tokens in OAuth while redirecting?
This is the method used for redirection:
[HttpGet("signin-google")]
[AllowAnonymous]
public async Task<IActionResult> GoogleResponse([FromQuery] string returnUrl, CancellationToken cancellationToken)
{
var authenticateResult = await HttpContext.AuthenticateAsync(GoogleDefaults.AuthenticationScheme);
if (!authenticateResult.Succeeded)
return BadRequest("Google authentication failed.");
var claims = authenticateResult.Principal.Identities.FirstOrDefault()?.Claims;
var email = claims?.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value;
// var ipAddress = HttpContext.Connection.RemoteIpAddress.MapToIPv6().ToString();
if (string.IsNullOrEmpty(email))
return BadRequest("Email not found");
var result = await _authenticationService.SignInWithProviderAsync("google", email, cancellationToken);
return result.Match<IActionResult, SignInResponse>(success =>
{
return Redirect("http://localhost:3000");
}, BadRequest);
}
本文标签: aspnet web apiSending tokens when redirectingStack Overflow
版权声明:本文标题:asp.net web api - Sending tokens when redirecting - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744117404a2591578.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论