Search code examples
oauthasp.net-mvc-5google-oauth

Google OAuth on MVC5 ExternalLoginCallback?error=access_denied


I have set up my Google OAuth

enter image description here

And I have added the code into Startup.Auth.cs

 app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
    {
        // LRC
        ClientId = "xxxxxxxxx",
        ClientSecret = "xxxxx"
        //CallbackPath = new PathString("/signin-google")
    });

But after I chose a google account to log in, it redirected me to the login page again,

I checked the network via Chrome and found that the access was denied.

http://www.liferunningclub.com.au/Account/ExternalLoginCallback?error=access_denied

I cannot figure it out.


Update Now I did something else:

  1. I added an annotation ([RequireHttps]) on the Account Controller
  2. I enabled the SSL for my project.
  3. I updated the url and re-direct url in Google Console to https

Tried to log in with Google, after I selected my Google account, it returned the same access_denied.

It would be better if the response from Google could give more detailed information.


Solution

  • I had the same problem using the latest ASP.Net MVC template with "Individual Accounts" selected.

    The solution was to enable the Google+ API for my project in the Google Developer console.

    I found my answer here (scroll down to "Changes to Google OAuth 2.0...").