Ivailo Karamanolev
Ivailo Karamanolev

Reputation: 823

Django Social Auth (Google OAuth 2) - AuthCancelled even when "Allow access" is clicked

I am successfully using Django Social Auth to login users with Facebook. I'm trying to implement Google OAuth2. I have taken all the steps I know of to integrate it, but I'm getting an AuthCanceled at /complete/google-oauth2/ exception even when I click Allow access. Here's what I did to integrate it:

Whan am I doing wrong? How can I fix/debug that AuthCancelled exception?

Upvotes: 1

Views: 4076

Answers (3)

Vinay Khatri
Vinay Khatri

Reputation: 330

I also faced the same error when I tried the social-auth-app-django library for social authentication. And I was receiving the following error.

AuthCanceled at /social-auth/complete/google-oauth2/

Two silly mistakes lead to this error.

  1. Not defining the redirect Authorized redirect URIs in the Client ID for the Web application.(set it to http://localhost:8000/social-auth/complete/google-oauth2/)
  2. The spelling mistake for SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET

So if you are receiving the same error, make sure you define the redirect authorize URIs and check your spelling.

Upvotes: 0

Sergey Lyapustin
Sergey Lyapustin

Reputation: 1937

Use SocialAuthExceptionMiddleware middleware for proper handling social_auth exception

MIDDLEWARE_CLASSES = (
    ...,
    'social_auth.middleware.SocialAuthExceptionMiddleware'
)

Upvotes: 1

Ivailo Karamanolev
Ivailo Karamanolev

Reputation: 823

The problem appears to be caused by a strange Google behavior: when I initially created my client ID, google gave me this client ID: 193271111225.apps.googleusercontent.com. After a conversation with the library author, he told me that his ids were much longer, so I created a new client ID with the exact same settings. The new ID generated was 193271111225-cvltnldi4hh5lmo784v2ir451b3rij7e.apps.googleusercontent.com and with it, it worked. Both IDs look the same in the console, but only the latter works.

Upvotes: 3

Related Questions