我正在使用 Djoser Python 包为我的应用程序创建身份验证。
如文档中所述,我已更新settings.py
如下所示 -
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
}
我也添加permission_class
了APIView
permission_classes = [IsAuthenticated]
我能够使用凭据获取refresh
and令牌 -access
{
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTU4NjI1MDYyOCwianRpIjoiZmU5MjA0NzE2NWIwNGNjYmE5YzgzMWYwMDY5Njk4NzQiLCJ1c2VyX2lkIjoxfQ.I-IPEVrMchQWfGKv80x8pcIMHkEoMlUci7eRZGKjzOA",
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNTg2MTY0NTI4LCJqdGkiOiI4NGVlMmQ1OWUzYTI0MWU5OGJhNmQyMDBlNTc5NjQ5YSIsInVzZXJfaWQiOjF9.4InHnERd9u7nt8-iaNjt08Fd9169-VVAIYgBGa08euE"
}
但是当我尝试使用access
邮递员的相同令牌发送 POST 请求时,我收到了这个错误 -
{
"detail": "Authentication credentials were not provided."
}
这是邮递员请求的屏幕截图 -