-
-
Notifications
You must be signed in to change notification settings - Fork 502
Fix client authentication for DeviceCodeGrant when getting a token #920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,27 @@ def validate_scopes(self, request): | |
| request.scopes, request.client, request): | ||
| raise errors.InvalidScopeError(request=request) | ||
|
|
||
| def validate_client_authentication(self, request): | ||
| """Raise on failed client authentication.""" | ||
| # Handles confidential clients | ||
| if self.request_validator.client_authentication_required(request): | ||
| # If the client type is confidential or the client was issued client | ||
| # credentials (or assigned other authentication requirements), the | ||
| # client MUST authenticate with the authorization server as described | ||
| # in Section 3.2.1. | ||
| # https://tools.ietf.org/html/rfc6749#section-3.2.1 | ||
| if not self.request_validator.authenticate_client(request): | ||
| log.debug('Client authentication failed, %r.', request) | ||
| raise errors.InvalidClientError(request=request) | ||
|
|
||
| # Handles public clients | ||
| elif not self.request_validator.authenticate_client_id(request.client_id, request): | ||
|
||
| # REQUIRED, if the client is not authenticating with the | ||
| # authorization server as described in Section 3.2.1. | ||
| # https://tools.ietf.org/html/rfc6749#section-3.2.1 | ||
| log.debug('Client authentication failed, %r.', request) | ||
| raise errors.InvalidClientError(request=request) | ||
|
|
||
| def prepare_authorization_response(self, request, token, headers, body, status): | ||
| """Place token according to response mode. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,14 +55,12 @@ def validate_token_request(self, request: common.Request) -> None: | |
| description=f"Duplicate {param} parameter.", request=request | ||
| ) | ||
|
|
||
| if not self.request_validator.authenticate_client(request): | ||
| raise rfc6749_errors.InvalidClientError(request=request) | ||
| elif not hasattr(request.client, "client_id"): | ||
| raise NotImplementedError( | ||
| "Authenticate client must set the " | ||
| "request.client.client_id attribute " | ||
| "in authenticate_client." | ||
| ) | ||
| self.validate_client_authentication(request) | ||
|
|
||
| if not hasattr(request.client, 'client_id'): | ||
| raise NotImplementedError('Authenticate client must set the ' | ||
| 'request.client.client_id attribute ' | ||
| 'in authenticate_client.') | ||
|
|
||
| # Ensure client is authorized use of this grant type | ||
| self.validate_grant_type(request) | ||
|
|
@@ -93,13 +91,7 @@ def create_token_response( | |
| """ | ||
| headers = self._get_default_headers() | ||
| try: | ||
| if self.request_validator.client_authentication_required( | ||
| request | ||
| ) and not self.request_validator.authenticate_client(request): | ||
| raise rfc6749_errors.InvalidClientError(request=request) | ||
|
Comment on lines
-96
to
-99
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This already happens inside |
||
|
|
||
| self.validate_token_request(request) | ||
|
|
||
| except rfc6749_errors.OAuth2Error as e: | ||
| headers.update(e.headers) | ||
| return headers, e.json, e.status_code | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Imports from the
rfc8628subpackage are not grouped alphabetically with the existing imports; consider organizing import order to match project style guidelines for readability.