Skip to content

Commit 0b1c42f

Browse files
committed
Tweaked error handling
1 parent 48794d3 commit 0b1c42f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

apps/dot_ext/views/authorization.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ def form_valid(self, form):
181181

182182
try:
183183
if not scopes:
184-
raise oauth2.AccessDeniedError(state=credentials.get("state", None))
184+
# Since the create_authorization_response will re-inject scopes even when none are
185+
# valid, we want to pre-emptively treat this as an error case
186+
raise OAuthToolkitError(
187+
error=oauth2.AccessDeniedError(state=credentials.get("state", None)), redirect_uri=credentials["redirect_uri"]
188+
)
185189
uri, headers, body, status = self.create_authorization_response(
186190
request=self.request, scopes=scopes, credentials=credentials, allow=allow
187191
)
188-
except (oauth2.AccessDeniedError, OAuthToolkitError) as error:
192+
except OAuthToolkitError as error:
189193
response = self.error_response(error, application)
190194

191195
if allow is False or not scopes:

0 commit comments

Comments
 (0)