如何应用jwt django rest token来访问其他Apis

时间:2018-06-18 17:52:34

标签: python django django-rest-framework jwt access-token

我正在使用此网址生成jwt令牌

http://127.0.0.1:8000/api/token/

HTTP 200 OK
Allow: POST, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTUyOTQyOTUwMSwianRpIjoiZmYxOTFmN2JhN2NhNDY2MWI0OTUzZGU2NmVlNjg3ODEiLCJ1c2VyX2lkIjoyfQ.SssEuSxKj09vshLq74h5NPMZFg8V-0oee9ZqLHzINV4",
    "access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNTI5MzQzNDAxLCJqdGkiOiJlNDNlZTE2MTlmOTM0ZjQxOWM4NWRiZGYxMzZkMzk2ZiIsInVzZXJfaWQiOjJ9.l9CPDVg371uIvXAVlLdV_uhzYYn9ejzEpCZLFKo1fU4"
}

我有一个列出用户的API(http://127.0.0.1:8000/api/userdetails/) 代码如下所示

class UserDetailsAPIView(APIView):

    serializer_class = UserLoginSerializer
    def get(self, request, format=None):   

        @permission_classes((IsAuthenticated, ))
        usernames = [user.username for user in User.objects.all()]
        return Response(usernames)

当我访问API(http://127.0.0.1:8000/api/userdetails/)时,它正在显示错误 "详细信息":"未提供身份验证凭据。" 那么我将如何通过提供生成的jwt令牌来访问API(http://127.0.0.1:8000/api/userdetails/)?

0 个答案:

没有答案