This project has moved. For the latest updates, please go here.

GoogleOAuth2AuthenticationOptions.AuthenticationType

Sep 26, 2014 at 5:45 PM
Edited Sep 26, 2014 at 5:47 PM
I'm using ver.3.0 and the updated to Google middleware with code below
                string clientId = ConfigurationManager.AppSettings.Get("GoogleClientID");
                string clientSecret = ConfigurationManager.AppSettings.Get("GoogleClientSecret");

                var googleOptions = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions()
                {
                    ClientId = clientId,
                    ClientSecret = clientSecret,
                    SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
                    Provider = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationProvider()
                    {
                        OnAuthenticated = async context =>
                        {
                            context.Identity.AddClaim(new System.Security.Claims.Claim("urn:google:access_token", context.AccessToken, XmlSchemaString, "Google"));
                        }
                    }
                };

                googleOptions.Scope.Add("https://www.googleapis.com/auth/plus.login");
                googleOptions.Scope.Add("profile");
                googleOptions.Scope.Add("email");

                app.UseGoogleAuthentication(googleOptions);
However, it does NOT add Google provider. Then I added line below and it has fixed the issue.


googleOptions.AuthenticationType = "Google+";

(the last symbol is a plus)

I found out that GoogleOAuth2AuthenticationOptions constructor passed Constants.DefaultAuthenticationType = "Google" to the base class, i.e. the same as in deprecated GoogleAuthenticationOptions . At the same time I saw numerous samples to use Google provider with very simple code:
app.UseGoogleAuthentication(
         clientId: "000-000.apps.googleusercontent.com",
         clientSecret: "00000000000");
Could you explain what is the proper way to use the latest Google provider?
Coordinator
Sep 26, 2014 at 7:01 PM
Your code looks fine. They value of the AuthenticationType shouldn't matter so long as it's unique in your app. E.g. if you set up two google auth middleware then you'll need to assign them different auth types. Are you still using the old obsolete provider?

Check here to see what that last extension does:
https://katanaproject.codeplex.com/SourceControl/latest#src/Microsoft.Owin.Security.Google/GoogleAuthenticationExtensions.cs
Sep 26, 2014 at 7:47 PM
Sorry, everything is ok. I didn't realize that AuthenticationType is used in our code to generate the social signin buttons - that's why removing "Google+" was implicitely defaulted ApplicationType to "Google" and make the corresponding Sign In button hidden.