json web token 认证模式
2019-04-28 本文已影响0人
爱修仙的道友
json web token实现登录
-
参考文档(很详细)
http://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html
https://www.jianshu.com/p/180a870a308a
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
),
}
from rest_framework_jwt.views import obtain_jwt_token
#...
urlpatterns = [
'',
# ...
url(r'^api-token-auth/', obtain_jwt_token),
]
-
postman获取 token
image.png -
断点测试
image.png
# settings
import datetime
JWT_AUTH = {
# 设置过期时间
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
# 设置请求头名
'JWT_AUTH_HEADER_PREFIX': 'JWT',
}