1

I have followed through the documentation on how to integrate both the REST framework and OAuth Toolkit, but when I run a request with a token I receive:

{"detail":"Authentication credentials were not provided."}

Here are my REST settings:

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

}

An example view:

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']

And I do have 'oauth2_provider' in my INSTALLED_APPS. I'm able to request and receive tokens without issue. It's only when I use them that I get the above error.

OpenDataAlex
  • 1,375
  • 5
  • 19
  • 39

0 Answers0