Nicolas Deforge
Nicolas Deforge

Reputation: 1

Throttle in Django Rest Framweork if user is None during Oauth2 request with CLient Credentials

I am using Django Rest Framework with Django OAuth Toolkit for allowing external organization to request endpoints.

I am using Crendentials Client grant type to ask access token.enter image description here

When i try request my endpoint I have this error : 'NoneType' object has no attribute 'is_authenticated'. The exception is raised in the get_cached_key function of the AnonThrottleClass.

In fact request.user is None with Client Credentials, so this function can not pass.

Here is my viewset :

class StudentViewSet(
mixins.CreateModelMixin,
mixins.UpdateModelMixin,
mixins.RetrieveModelMixin,
mixins.ListModelMixin,
mixins.DestroyModelMixin,
viewsets.GenericViewSet,):

serializer_class = StudentSerializer
authentication_classes = (OAuth2Authentication,)
permission_classes = (TokenHasScope,)
required_scopes = [
    oauth2_settings.READ_SCOPE,
    oauth2_settings.WRITE_SCOPE,
]
schema = is_schema_for_open_api_doc(True)
queryset = Student.objects.all()

Can you help me with this ?

Thank you !

Upvotes: 0

Views: 275

Answers (0)

Related Questions