|
20 | 20 | IntrospectTokenView as DotIntrospectTokenView, |
21 | 21 | ) |
22 | 22 | from oauth2_provider.models import get_application_model |
| 23 | +from oauthlib.oauth2 import AccessDeniedError |
23 | 24 | from oauthlib.oauth2.rfc6749.errors import InvalidClientError, InvalidGrantError |
24 | 25 | from urllib.parse import urlparse, parse_qs |
25 | 26 | import html |
@@ -179,13 +180,19 @@ def form_valid(self, form): |
179 | 180 | refresh_token_delete_cnt = 0 |
180 | 181 |
|
181 | 182 | try: |
| 183 | + if not scopes: |
| 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=AccessDeniedError(state=credentials.get("state", None)), redirect_uri=credentials["redirect_uri"] |
| 188 | + ) |
182 | 189 | uri, headers, body, status = self.create_authorization_response( |
183 | 190 | request=self.request, scopes=scopes, credentials=credentials, allow=allow |
184 | 191 | ) |
185 | 192 | except OAuthToolkitError as error: |
186 | 193 | response = self.error_response(error, application) |
187 | 194 |
|
188 | | - if allow is False: |
| 195 | + if allow is False or not scopes: |
189 | 196 | (data_access_grant_delete_cnt, |
190 | 197 | access_token_delete_cnt, |
191 | 198 | refresh_token_delete_cnt) = remove_application_user_pair_tokens_data_access(application, self.request.user) |
|
0 commit comments