GetExternalLoginInfoAsync null with OWIN in ExternalLoginCallback if it is not already logged into Google

I am trying to implement external logins with OWIN in an MVC5 application using a google account.

If Iโ€™ve already logged into Google, clicking the google button in my application is great, and it will lead me to my registration page after I have allowed me access to logininfo.

If I have not logged in to Google yet, when I click the Google Apps button for my applications, I will be prompted to log in to Google as expected, but the callback receiver does not seem to see that I'm logged in, since logininfo is always null in this script in the callback as shown 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 is almost like an external cookie is not available for OWIN until the request after entering Google.

+6
source share
1 answer

After several days of investigation, I finally came across an answer. The problem is that after logging into Google, it redirects back to the site and does not have permission to signin-google, so it redirects back to the login page. Not sure why this works if it is already signed up by Google. I discovered this after I found the article ...

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

I added the following to my configuration file.

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

Now it works ...

+7
source

Source: https://habr.com/ru/post/969540/


All Articles