集成Django REST框架和Django OAuth工具包身份验证
我已经阅读了有关如何集成REST框架和OAuth工具包的文档,但是当我使用令牌运行请求时,我收到:集成Django REST框架和Django OAuth工具包身份验证,django,django-rest-framework,django-oauth-toolkit,Django,Django Rest Framework,Django Oauth Toolkit,我已经阅读了有关如何集成REST框架和OAuth工具包的文档,但是当我使用令牌运行请求时,我收到: {"detail":"Authentication credentials were not provided."} 以下是我的休息设置: REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'oauth2_provider.contrib.rest_framework.OAuth2Authen
{"detail":"Authentication credentials were not provided."}
以下是我的休息设置:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
'PAGE_SIZE': 20
}
示例视图:
from django.contrib.auth.models import Group
from rest_framework import permissions, viewsets
from oauth2_provider.contrib.rest_framework import TokenHasScope, OAuth2Authentication
from data_commons_security.security.models import Permission, Profile, Role, User
from data_commons_security.security.serializers import (
GroupSerializer,
)
class GroupViewSet(viewsets.ReadOnlyModelViewSet):
authentication_classes = [OAuth2Authentication]
queryset = Group.objects.all()
serializer_class = GroupSerializer
permission_classes = [TokenHasScope]
required_scopes = ['read', 'groups']
我在安装的应用程序中有“oauth2_provider”。我可以毫无疑问地请求和接收代币。只有当我使用它们时,我才会出现上述错误。TokenHasScope从何而来?在代码中添加您的导入行。添加-对此表示歉意!
TokenHasScope
来自哪里?在代码中添加您的导入行。添加-对此表示歉意!