Django allauth refuse to recognize google socialaccount

I encountered a weird behavior that is really frustrating.

# settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',

    # custom apps
    'a_core',
    'a_user',

    # allauth
    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    # providers for social accounts
    'allauth.socialaccount.providers.github',   
    'allauth.socialaccount.providers.google',
]

AUTHENTICATION_BACKENDS = [
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such as login by e-mail
    'allauth.account.auth_backends.AuthenticationBackend',
    
]

LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

SOCIALACCOUNT_PROVIDERS = {
    'google': { # WHY CANT GOOGLE CONFIG PROPERLY?
        'SCOPE' : [
            'profile',
            'email'
        ],
        'APP': {
            'client_id': os.environ['GOOGLE_AUTH_CLIENT_ID'],
            'secret': os.environ['GOOGLE_AUTH_CLIENT_SECRET'],
            'key': '',
        },
    },
    'github': {
        'SCOPE' : [
            'profile',
            'email'
        ],
        'APP': {
            'client_id': os.environ['GOOGLE_AUTH_CLIENT_ID'],
            'secret': os.environ['GOOGLE_AUTH_CLIENT_SECRET'],
            'key': '',
        },
        'AUTH_PARAMS': {
            'access_type':'online',
        }
    }
}
# login.html

<a href="{% provider_login_url 'google' %}"  Login with social </a>

>>> raise ImproperlyConfigured(f"unknown provider: {app.provider}")
django.core.exceptions.ImproperlyConfigured: unknown provider: google
[13/May/2024 13:36:30] "GET /accounts/login/ HTTP/1.1" 500 128820
# login.html

<a href="{% provider_login_url 'github' %}"  Login with social </a>

>>> Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

[13/May/2024 13:43:25] "GET /accounts/login/ HTTP/1.1" 200 5243
[13/May/2024 13:43:27] "GET /accounts/github/login/ HTTP/1.1" 200 1536
[13/May/2024 13:43:29] "GET /accounts/login/ HTTP/1.1" 200 5243

Somehow, my login template was able to load a github social account URL using the wrong config, but complains when provider_login_url was set to google.

From Google cloud console Client ID for Web application, I’ve already set the necessary URLs for development.

Authorized JavaScript origins
For use with requests from a browser
URIs 1 
http://127.0.0.1:8000
URIs 2 
http://localhost:8000

Authorized redirect URIs
For use with requests from a web server
URIs 1 
http://127.0.0.1:8000/
URIs 2 
http://127.0.0.1:8000/accounts/google/login/callback/
URIs 3 
http://localhost:8000/accounts/google/login/callback/
URIs 4 
http://localhost:8000/

I went through a couple tutorials that all said the same thing, somehow I was unable to get around this problem. I tried a wrong URL to check the URLs django registers:

Django tried these URL patterns, in this order:

admin/
accounts/ login/ [name='account_login']
accounts/ logout/ [name='account_logout']
accounts/ inactive/ [name='account_inactive']
accounts/ signup/ [name='account_signup']
accounts/ reauthenticate/ [name='account_reauthenticate']
accounts/ email/ [name='account_email']
accounts/ confirm-email/ [name='account_email_verification_sent']
accounts/ ^confirm-email/(?P<key>[-:\w]+)/$ [name='account_confirm_email']
accounts/ password/change/ [name='account_change_password']
accounts/ password/set/ [name='account_set_password']
accounts/ password/reset/ [name='account_reset_password']
accounts/ password/reset/done/ [name='account_reset_password_done']
accounts/ ^password/reset/key/(?P<uidb36>[0-9A-Za-z]+)-(?P<key>.+)/$ [name='account_reset_password_from_key']
accounts/ password/reset/key/done/ [name='account_reset_password_from_key_done']
accounts/ 3rdparty/
accounts/ social/login/cancelled/
accounts/ social/login/error/
accounts/ social/signup/
accounts/ social/connections/

accounts/ github/ <<< where did google go???

accounts/ login/cancelled/ [name='socialaccount_login_cancelled']
accounts/ login/error/ [name='socialaccount_login_error']
accounts/ signup/ [name='socialaccount_signup']
accounts/ [name='socialaccount_connections']

EDIT:
The missing URL for google is resolved after I downgraded django-allauth version from 0.62.1 to 0.61.0.

I raised an issue to the repo. Unable to find google provider · Issue #3801 · pennersr/django-allauth · GitHub

2 Likes

Yes! Frustrating trying to get this to work… Your suggestion to downgrade to 0.61.0 did the trick. Many thanks.

Thanks Your suggestion worked.