I have Asp.net Core Identity version 2.0 Set up and running. I am finding that _signinManager.SignoutAsync is not logging out user once they have signed in with Google. When I go back to my Login Method it just shows the User as logged in with their Claims object still intact.
The code is really simple as below
[AllowAnonymous]
public ActionResult TestGoogle()
{
var redirectUrl = Url.Action(nameof(ExternalCallback), "Account", new { ReturnUrl = "" });
var properties = _signInManager.ConfigureExternalAuthenticationProperties("Google", redirectUrl);
return Challenge(properties, "Google");
}
public async Task<IActionResult> LogOff()
{
await _signInManager.SignOutAsync();
return RedirectToAction(nameof(HomeController.Index), "Home");
}
The problem is that your
RedirectToActionoverwrites the redirect to the Identity Server endsession URL thatSignOutAsyncissues.As for
SignOutAsync, what is obsolete is theAuthenticationportion -- as of ASP.NET Core 2.0 it's an extension directly offHttpContextitself.(The same explanation for the same signout problem is given here by Microsoft's HaoK.)
Edit: The solution is to send a redirect URL in an
AuthenticationPropertiesobject with the finalSignOutAsync: