feat(backend): added jwt auth support

This commit is contained in:
Rushil Umaretiya 2022-04-16 21:12:58 -04:00
parent acba7b111d
commit 7cad429a2c
4 changed files with 35 additions and 1 deletions

View File

@ -9,6 +9,7 @@ gunicorn = "*"
python-dotenv = "*" python-dotenv = "*"
djangorestframework = "*" djangorestframework = "*"
django-cors-headers = "*" django-cors-headers = "*"
djangorestframework-simplejwt = "*"
[dev-packages] [dev-packages]

18
server/Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "6b09e5def16da359280b38cfa9690ef7fb07897b5befd3c0f5b16de35d664690" "sha256": "d2db7358afc491233105dbd0ca11ab1f16efa6e70de3e44270a99ce7acde40b6"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -48,6 +48,14 @@
"index": "pypi", "index": "pypi",
"version": "==3.13.1" "version": "==3.13.1"
}, },
"djangorestframework-simplejwt": {
"hashes": [
"sha256:75323528a7b910843b879194746f0ebc3481c4ad9f354de2dd162160662fb95a",
"sha256:cd3ee3aabdc98de104957c136e74ba2a16571b151c88ecd97421fce171a03ea4"
],
"index": "pypi",
"version": "==5.1.0"
},
"gunicorn": { "gunicorn": {
"hashes": [ "hashes": [
"sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e", "sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e",
@ -56,6 +64,14 @@
"index": "pypi", "index": "pypi",
"version": "==20.1.0" "version": "==20.1.0"
}, },
"pyjwt": {
"hashes": [
"sha256:b888b4d56f06f6dcd777210c334e69c737be74755d3e5e9ee3fe67dc18a0ee41",
"sha256:e0c4bb8d9f0af0c7f5b1ec4c5036309617d03d56932877f2f7a0beeb5318322f"
],
"markers": "python_version >= '3.6'",
"version": "==2.3.0"
},
"python-dotenv": { "python-dotenv": {
"hashes": [ "hashes": [
"sha256:b7e3b04a59693c42c36f9ab1cc2acc46fa5df8c78e178fc33a8d4cd05c8d498f", "sha256:b7e3b04a59693c42c36f9ab1cc2acc46fa5df8c78e178fc33a8d4cd05c8d498f",

View File

@ -1,10 +1,17 @@
from django.urls import path from django.urls import path
from . import views from . import views
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
urlpatterns = [ urlpatterns = [
path('profile/create', views.ConsumerCreate.as_view()), path('profile/create', views.ConsumerCreate.as_view()),
path('profile/', views.ConsumerDetail.as_view()), path('profile/', views.ConsumerDetail.as_view()),
path('foundation/', views.FoundationViewSet.as_view({'get': 'list', 'post': 'create'})), path('foundation/', views.FoundationViewSet.as_view({'get': 'list', 'post': 'create'})),
path('foundation/<int:pk>/', views.FoundationViewSet.as_view({'get': 'retrieve', 'put': 'update', 'delete': 'destroy'})), path('foundation/<int:pk>/', views.FoundationViewSet.as_view({'get': 'retrieve', 'put': 'update', 'delete': 'destroy'})),
path('token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
] ]

View File

@ -106,6 +106,16 @@ else:
} }
} }
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
# Password validation # Password validation