I have used Azure AD B2C User Flow to login a user in my application.
I have added the [Authorize] Attribute on my Controller Action Method.
[Authorize]
public IActionResult AuthenticateUser()
{
return RedirectToAction("LoginUser", profile);
}
Here is my ConfigureServices Method in Startup.cs (just for reference)
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(Configuration, "AzureAd")
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { "" })
.AddDownstreamWebApi("MyApi", Configuration.GetSection("MyApi"))
.AddInMemoryTokenCaches();
}
Now user login is working fine, and then I try to logout user like this:
public IActionResult LogoutUser()
{
try
{
HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
}
catch { }
finally
{
HttpContext.Session.Clear();
}
string logoutUrl = "https://MY_WEB_APP.b2clogin.com/MY_WEB_APP.onmicrosoft.com/b2c_1_ss_signin_signup_uf/oauth2/v2.0/logout?post_logout_redirect_uri=https://MY_WEB_APP.com/my_logout_redirect_url";
return Redirect(logoutUrl);
}
But after logout when I get back to the AuthenticateUser Action method in my application it automatically authenticates the user I just sign out from.
May be its because of browser cache that is automatically signing the user again on the User Flow Login Page.