[英]how to get the user details using jwt authentication in django rest framework?
I am trying to get the user details using JWT token authentication.我正在尝试使用 JWT 令牌身份验证获取用户详细信息。 I am able to get them using BasicAuthentication and JsonWebToken authentication.
我可以使用 BasicAuthentication 和 JsonWebToken 身份验证来获取它们。 I am trying to get the details using JWT .
我正在尝试使用 JWT 获取详细信息。
class PermissionView(APIView):
permission_classes = [IsAuthenticated]
authentication_classes = [BasicAuthentication,JSONWebTokenAuthentication]
def get(self, request,format=None):
data = {
'username': request.user.username,
'password':request.user.password,
}
return Response(data)
urls:网址:
url(r'^api-token/$', obtain_jwt_token),
output: 1) generating the token输出:1)生成令牌
2) getting the user details using Basic Authentication and JsonWebTokenauthentication] 2) 使用 Basic Authentication 和 JsonWebTokenauthentication 获取用户详细信息]
I am trying to get the user details or authenticate the user details using JWT token.我正在尝试使用 JWT 令牌获取用户详细信息或验证用户详细信息。 Help would be appreciated?
帮助将不胜感激?
Let us revisit JWT in Django flow to understand something:让我们重新审视 Django 流程中的 JWT 以了解一些东西:
Conclusion: you will find the user who is currently requesting your API in the request object as request.user
.结论:您将在
request.user
对象中找到当前正在请求您的 API 的用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.