【问题标题】:How to log out from application but not from Azure AD?如何从应用程序而不是 Azure AD 中注销?
【发布时间】:2022-01-09 02:28:21
【问题描述】:

在我的 Asp.Net MVC 应用程序中,我最近集成了 Azure AD 身份验证。登录工作正常,但我无法正确注销。我只想从我的应用程序中注销用户,而不是“单点注销”。我读过的所有内容都是关于单点注销的。这是我尝试过的:

  1. 放弃会话并重定向到登录页面。在 Html.AntiForgeryToken() 语句的登录页面上抛出与缺少声明相关的错误

    Session.Abandon();
    return RedirectToAction("Index", "Login");
    
  2. 这与 #1 有相同的错误

    FederatedAuthentication.SessionAuthenticationModule.SignOut();
    FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie();
    return RedirectToAction("Index", "Login");
    
  3. 这需要用户单点退出

    HttpContext.GetOwinContext().Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
    

【问题讨论】:

  • 你好@Apeksha,有什么更新吗?!?如果提供的解决方案有效,您能否接受它作为帮助其他社区成员解决类似问题的答案。

标签: asp.net-mvc azure-ad-b2c logout


【解决方案1】:

以下是@Jan Hajek here 建议的一些解决方法

  • 确保 Azure AD 在您的 .NET 应用程序中列为连接服务。 这将防止单次注销。

  • 我们可以在controller 中创建单点注销端点,如下例所示

return SignOut(
    new AuthenticationProperties
    {
        RedirectUri = callbackUrl,
    },
    CookieAuthenticationDefaults.AuthenticationScheme
);

注意:-当我们点击注销时,它会清除正确的 cookie,因为用户会话(在 Razor 页面和 MVC 的情况下)存储在 Cookies 中。

我们还可以将redirect logout url(例如-“<your-doman>/.auth/logout”)设置为应用程序本身的主页,在该主页上要求再次登录。

更多信息请参考以下链接

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多