OWIN - Authentication.SignOut() doesn't remove cookies

前端 未结 1 1022
别跟我提以往
别跟我提以往 2020-12-10 06:49

I have a MVC Web App in Azure with AD authentication. When I run the website locally, it signs in and out just fine, using Azure AD. But the signout on my deployed Azure w

相关标签:
1条回答
  • 2020-12-10 07:20

    I have figured out what the issue is. The out-of-the-box MVC Web App in Azure with AD authentication that I created uses AspNet cookies. Which the GetOwinContext().Authentication.SignOut clears. And this was working fine for me on localhost. The issue arose when I deployed it to Azure and then configured the website in the new Azure portal, to use AD authentication. It appears to convert the website into a Azure App Service. Now the cookies are AppServiceAuthSession cookies - no longer the AspNet cookies. Thus, the logout no longer works.

    Here is the response from the Microsoft rep that I worked with on this:

    I did some more research around this, and spoke with both the Azure AD teams and Azure Websites teams. Apparently that new portal setting takes care of all the auth components for you. So really you have two approaches to setting up Auzre AD auth against your website. You can do it through code like you see in that Out of the Box ASP.NET MVC project, where you have access to the AccountController.

    Or the other approach is to just let Azure handle it for you by enabling that setting in the new Azure portal. When you let the new Azure portal do it then it uses a different session cookie name and different logout logic. It appears that automatic auth doesn’t play well with the coded logout logic.

    So your workaround is correct. You basically have two workarounds here to get an MVC app up and running that supports Azure AD authentication:

    1. Create MVC app that supports AAD auth through code. Manually add application to that Azure AD tenant Applications list to setup the trust. Handle login/logout through code in your MVC app
    2. Create an MVC app that doesn’t have any auth logic. Configure it to support Azure AD auth through the new portal. Add some specific links for logging in and logging out. For this second scenario I recommend you pull down and play with the sample here: https://github.com/btardif/Websites-Authentication-Authorization. That sample you can see supports a Sign Out link, but it taps into the new Authentication/Authorization settings in that new portal. Deploy that sample to new website, enable Auth settings in the new portal, and you’ll see the signout works and properly deletes those auth session cookies correctly.
    0 讨论(0)
提交回复
热议问题