IT/Django

Setup django-allauth social login

bepuri 2022. 9. 8. 11:42
728x90

Follow this official documents.
https://django-allauth.readthedocs.io/en/latest/installation.html
I just summarized in this post.

poetry add django-allauth

After installation done

Follow this

urls.py
urlpatterns = [
    ...
    path('accounts/', include('allauth.urls')),
    ...
]

Important! You must include the providers you want to use.

settings.py

AUTHENTICATION_BACKENDS = [
    'allauth.account.auth_backends.AuthenticationBackend',
]

INSTALLED_APPS = [
    ...
    # The following apps are required:
    'django.contrib.auth',
    'django.contrib.messages',
    'django.contrib.sites',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
]
...


LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

SOCIALACCOUNT_LOGIN_ON_GET = True
ACCOUNT_LOGOUT_ON_GET = True

SOCIALACCOUNT_PROVIDERS = {
    "google": {
        "APP": {
            "client_id": GOOGLE_CLIENT_ID,
            "secret": GOOGLE_CLIENT_SECRET,
            "key": "",
        }
    },

Those detailed options are explained in offical document.
You can see login page with http://127.0.0.1:8000/accounts/google/login/

728x90