jwt认证生成后的token后端解析
一.首先前端发送token
token所在的位置headers
{'authorization':token的值',Content-Type':application/json}
在ajax写
//只展示headers部分代码
headers:{"authorization":this.$cookies.get("token")}
//token值一般是放在cookies里面
//ajax提交默认就是json格式所有不需要声明js格式
二.后端接受并解析token
1.首先先定义个认证类
from rest_framework.exceptions import AuthenticationFailed
import jwt
from rest_framework_jwt.authentication import BaseJSONWebTokenAuthentication
from rest_framework_jwt.authentication import jwt_decode_handler
from rest_framework_jwt.authentication import get_authorization_header
class JWTAuthentication(BaseJSONWebTokenAuthentication):
# 自定义认证类,重写authenticate方法
def authenticate(self, request):
# 认证通过,返回user,auth
# 认证失败,返回None
# auth = reque