Skip to content

Commit d573afc

Browse files
committed
Ensure device token errors are returning 400
1 parent fa02f87 commit d573afc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

oauth2_provider/views/base.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django import http
77
from django.contrib.auth.mixins import LoginRequiredMixin
88
from django.contrib.auth.views import redirect_to_login
9-
from django.http import HttpResponse
9+
from django.http import HttpResponse, JsonResponse
1010
from django.shortcuts import resolve_url
1111
from django.utils import timezone
1212
from django.utils.decorators import method_decorator
@@ -323,10 +323,20 @@ def device_flow_token_response(
323323
device = Device.objects.get(device_code=device_code)
324324

325325
if device.status == device.AUTHORIZATION_PENDING:
326-
raise AuthorizationPendingError
326+
pending_error = AuthorizationPendingError()
327+
return http.HttpResponse(
328+
content=pending_error.json,
329+
status=pending_error.status_code,
330+
content_type="application/json"
331+
)
327332

328333
if device.status == device.DENIED:
329-
raise AccessDenied
334+
access_denied_error = AccessDenied()
335+
return http.HttpResponse(
336+
content=access_denied_error.json,
337+
status=access_denied_error.status_code,
338+
content_type="application/json"
339+
)
330340

331341
url, headers, body, status = self.create_token_response(request)
332342

0 commit comments

Comments
 (0)