json web token 认证模式

2019-04-28  本文已影响0人  爱修仙的道友

json web token实现登录

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),
]
image.png
# settings
import datetime
JWT_AUTH = {
    # 设置过期时间
    'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
    # 设置请求头名
    'JWT_AUTH_HEADER_PREFIX': 'JWT',
}
上一篇下一篇

猜你喜欢

热点阅读