Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Return 401 for API request with Invalid Authorization #3663

Closed
8 changes: 4 additions & 4 deletions api/api/views/oauth2_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.views import APIView
from rest_framework.exceptions import AuthenticationFailed

from drf_spectacular.utils import extend_schema
from oauth2_provider.generators import generate_client_secret
Expand Down Expand Up @@ -173,15 +174,14 @@ def get(self, request, format=None):
> token has expired.
"""

# TODO: Replace 403 responses with DRF `authentication_classes`.
if not request.auth:
return Response(status=403, data="Forbidden")
if "Authorization" in request.headers and not request.auth:
raise AuthenticationFailed(detail="Invalid credentials")

access_token = str(request.auth)
client_id, rate_limit_model, verified = get_token_info(access_token)

if not client_id:
return Response(status=403, data="Forbidden")
raise AuthenticationFailed(detail="Invalid credentials")

throttle_type = rate_limit_model
throttle_key = "throttle_{scope}_{client_id}"
Expand Down
Loading