microsoft-edge - Azure AD B2C 未在 Edge 中正确注销
问题描述
从 Microsoft 的 AD B2C示例中,我能够在所有浏览器中成功登录和注销我自己的租户,除了 Edge,其中注销行为异常。
问题:在 Edge 中注销并随后尝试新登录时,浏览器会快速重定向到 Azure,然后之前的用户似乎被 Azure自动登录,而没有提示输入凭据。这显然不是我们想要的。
实际上,在 Edge 中注销似乎根本不成功,我们必须等待 Azure 会话超时才能再次尝试正确登录。这仅在部署的开发实例中发生,而不是在 Edge 中本地运行时发生。
问题:是否有一些解决方法可以让完全注销以在 Edge 中工作?为什么我只能在 Edge 中遇到这种情况?
登录方式:
public void Login( )
{
//Use the default policy (specified in Startup.Auth) to process the sign up / sign in flow
if (!Request.IsAuthenticated)
{
HttpContext.GetOwinContext().Authentication.Challenge();
return;
}
Response.Redirect("/");
}
注销方法:
/*
* Called when requesting to sign out
*/
public void SignOut( )
{
// To sign out the user, you should issue an OpenIDConnect sign out request.
if (Request.IsAuthenticated)
{
IEnumerable<AuthenticationDescription> authTypes = HttpContext.GetOwinContext().Authentication.GetAuthenticationTypes();
HttpContext.GetOwinContext().Authentication.SignOut( authTypes.Select(t => t.AuthenticationType).ToArray());
}
}
我尝试添加 Session.RemoveAll();
Session.Abandon();
注销,但没有奏效。
启动方法也如示例中所示。
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
...);
...
解决方案
请参考 Azure 文档中的描述:
当您想让用户退出应用程序时,仅清除应用程序的 cookie 或以其他方式结束与用户的会话是不够的。您还必须将用户重定向到 Azure AD 才能注销。如果您不这样做,用户可能无需再次输入他们的凭据即可重新验证您的应用程序。这是因为他们将与 Azure AD 进行有效的单点登录会话。
因此,您可以简单地将用户重定向到 end_session 端点:
GET https://fabrikamb2c.b2clogin.com/fabrikamb2c.onmicrosoft.com/oauth2/v2.0/logout?
p=b2c_1_sign_in
&post_logout_redirect_uri=https%3A%2F%2Faadb2cplayground.azurewebsites.net%2F
更多详细信息,请参阅Azure Active Directory B2C:使用 OpenID Connect 进行 Web 登录
推荐阅读
- google-cloud-dataproc - Knox 进程消耗 Dataproc 主节点中的所有资源
- python - Python JSON 更新未按预期工作
- node.js - 成功部署的应用程序无法访问 POSTGRES - HEROKU
- python - 如何避免在 Python 中为变量分配任何内容?
- ckeditor - 向ckeditor5 onchange中的元素添加属性
- javascript - NextJS:使用自定义服务器(NestJS)呈现特定页面
- cmake - 使用 cpack 时设置 CMAKE_INSTALL_PREFIX
- javascript - 函数作为带参数的函数的参数
- arrays - 使用复选框进行反应过滤
- r - 手动将图例添加到 ggplot2 绘图