Skip to content

Commit

Permalink
chore(deps): switch to djangorestframework-simplejwt
Browse files Browse the repository at this point in the history
Drop djangorestframework-jwt in favour of -simplejwt as it's no longer maintained.
See: jpadilla/django-rest-framework-jwt#484
  • Loading branch information
Stefan Borer committed Feb 7, 2020
1 parent 413fa08 commit 1fa7e96
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ django-auth-ldap==2.1.0
django-filter==2.2.0
django-multiselectfield==0.1.11
djangorestframework==3.11.0
djangorestframework-jwt==1.11.0
djangorestframework-simplejwt==4.4.0
djangorestframework-jsonapi==3.0.0
psycopg2-binary==2.8.4
pytz==2019.3
Expand Down
13 changes: 6 additions & 7 deletions timed/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):
"DEFAULT_PARSER_CLASSES": ("rest_framework_json_api.parsers.JSONParser",),
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_jwt.authentication.JSONWebTokenAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
"DEFAULT_METADATA_CLASS": "rest_framework_json_api.metadata.JSONAPIMetadata",
"EXCEPTION_HANDLER": "rest_framework_json_api.exceptions.exception_handler",
Expand Down Expand Up @@ -187,11 +186,11 @@ def default(default_dev=env.NOTSET, default_prod=env.NOTSET):

AUTH_USER_MODEL = "employment.User"

JWT_AUTH = {
"JWT_EXPIRATION_DELTA": datetime.timedelta(days=2),
"JWT_ALLOW_REFRESH": True,
"JWT_REFRESH_EXPIRATION_DELTA": datetime.timedelta(days=7),
"JWT_AUTH_HEADER_PREFIX": "Bearer",
SIMPLE_AUTH = {
"ACCESS_TOKEN_LIFETIME": datetime.timedelta(days=2),
"REFRESH_TOKEN_LIFETIME": datetime.timedelta(days=7),
# TODO check if this is ROTATE_REFRESH_TOKENS
# "JWT_ALLOW_REFRESH": True,
}

AUTH_PASSWORD_VALIDATORS = [
Expand Down
15 changes: 5 additions & 10 deletions timed/tests/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.urls import reverse
from rest_framework import exceptions, status
from rest_framework.test import APIClient
from rest_framework_jwt.settings import api_settings


class JSONAPIClient(APIClient):
Expand Down Expand Up @@ -40,7 +39,7 @@ def post(self, path, data=None, **kwargs):
path=path,
data=self._parse_data(data),
content_type=self._content_type,
**kwargs
**kwargs,
)

def delete(self, path, data=None, **kwargs):
Expand All @@ -53,7 +52,7 @@ def delete(self, path, data=None, **kwargs):
path=path,
data=self._parse_data(data),
content_type=self._content_type,
**kwargs
**kwargs,
)

def patch(self, path, data=None, **kwargs):
Expand All @@ -66,7 +65,7 @@ def patch(self, path, data=None, **kwargs):
path=path,
data=self._parse_data(data),
content_type=self._content_type,
**kwargs
**kwargs,
)

def login(self, username, password):
Expand All @@ -79,7 +78,7 @@ def login(self, username, password):
data = {
"data": {
"attributes": {"username": username, "password": password},
"type": "obtain-json-web-tokens",
"type": "token-obtain-pair-views",
}
}

Expand All @@ -88,8 +87,4 @@ def login(self, username, password):
if response.status_code != status.HTTP_200_OK:
raise exceptions.AuthenticationFailed()

self.credentials(
HTTP_AUTHORIZATION="{0} {1}".format(
api_settings.JWT_AUTH_HEADER_PREFIX, response.data["token"]
)
)
self.credentials(HTTP_AUTHORIZATION=f"Bearer {response.data['access']}")
6 changes: 3 additions & 3 deletions timed/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from django.conf.urls import include, url
from django.contrib import admin
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token
from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView

urlpatterns = [
url(r"^admin/", admin.site.urls),
url(r"^api/v1/auth/login", obtain_jwt_token, name="login"),
url(r"^api/v1/auth/refresh", refresh_jwt_token, name="refresh"),
url(r"^api/v1/auth/login", TokenObtainPairView.as_view(), name="login"),
url(r"^api/v1/auth/refresh", TokenRefreshView.as_view(), name="refresh"),
url(r"^api/v1/", include("timed.employment.urls")),
url(r"^api/v1/", include("timed.projects.urls")),
url(r"^api/v1/", include("timed.tracking.urls")),
Expand Down

0 comments on commit 1fa7e96

Please sign in to comment.