Skip to content

Commit b16f5ac

Browse files
committed
less redundant
1 parent 6edc849 commit b16f5ac

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

apps/dot_ext/views/authorization.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
IntrospectTokenView as DotIntrospectTokenView,
2121
)
2222
from oauth2_provider.models import get_application_model
23-
from oauthlib.oauth2 import AccessDeniedError
23+
from oauthlib import oauth2
2424
from oauthlib.oauth2.rfc6749.errors import InvalidClientError, InvalidGrantError
2525
from urllib.parse import urlparse, parse_qs
2626
import html
@@ -179,33 +179,20 @@ def form_valid(self, form):
179179
access_token_delete_cnt = 0
180180
refresh_token_delete_cnt = 0
181181

182-
if allow is False:
183-
(data_access_grant_delete_cnt,
184-
access_token_delete_cnt,
185-
refresh_token_delete_cnt) = remove_application_user_pair_tokens_data_access(application, self.request.user)
186-
187-
if not scopes:
188-
beneficiary_authorized_application.send(
189-
sender=self,
190-
request=self.request,
191-
auth_status="FAIL",
192-
auth_status_code=302,
193-
user=self.request.user,
194-
application=application,
195-
share_demographic_scopes=share_demographic_scopes,
196-
scopes=scopes,
197-
allow=allow,
198-
access_token_delete_cnt=access_token_delete_cnt,
199-
refresh_token_delete_cnt=refresh_token_delete_cnt,
200-
data_access_grant_delete_cnt=data_access_grant_delete_cnt)
201-
raise AccessDeniedError(state=credentials.get("state", None))
202182
try:
203183
uri, headers, body, status = self.create_authorization_response(
204184
request=self.request, scopes=scopes, credentials=credentials, allow=allow
205185
)
186+
if not scopes:
187+
raise oauth2.AccessDeniedError(state=credentials.get("state", None))
206188
except OAuthToolkitError as error:
207189
response = self.error_response(error, application)
208190

191+
if allow is False:
192+
(data_access_grant_delete_cnt,
193+
access_token_delete_cnt,
194+
refresh_token_delete_cnt) = remove_application_user_pair_tokens_data_access(application, self.request.user)
195+
209196
beneficiary_authorized_application.send(
210197
sender=self,
211198
request=self.request,

0 commit comments

Comments
 (0)