C
C#5mo ago
Alex

✅ Web API redirect back to client

I have a GET route that handles external authentication. On the client I have anchor <a href="myapi:8080/sign-in/external/Google">Google</a> to sign in with Google. If authentication is successful I want to return cookie (I'll change it later) and redirect back to client. I have one option to provide returnUrl but I'm not sure if it is a right solution. How can I do it?
[HttpGet("sign-in/external/{provider}")]
public IActionResult External([FromRoute] string provider)
{
AuthenticationProperties props =
_signInManager.ConfigureExternalAuthenticationProperties(provider, "/api/Accounts/external-callback");

return new ChallengeResult(provider, props);
}

[HttpGet("external-callback")]
public async Task<IActionResult> ExternalCallback()
{
...
// if authentication is success
return Ok();
}
[HttpGet("sign-in/external/{provider}")]
public IActionResult External([FromRoute] string provider)
{
AuthenticationProperties props =
_signInManager.ConfigureExternalAuthenticationProperties(provider, "/api/Accounts/external-callback");

return new ChallengeResult(provider, props);
}

[HttpGet("external-callback")]
public async Task<IActionResult> ExternalCallback()
{
...
// if authentication is success
return Ok();
}
<AnchorButton
href={`${import.meta.env.VITE_API_URL}/accounts/sign-in/external/Google`}
>Google</AnchorButtom>
<AnchorButton
href={`${import.meta.env.VITE_API_URL}/accounts/sign-in/external/Google`}
>Google</AnchorButtom>
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server