如何从oauth2.0注销windows azure活动目录身份验证

Abh*_*hek 5 authentication cookies azure oauth-2.0 azure-connect

我们使用auth2.0进行windows azure活动目录身份验证,其中在https://login.microsoftonline.com/login.srf?wa=wsignin1.0&wtrealm=上执行身份验证,并且在成功进行身份验证后,我们将重定向到我们的网站.要注销该网站,我们会删除在我们网站上生成的所有Cookie,并再次重定向到login.microsoftonline.com/login.srf?wa=wsignin1.0&wtrealm = .......网址,但此时我们还没有收到任何登录凭据屏幕,并使用访问令牌重定向到我们的站点.注销需要什么过程.因为如果我们删除所有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"); 
       }
Run Code Online (Sandbox Code Playgroud)

ast*_*kov 2

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

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

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

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());
} 
Run Code Online (Sandbox Code Playgroud)

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