【问题标题】:how to logout from oauth2.0 authentication of windows azure active directory authentication如何从 Windows azure Active Directory 身份验证的 oauth2.0 身份验证中注销
【发布时间】:2013-09-22 22:24:38
【问题描述】:

我们正在使用 auth2.0 进行 Windows azure Active Directory 身份验证,其中身份验证是在 https://login.microsoftonline.com/login.srf?wa=wsignin1.0&wtrealm=...... 上执行的,并且在身份验证成功后,我们将重定向到我们的站点。 为了注销该站点,我们删除了我们站点上生成的所有 cookie 并再次重定向到 login.microsoftonline.com/login.srf?wa=wsignin1.0&wtrealm=....... url,但此时我们没有得到任何登录凭据屏幕和 使用访问令牌重定向到我们的网站。注销需要什么流程。因为如果我们删除所有 cookie 或关闭浏览器并重新打开该站点并将我们重定向到 login.microsoftonline.com/login.srf?wa=wsignin1.0&wtrealm=........ url。

我们正在使用以下代码进行注销过程

    [NoCacheAttribute]
    public ActionResult LogOut()
    {
   UserCookieWrapper.delete_UserCookieWrapper();
     //This function delete all the datamemeber of the UserCookieWrapper class                             

     string[] theCookies =   
    System.IO.Directory.GetFiles(Environment.GetFolderPath(
    Environment.SpecialFolder.Cookies));
        foreach(string currentFile in theCookies)
        {
           try
           {
              System.IO.File.Delete(currentFile);
           }
           catch(Exception objEx) { }

        }                    
        Response.Clear();
       return RedirectToAction("Index", "Login"); 
       }

【问题讨论】:

  • 看看这个帖子:stackoverflow.com/questions/14932241/…。本质上,您还需要从 Windows Azure Active Directory 中注销用户。
  • 但是这里我们使用的是 oauth2.0 身份验证而不是 WsFederation 那么我们如何注销。

标签: authentication cookies azure oauth-2.0 azure-connect


【解决方案1】:

清除您创建的 cookie 对您没有帮助,因为用户仍使用 Azure AD 登录。这就是howo Web-SSO(单点登录)的工作原理。无论您使用哪种协议对 Azure AD 进行身份验证,您仍然需要正确实施注销 - 联合注销!您可以在 Internet 上找到的 任何 web-sso 提供商就是这种情况 - Google、Facebook、LinkedIn、Twitter,应有尽有。

您所做的只是将用户从您的应用程序中注销,而不是从身份提供者。一旦您的应用程序将用户重定向到选定的身份提供者(在您的情况下为 AAD),如果用户与其有活动会话,则将看不到登录屏幕!

为了正确实施联合注销,您必须通读Implementing SSO with Azure Active Directory。您可以快进到“实施注销控制器”步骤。这将显示如下代码:

public void SignOut()
{
     WsFederationConfiguration fc = 
            FederatedAuthentication.FederationConfiguration.WsFederationConfiguration;

     string request = System.Web.HttpContext.Current.Request.Url.ToString();
     string wreply = request.Substring(0, request.Length - 7);

     SignOutRequestMessage soMessage = 
                     new SignOutRequestMessage(new Uri(fc.Issuer), wreply);
     soMessage.SetParameter("wtrealm", fc.Realm);

     FederatedAuthentication.SessionAuthenticationModule.SignOut();
     Response.Redirect(soMessage.WriteQueryString());
} 

请通读整个部分(最好是整篇文章)以了解代码的作用以及为什么必须这样做。

【讨论】:

  • 我们已经尝试使用上面的代码,但是我们在下面的行中得到了空异常错误。 SignOutRequestMessage soMessage = new SignOutRequestMessage(new Uri(fc.Issuer), wreply);//这里我们得到fc.Issuer值null
  • 您需要在 web.config 中配置 wsfederation。只是它不一定重定向!
  • 我在 web.config 文件中添加了 wsfederation 配置,但我再次得到 FederatedAuthentication.SessionAuthenticationModule.SignOut(); null 并抛出错误。
  • 您是否会使用您正在使用的确切代码(包括您的 web.config 的 system.identityModelsystem.identityModel.services 部分)、确切的错误和完整的堆栈跟踪来更新您的问题。否则我们无能为力。
  • 我已经复制了jsfiddle.net/JkBFe/3上的web配置设置cs文件代码,请检查并告诉我解决方案。
猜你喜欢
  • 1970-01-01
  • 2016-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-30
  • 1970-01-01
  • 1970-01-01
  • 2015-01-11
相关资源
最近更新 更多