Reputation: 823
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:
http://mysite/complete/google-oauth2
, before I did that I got "unauthorized redirect url" from Google.In my settings.py I have
GOOGLE_OAUTH2_CLIENT_ID = '*****'
GOOGLE_OAUTH2_CLIENT_SECRET = '*****'
AUTHENTICATION_BACKENDS = (
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.facebook.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',
)
Whan am I doing wrong? How can I fix/debug that AuthCancelled exception?
Upvotes: 1
Views: 4076
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.
So if you are receiving the same error, make sure you define the redirect authorize URIs and check your spelling.
Upvotes: 0
Reputation: 1937
Use SocialAuthExceptionMiddleware middleware for proper handling social_auth exception
MIDDLEWARE_CLASSES = (
...,
'social_auth.middleware.SocialAuthExceptionMiddleware'
)
Upvotes: 1
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