Identity: Google authentication fails in new project

Created on 14 Jul 2015  路  6Comments  路  Source: aspnet/Identity

I'm trying to get Google authentication to work on a new project created with Visual Studio 2015 RC.

To reproduce, create a new project from VS, in ConfigureServices add the following lines:

``` c#
services.Configure(options => {
options.ClientId = "xxx.apps.googleusercontent.com";
options.ClientSecret = "xxx";
});

and then the `Configure` method, add the following line:

``` c#
app.UseGoogleAuthentication();

This is how I have configured OAuth for Google:
screen shot 2015-07-14 at 19 05 55

This is my dependencies in project.json:

"dependencies": {
  "EntityFramework.SqlServer": "7.0.0-beta5",
  "EntityFramework.InMemory": "7.0.0-beta5",
  "EntityFramework.Commands": "7.0.0-beta5",
  "Microsoft.AspNet.Mvc": "6.0.0-beta5",
  "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
  "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
  "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
  "Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
  "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
  "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
  "Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
  "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta5",
  "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta5",
  "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta5",
  "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
  "Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
  "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
  "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta5",
  "Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
  "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
  "Microsoft.Framework.Logging": "1.0.0-beta5",
  "Microsoft.Framework.Logging.Console": "1.0.0-beta5",
  "Kestrel": "1.0.0-beta5"
}

The error message in the console gives me a 403 even though I successfully login with my Google account. Are there any configuration I'm missing?

error   : [Microsoft.AspNet.Authentication.Google.GoogleAuthenticationMiddleware] Authentication failed
System.Net.Http.HttpRequestException: Response status code does not indicate success: 403 (Forbidden).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Microsoft.AspNet.Authentication.Google.GoogleAuthenticationHandler.<GetUserInformationAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.AspNet.Authentication.OAuth.OAuthAuthenticationHandler`2.<AuthenticateCoreAsync>d__8.MoveNext()

Most helpful comment

Because I had the very same problem and was a bit puzzled by the answer, here's a guide:

  • In the Google Developers Console, select your project
  • go to APIs & auth, Social APIs, Google+ API
  • enable that one

After that, the application defined under Credentials should be able to login with the openid profile email scopes.

All 6 comments

It works when I use the API-key from the sample project so I guess it's my configuration that is wrong, can you show me how your account is configured?

You probably didn't turn on API/Google plus access or something like that, there's some other detailed setting that you need to enable for google auth to work.

Oh embarrassing, it was the Google+API, thanks for your help

Because I had the very same problem and was a bit puzzled by the answer, here's a guide:

  • In the Google Developers Console, select your project
  • go to APIs & auth, Social APIs, Google+ API
  • enable that one

After that, the application defined under Credentials should be able to login with the openid profile email scopes.

Thanks!!!

Had the same thing after I changed from our staging google's project to the production's one.
@HaoK is it possible to make the error clearer?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vaylandt picture Vaylandt  路  9Comments

panchengtao picture panchengtao  路  7Comments

danroth27 picture danroth27  路  4Comments

jholovacs picture jholovacs  路  4Comments

VR-Architect picture VR-Architect  路  6Comments