Skip to content

Commit 790ecaa

Browse files
committed
Added OAuth configuration to API
1 parent e5116ba commit 790ecaa

File tree

6 files changed

+430
-3
lines changed

6 files changed

+430
-3
lines changed

api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ coverage.xml
3737
.env
3838
.env.*
3939
*.env
40+
/src/myapi/.env
4041

4142
# Files generated by editors
4243
*.swp

api/poetry.lock

Lines changed: 381 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ requires-python = ">=3.11"
1010
dependencies = [
1111
"django (>=5.2.3,<6.0.0)",
1212
"djangorestframework (>=3.16.0,<4.0.0)",
13-
"django-cors-headers (>=4.7.0,<5.0.0)"
13+
"django-cors-headers (>=4.7.0,<5.0.0)",
14+
"django-allauth (>=65.10.0,<66.0.0)",
15+
"python-dotenv (>=1.1.1,<2.0.0)",
16+
"requests (>=2.32.4,<3.0.0)",
17+
"jwt (>=1.4.0,<2.0.0)"
1418
]
1519

1620
[tool.poetry]

api/src/api/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# src/api/urls.py
2-
from django.urls import path
2+
from django.urls import path, include
33
from . import views
44

55
urlpatterns = [
@@ -8,4 +8,5 @@
88
path('update/<int:task_number>/', views.task_status_update,
99
name='task_status_update'),
1010
path('delete/<int:task_number>/', views.delete_task, name='delete_task'),
11+
path('accounts/', include('allauth.urls')),
1112
]

api/src/myapi/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
/.env

api/src/myapi/settings.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"""
1212

1313
from pathlib import Path
14+
from dotenv import load_dotenv
15+
import os
16+
load_dotenv('./env')
1417

1518
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1619
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -33,13 +36,18 @@
3336
INSTALLED_APPS = [
3437
'django.contrib.admin',
3538
'django.contrib.auth',
39+
'django.contrib.sites',
3640
'django.contrib.contenttypes',
3741
'django.contrib.sessions',
3842
'django.contrib.messages',
3943
'django.contrib.staticfiles',
4044
'rest_framework',
4145
'api.apps.ApiConfig',
4246
'corsheaders',
47+
'allauth',
48+
'allauth.account',
49+
'allauth.socialaccount',
50+
'allauth.socialaccount.providers.google',
4351
]
4452

4553
MIDDLEWARE = [
@@ -48,6 +56,7 @@
4856
'django.contrib.sessions.middleware.SessionMiddleware',
4957
'django.middleware.common.CommonMiddleware',
5058
'django.middleware.csrf.CsrfViewMiddleware',
59+
'allauth.account.middleware.AccountMiddleware',
5160
'django.contrib.auth.middleware.AuthenticationMiddleware',
5261
'django.contrib.messages.middleware.MessageMiddleware',
5362
'django.middleware.clickjacking.XFrameOptionsMiddleware',
@@ -130,3 +139,33 @@
130139
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
131140

132141
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
142+
143+
144+
# OAuth settings
145+
146+
SITE_ID = 1
147+
148+
AUTHENTICATION_BACKENDS = [
149+
'django.contrib.auth.backends.ModelBackend',
150+
'allauth.account.auth_backends.AuthenticationBackend',
151+
]
152+
153+
LOGIN_REDIRECT_URL = '/'
154+
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
155+
156+
ACCOUNT_EMAIL_VERIFICATION = "none"
157+
ACCOUNT_LOGIN_METHODS = {'username', 'email'}
158+
ACCOUNT_SIGNUP_FIELDS = ['email*', 'username*', 'password1*', 'password2*']
159+
160+
161+
SOCIALACCOUNT_PROVIDERS = {
162+
"google": {
163+
"SCOPE": [
164+
"profile",
165+
"email",
166+
],
167+
"AUTH_PARAMS": {
168+
"access_type": "online",
169+
}
170+
}
171+
}

0 commit comments

Comments
 (0)