I have a blazor application and I have implemented the login and logout using openId connect. I was able to login and get authenticated. After authenticated, we are getting a link back like this
http://{domain}/login/token/redirect?stateToken=02.id.FG94TfF8YNNK-6CcVobVh0t0YhVVN2Fy2qkjH4xM
My controller code is as follows:
type or paste co [HttpGet("Login")]
public IActionResult Login([FromQuery] string returnUrl)
{
var redirectUri = returnUrl is null ? Url.Content("~/") : "/" + returnUrl;
if (User.Identity.IsAuthenticated)
{
return LocalRedirect(redirectUri);
}
return Challenge();
}
[HttpGet("Logout")]
public async Task<ActionResult> Logout([FromQuery] string returnUrl)
{
var redirectUri = returnUrl is null ? Url.Content("~/") : "/" + returnUrl;
if (!User.Identity.IsAuthenticated)
{
return LocalRedirect(redirectUri);
}
await HttpContext.SignOutAsync();
return LocalRedirect("/logout/100");
}
Questions
- How to capture the stateToken in the login method.
- When I click the logout button, it is redirecting to the login screen instead of my logout page…
If I commented out the await HttpContext.SignOutAsync(), then logout page is coming stating it is still Validateduser.
How to resolve the logout. Our requirement is as soon as I click the logout button, the user sessions should get cleared and redirect to the logout page.
Any help appriciated.
Thanks in advance