GetExternalLoginInfoAsync null with OWIN in ExternalLoginCallback unless already logged into google

瘦欲@ 提交于 2019-12-04 22:42:30

问题


I've been trying to implement external logins with OWIN in an MVC5 app using a google account.

If I'm already logged into google, clicking the google button in my app is fine and it takes me to my registration page after allowing me access to the logininfo.

If I'm not already logged into google when I click my applications google button, I get prompted to login with Google as expected but the call back receiver doesn't seem to see that I've logged in as logininfo is always null in this scenario in the callback as below...

    [AllowAnonymous]
    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {
        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

         if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }

        // Code omitted for brevity.
        }
    }

Does anyone have a workaround or explanation? It's almost like the external cookie isn't made available to OWIN until the request after logging into google.


回答1:


After days of investigation, I have eventually come across the answer. The problem seems to be that after logging into google, it redirects back to the site and doesn't have permission to signin-google so is redirected back to the login page. Not sure why this works if already signed into google though. I discovered this after finding the article...

http://blog.technovert.com/2014/01/google-openid-integration-issues-asp-net-identity/

I added the following to my config file.

<location path="signin-google">
 <system.web>
   <authorization>
     <allow users="*" />
   </authorization>
 </system.web>
</location>

It now works...



来源:https://stackoverflow.com/questions/23742086/getexternallogininfoasync-null-with-owin-in-externallogincallback-unless-already

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!