switch JWT framework

This commit is contained in:
Tyrel Souza 2019-09-25 23:43:16 -04:00
parent f62e1498fd
commit c583f4e9cc
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
3 changed files with 12 additions and 16 deletions

View File

@ -70,10 +70,10 @@ DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "logbook",
"USER": os.environ.get("DJANGO_DB_NAME", ""),
"USER": os.environ.get("DJANGO_DB_USER", ""),
"PASSWORD": os.environ.get("DJANGO_DB_PASS", ""),
"HOST": "127.0.0.1",
"PORT": "5433",
"PORT": os.environ.get("DJANGO_DB_PORT", "5432"),
}
}
@ -114,7 +114,6 @@ STATIC_URL = "/static/"
CORS_ORIGIN_ALLOW_ALL = False
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_WHITELIST = (
# TODO - set this properly for production
"http://127.0.0.1:8080",
"http://127.0.0.1:8000",
"http://127.0.0.1:8001",
@ -137,16 +136,9 @@ REST_FRAMEWORK = {
"rest_framework.renderers.TemplateHTMLRenderer",
),
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_jwt.authentication.JSONWebTokenAuthentication",
'rest_framework_simplejwt.authentication.JWTAuthentication',
"rest_framework.authentication.SessionAuthentication",
),
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
"PAGE_SIZE": 20,
}
JWT_AUTH = {
"JWT_ALLOW_REFRESH": True,
"JWT_EXPIRATION_DELTA": datetime.timedelta(hours=1),
"JWT_REFRESH_EXPIRATION_DELTA": datetime.timedelta(days=7),
}

View File

@ -1,11 +1,15 @@
from django.contrib import admin
from django.urls import path, include
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
urlpatterns = [
path("admin/", admin.site.urls),
path("api/v1/auth/obtain_token/", obtain_jwt_token),
path("api/v1/auth/refresh_token/", refresh_jwt_token),
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
# The rest of the endpoints
path("api/v1/", include("flight.api")),
]

View File

@ -1,7 +1,7 @@
Django==2.2.5
django-cors-headers==3.1.0
djangorestframework==3.10.3
djangorestframework-jwt==1.11.0
djangorestframework_simplejwt
psycopg2==2.8.3
PyJWT==1.7.1
pytz==2019.2