Saravanan
Saravanan

Reputation: 7844

Google Authentication via owin returns access denied

I am using google owing middleware for authentication

The following is my middleware setup

 app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            //AuthenticationType = AuthServerConstants.PrimaryAuthenticationType
            AuthenticationMode = AuthenticationMode.Passive,
            AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            ExpireTimeSpan = TimeSpan.FromMinutes(30)
        }).UseExternalSignInCookie(AuthServerConstants.ExternalAuthenticationType);

The following is my google Middleware

var google = new GoogleOAuth2AuthenticationOptions
        {
            ClientId = AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppId),
            ClientSecret = AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppSecret),
            SignInAsAuthenticationType = signInAsType,
            AuthenticationMode = AuthenticationMode.Passive
        };
        app.UseGoogleAuthentication(google);

I have enabled the Google+API in the google developer console

enter image description here

I am using Google Middleware version 2.1. My google authentication still returns error=access_denied

can anyone let me know what could have been missed out in this process.

NOTE My external authentication cookie middleware does not set the cookie yet in the browser.

Upvotes: 1

Views: 3443

Answers (2)

Dipendu Paul
Dipendu Paul

Reputation: 2753

I faced the same issue lately. In my case I had to enable Google+ API on Google developer console. You can enable the Google+ API by first typing the name on "Find product and services" search box and then by clicking on "Enable" button.

Upvotes: 0

DSR
DSR

Reputation: 4668

Actually, April 20, 2014 the Open ID was deprecated, because of that we can't use

app.UseGoogleAuthentication();

instead, we have to create project using Goolge Console. Then you need to update your code same as you did with 'ClientId' and 'ClientSecret'.

Your code should look like

app.UseGoogleAuthentication(AppSettingHelpers.GetValue<string>(AppSettingConstan‌​ts.GoogleAppId),     AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppSecret));

Note that: You should be careful when providing Redirect URIs when creating project on Google console. Because the Redirect URIs may look like

 http://YourDomain/signin-google 
LocalHost - https://YourLocalHost/signin-google

This works for me.

Hope this helps.

Upvotes: 1

Related Questions