Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function

Tags:

I am currently upgrading my login process for Google to use OAuth before they depricate their OpenID login method.

The steps I have Identified so far is that I have upgraded the package Microsoft.Owin.Security.Google to version 2.1.0 as this version includes the ability to include options in the UseGoogleAuthentication method.

I have tried to use Alex Wheat's Solution in the link: Get ExtraData from MVC5 framework OAuth/OWin identity provider with external auth provider

The code in Startup.Auth.cs (which also includes Facebook authentication) goes from this:

    var facebookAuthenticationOptions = new FacebookAuthenticationOptions()         {             AppId = "MYAPPID",             AppSecret = "MYSECRET"         };         facebookAuthenticationOptions.Scope.Add("email");         app.UseFacebookAuthentication(facebookAuthenticationOptions);          app.UseGoogleAuthentication(); 

To this:

var facebookAuthenticationOptions = new FacebookAuthenticationOptions()         {             AppId = "MYAPPID",             AppSecret = "MYSECRET"         };         facebookAuthenticationOptions.Scope.Add("email");         app.UseFacebookAuthentication(facebookAuthenticationOptions);           var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions         {             ClientId = "MYCLIENTID",             ClientSecret = "MYSECRET",             CallbackPath = new PathString("/en/Account/ExternalLoginCallback"),             Provider = new GoogleOAuth2AuthenticationProvider()             {              }         };          app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions); 

After I add options to the Google Authentication, my app does not allow the ExternalLoginCallback action to be called for either google or facebook (no changes to facebook code but the issue still affects it).

On the front end, after clicking the external login buttons, the page redirects me to the link below and returns an empty white screen

https....../en/Account/ExternalLoginCallback#__=_ (There is actually only a single underscore before the = sign, SO syntax removes it if I have it as it appears on my address bar).

for facebook and

https....../en/Account/ExternalLoginCallback

for google. It does not hit the controller method below as it normally does (I have tried to place debug breakpoints within this function and it never gets stopped when there are google authentication options.

    // GET: /Account/ExternalLoginCallback     [AllowAnonymous]     public async Task<ActionResult> ExternalLoginCallback(string returnUrl)     { 

If I remove the authentication options from Google Authentication, it just reverts back to the old OpenID login and works fine again.

Am I missing something simple here? or is there something bad happening inside the Owin.Security.Google Library that is causing the problem?


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!