Skip to content

Commit

Permalink
Added JWT token auth
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDyakonov committed Jun 16, 2024
1 parent 90d03aa commit e338e8a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
12 changes: 12 additions & 0 deletions backend/apps/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.urls import path
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
TokenVerifyView,
)

urlpatterns = [
path("token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("token/verify/", TokenVerifyView.as_view(), name="token_verify"),
]
5 changes: 3 additions & 2 deletions backend/apps/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import include, path
from django.contrib.auth import views as auth_views
from apps.mailer.views import mailing_admin
from django.contrib.auth import views as auth_views
from django.urls import include, path

urlpatterns = [
path("", include("apps.core.urls")),
Expand All @@ -11,4 +11,5 @@
path("mailer/", include("apps.mailer.urls")),
path("api/mailing-admin/", mailing_admin, name="mailing-admin"),
path("api/mailing-admin/logout/", auth_views.LogoutView.as_view(), name="logout"),
path("users/", include("apps.accounts.urls")),
]
22 changes: 15 additions & 7 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"rest_framework_swagger",
"drf_yasg",
"whitenoise.runserver_nostatic",
"rest_framework_simplejwt.token_blacklist",
# Celery
"django_celery_results",
# Custom
Expand Down Expand Up @@ -181,16 +182,23 @@
REST_FRAMEWORK = {
# "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
# "PAGE_SIZE": 10,
# "DEFAULT_AUTHENTICATION_CLASSES": (
# "rest_framework_simplejwt.authentication.JWTAuthentication",
# ),
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
# 'COERCE_DECIMAL_TO_STRING': False,
}

# SIMPLE_JWT = {
# "TOKEN_OBTAIN_SERIALIZER": "apps.users.serializers.CustomTokenObtainPairSerializer",
# "ACCESS_TOKEN_LIFETIME": timedelta(days=7),
# }
SIMPLE_JWT = {
# "TOKEN_OBTAIN_SERIALIZER": "apps.users.serializers.CustomTokenObtainPairSerializer",
"ACCESS_TOKEN_LIFETIME": timedelta(days=7),
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
"AUTH_HEADER_TYPES": ("Bearer",),
"USER_ID_FIELD": "id",
"USER_ID_CLAIM": "user_id",
# "SIGNING_KEY": os.getenv("DJANGO_SIGNING_KEY"),
"ROTATE_REFRESH_TOKENS": True,
"BLACKLIST_AFTER_ROTATION": True,
}

# CELERY
CELERY_BROKER_URL = "redis://" + os.getenv("REDIS_HOST") + ":" + os.getenv("REDIS_PORT")
Expand Down
7 changes: 5 additions & 2 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
amqp==5.2.0
asgiref==3.8.1
async-timeout==4.0.3
beautifulsoup4==4.12.3
billiard==4.2.0
boto3==1.34.126
botocore==1.34.126
Expand All @@ -22,9 +23,11 @@ django-celery-results==2.5.1
django-cors-headers==4.3.1
django-jazzmin==3.0.0
django-rest-swagger==2.2.0
django-selectel-storage==1.0.2
django-storages==1.14.3
djangorestframework==3.15.1
djangorestframework-gis==1.0
djangorestframework-simplejwt==5.3.1
drf-yasg==1.21.7
icalendar==5.0.12
idna==3.7
Expand All @@ -41,6 +44,7 @@ packaging==24.1
pillow==10.3.0
prompt_toolkit==3.0.46
psycopg2-binary==2.9.9
PyJWT==2.8.0
pypng==0.20220715.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
Expand All @@ -54,6 +58,7 @@ requests==2.32.3
s3transfer==0.10.1
simplejson==3.19.2
six==1.16.0
soupsieve==2.5
sqlparse==0.5.0
typing_extensions==4.12.2
tzdata==2024.1
Expand All @@ -65,5 +70,3 @@ whitenoise==6.6.0
wrapt==1.16.0
x-wr-timezone==0.0.7
yookassa==3.1.0

beautifulsoup4~=4.12.3

0 comments on commit e338e8a

Please sign in to comment.