Closed mynewcodingjourney closed 4 months ago
Did you install using pip install django-allauth[socialaccount]
?
Did you install using
pip install django-allauth[socialaccount]
?
No,
I've installed the entire package through pip install django-allauth, so it has downloaded all the social account providers, including Google and GitHub...
See this screenshot of my venv directory, which shows that django-allauth for Google exists:
Please read here: https://docs.allauth.org/en/latest/release-notes/recent.html#backwards-incompatible-changes
The [socialaccount]
extra makes sure that the dependencies (requests
, jwt
) for Google are installed. The google
provider is always there in your env, its dependencies are not. Can you give it a try?
Please read here: https://docs.allauth.org/en/latest/release-notes/recent.html#backwards-incompatible-changes
Thank you for pointing that out!
The
[socialaccount]
extra makes sure that the dependencies (requests
,jwt
) for Google are installed. The
I've installed the dependencies as per your suggestion, and everything seems to be working perfectly now. Appreciate the help!
I'm encountering two issues after setting up Django Allauth for authentication in my Django project:
I'm using, Ubuntu - Ubuntu 20.04.6 LTS (VS Code)
Here are the exact steps I followed to set up django-allauth in my project:
requirements.txt:
Generated by 'django-admin startproject' using Django 4.2.8.
For more information on this file, see https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see https://docs.djangoproject.com/en/4.2/ref/settings/ """
from pathlib import Path
Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(file).resolve().parent.parent
Quick-start development settings - unsuitable for production
See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-k8d%eq^(g8*eeo31lnaiogpl3x60h)5y9t15jup)_txf$9u2'
SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
Application definition
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.github', 'allauth.socialaccount.providers.google', ]
MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', "allauth.account.middleware.AccountMiddleware", ]
SOCIALACCOUNT_PROVIDERS = { 'github': { 'SCOPE': [ 'user', 'repo', 'read:org', ], }, 'google': { 'SCOPE': [ 'profile', 'email', ], 'AUTH_PARAMS': { 'access_type': 'online', }, 'OAUTH_PKCE_ENABLED': True, } }
ROOT_URLCONF = 'googlelogin.urls'
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]
AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend', 'allauth.account.auth_backends.AuthenticationBackend', ]
WSGI_APPLICATION = 'googlelogin.wsgi.application'
Database
https://docs.djangoproject.com/en/4.2/ref/settings/#databases
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } }
Password validation
https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ]
Internationalization
https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
Static files (CSS, JavaScript, Images)
https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = 'static/'
Default primary key field type
https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
from django.contrib import admin from django.urls import path, include
urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('allauth.urls')), ]
python manage.py migrate
python manage.py createsuperuser
{% extends 'base.html' %} {% load static %} {% load socialaccount %}
{% block extra_head %}
{% endblock %}
{% block dynamic_content %}
{% endblock %}