|
28 | 28 |
|
29 | 29 | """ |
30 | 30 | from oauth2.error import OAuthInvalidError, UserNotAuthenticated, \ |
31 | | - AccessTokenNotFound, UserIdentifierMissingError, RedirectUriUnknown |
| 31 | + AccessTokenNotFound, UserIdentifierMissingError, RedirectUriUnknown, \ |
| 32 | + AuthCodeNotFound |
32 | 33 | from oauth2.compatibility import urlencode, quote |
33 | 34 | import json |
34 | 35 | import time |
@@ -527,25 +528,27 @@ def _read_params(self, request): |
527 | 528 | explanation="Invalid redirect_uri parameter") |
528 | 529 |
|
529 | 530 | def _validate_code(self): |
530 | | - stored_code = self.auth_code_store.fetch_by_code(self.code) |
531 | | - |
532 | | - if stored_code is None: |
533 | | - raise OAuthInvalidError(error="invalid_request", |
534 | | - explanation="Invalid authorization code " \ |
535 | | - "parameter") |
| 531 | + try: |
| 532 | + stored_code = self.auth_code_store.fetch_by_code(self.code) |
| 533 | + except AuthCodeNotFound: |
| 534 | + raise OAuthInvalidError( |
| 535 | + error="invalid_request", |
| 536 | + explanation="Invalid authorization code parameter") |
536 | 537 |
|
537 | 538 | if stored_code.code != self.code: |
538 | | - raise OAuthInvalidError(error="invalid_grant", |
539 | | - explanation="Invalid code parameter in " \ |
540 | | - "request") |
| 539 | + raise OAuthInvalidError( |
| 540 | + error="invalid_grant", |
| 541 | + explanation="Invalid code parameter in request") |
541 | 542 |
|
542 | 543 | if stored_code.redirect_uri != self.redirect_uri: |
543 | | - raise OAuthInvalidError(error="invalid_request", |
544 | | - explanation="Invalid redirect_uri parameter") |
| 544 | + raise OAuthInvalidError( |
| 545 | + error="invalid_request", |
| 546 | + explanation="Invalid redirect_uri parameter") |
545 | 547 |
|
546 | 548 | if stored_code.is_expired(): |
547 | | - raise OAuthInvalidError(error="invalid_grant", |
548 | | - explanation="Authorization code has expired") |
| 549 | + raise OAuthInvalidError( |
| 550 | + error="invalid_grant", |
| 551 | + explanation="Authorization code has expired") |
549 | 552 |
|
550 | 553 | self.data = stored_code.data |
551 | 554 | self.scopes = stored_code.scopes |
|
0 commit comments