1

I have a ASP.NET MVC application that uses oauth2 to authenticate googleplus users.

My problem is that the "OnAuthenticated" handler is never getting called even though the authentication is successful (ExternalLogin callback fires and i'm able to see that i'm logged in into google).

Can someone help me understand why the OnAuthenticated handler is not getting called and what mistake I'm doing? Thanks for all your help !

Here is the code i'm using in my startup.auth.cs

using Owin.Security.Providers.GooglePlus;
...
...
var googlePlusOptions = new GooglePlusAuthenticationOptions
        {
            ClientId = googleClientId,
            ClientSecret = googleClientSecret,
            SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            Provider = new Owin.Security.Providers.GooglePlus.Provider.GooglePlusAuthenticationProvider()
            {
                OnAuthenticated = (context) =>
                {
                    context.Identity.AddClaim(new System.Security.Claims.Claim("urn:googleplus:accesstoken", context.AccessToken, System.Security.Claims.ClaimValueTypes.String, "Facebook"));
                    foreach (var x in context.User)
                    {
                        var claimType = string.Format("urn:googleplus:{0}", x.Key);
                        string claimValue = x.Value.ToString();
                        if (!context.Identity.HasClaim(claimType, claimValue))
                            context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, System.Security.Claims.ClaimValueTypes.String, "Facebook"));

                    }
                    return System.Threading.Tasks.Task.FromResult(0);
                }
            },
        };

        googlePlusOptions.Scope.Add("email");
        app.UseGooglePlusAuthentication(googlePlusOptions);

Best Regards,

2P

2
  • I have the same issue with google plus, my facebook providers OnAuthenticated is working fine. Did you get any further with this? Commented Aug 8, 2014 at 13:57
  • Yes. I have added that as an answer. Let me know if that is helpful for you. Never thought someone else would hit it and did not answer it earlier :) Commented Aug 19, 2014 at 6:15

1 Answer 1

0

I finally figured out what the issue was...

Debugging: 1. found that even though the call back was called, the isAuthenticated field was set to false indicating something went wrong causing the controller action to redirect to login page. 2. Using fiddler found that the response I got from google said that there is an issue with the redirect URIs or permission was not set properly. In my case it was a redirect URI problem.

RESOLUTION: Went to the google developer console. Go to APIs&Auth --> Credentials --> Edit Settings.

Ensured that the redirect uri is added to the list like https://www.yoursite.com/signin-googleplus.

NOTE: You need to add http and https separately as two entries.

That helped be get unblocked. Hope this works for you as well.

Best Regards, 2P

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.