DRF에서 JWT사용하기
Json Web Token
최근에는 django-rest-framework-jwt 라이브러리를 많이 사용하지 않는다고 한다.
또한 DRF 공식문서에 따르면 djangorestframework-simplejwt 라이브러리 사용을 권장하고 있다.
djangorestframework-jwt 라이브러리는 더이상 업데이트 되지 않는다고 함
- 결론
- djangorestframework-simplejwt 라이브러리 사용해라
- djangorestframework-jwt 는 업데이트 중단됨
# 설치
pip install djangorestframework-simplejwt
# django settings.py
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': (
...
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
...
}
# urls.py
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
urlpatterns = [
...
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
...
]
# accounts/urls.py
urlpatterns = [
...
path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
...
]
Postman을 이용해서 잘돌아가는지 확인하면 좋음.
추후 글 보완해서 다시 작성예정.
[참고블로그]
- 공식 도큐먼트
django-rest-framework-simplejwt.readthedocs.io/en/latest/getting_started.html
Getting started — Simple JWT 4.4.0 documentation
© Copyright 2020, David Sanders Revision 3f3228bc.
django-rest-framework-simplejwt.readthedocs.io
hackernoon.com/110percent-complete-jwt-authentication-with-django-and-react-2020-iejq34ta
110% Complete JWT Authentication with Django & React - 2020 | Hacker Noon
ReactJS is a fantastic frontend framework, and Django is a fantastic backend framework. However, as usual when dealing with anything of more than trivial complexity, it isn’t easy to get the two to place nicely together. It's not like taping a banana to
hackernoon.com
'Python > DRF' 카테고리의 다른 글
[DRF] ModelSerializer 사용법 (feat. method-hyperlink) (0) | 2021.01.20 |
---|---|
[DRF] CBV - APIView, Mixins, generics APIView, ViewSet (0) | 2021.01.05 |
[DRF] Json 기초 (0) | 2021.01.05 |
댓글