所以我已经安装了 djanogo rest framework JWT 并设置了设置和认证类。根据本指南。我将省略设置,因为它们是正确的,这不是问题所在。也不要发布太多代码
https://jpadilla.github.io/django-rest-framework-jwt/
然后我从前端调用服务器上的授权视图
let token = "hardcoded token just to get the service working";
if(token != null){
this.authservice.authorizetoken(token)
.subscribe(
(req: any)=>{
console.log(req);
}
);
// grab the permissions a user has and who they are by token
authorizetoken(token){
return this.http.get(userauthorization, {
headers: new HttpHeaders().set('Authorization', 'JWT' + token )
});
}
然后在我的 django 中是查看代码:
class UserAuthorization(APIView):
authentication_classes = (JSONWebTokenAuthentication,)
def get(self, request, *args, **kwargs):
print(request.user)
return Response({})
但我不断收到匿名用户返回。它不应该是一个用户对象,因为我在标题中传递了一个令牌?
我不知道我做错了什么。