Skip to content

Commit 2519675

Browse files
Merge pull request #2 from ansuha/google-login-support
Google login support using social-auth-app-django
2 parents ab325af + 585e7a2 commit 2519675

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

pollme/settings.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34+
'social_django',
3435
'django.contrib.admin',
3536
'django.contrib.auth',
3637
'django.contrib.contenttypes',
@@ -39,14 +40,12 @@
3940
'django.contrib.staticfiles',
4041
'polls.apps.PollsConfig',
4142
'accounts.apps.AccountsConfig',
42-
'allauth',
43-
'allauth.account',
4443
]
4544

46-
AUTHENTICATION_BACKENDS = [
47-
'allauth.account.auth_backends.AuthenticationBackend',
48-
]
49-
45+
AUTHENTICATION_BACKENDS = (
46+
'social_core.backends.google.GoogleOAuth2',
47+
'django.contrib.auth.backends.ModelBackend',
48+
)
5049

5150
MIDDLEWARE = [
5251
'django.middleware.security.SecurityMiddleware',
@@ -56,7 +55,6 @@
5655
'django.contrib.auth.middleware.AuthenticationMiddleware',
5756
'django.contrib.messages.middleware.MessageMiddleware',
5857
'django.middleware.clickjacking.XFrameOptionsMiddleware',
59-
'allauth.account.middleware.AccountMiddleware',
6058
]
6159

6260
ROOT_URLCONF = 'pollme.urls'
@@ -72,6 +70,8 @@
7270
'django.template.context_processors.request',
7371
'django.contrib.auth.context_processors.auth',
7472
'django.contrib.messages.context_processors.messages',
73+
'social_django.context_processors.backends',
74+
'social_django.context_processors.login_redirect',
7575
],
7676
},
7777
},
@@ -132,15 +132,7 @@
132132
os.path.join(BASE_DIR, 'static')
133133
]
134134

135-
SOCIALACCOUNT_PROVIDERS = {
136-
'google': {
137-
'SCOPE': [
138-
'profile',
139-
'email',
140-
],
141-
'AUTH_PARAMS': {
142-
'access_type': 'online',
143-
},
144-
'OAUTH_PKCE_ENABLED': True,
145-
}
146-
}
135+
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id'
136+
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret'
137+
SOCIAL_AUTH_URL_NAMESPACE = 'social'
138+
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/polls/list/user/'

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ asgiref==3.3.1
22
Django==3.1.14
33
pytz==2020.5
44
sqlparse==0.4.4
5+
social-auth-app-django>=0.4.0

0 commit comments

Comments
 (0)