[17.0][MIG] add fastapi_auth_api_key#539
Closed
henrybackman wants to merge 3 commits into
Closed
Conversation
petrus-v
reviewed
Jul 28, 2025
|
|
||
|
|
||
| def authenticated_auth_api_key( | ||
| key: Annotated[str, Depends(APIKeyHeader(name="HTTP-API-KEY"))], |
Contributor
There was a problem hiding this comment.
is it a real desired changed ? to avoid breaking consumer I would recomand to use same header as on previous version ie; https://github.com/OCA/rest-framework/blob/16.0/base_rest_auth_api_key/apispec/rest_method_security_plugin.py#L17
Suggested change
| key: Annotated[str, Depends(APIKeyHeader(name="HTTP-API-KEY"))], | |
| key: Annotated[str, Depends(APIKeyHeader(name="API-KEY"))], |
| headers={"WWW-Authenticate": "HTTP-API-KEY"}, | ||
| ) from error | ||
| # Ensure the api key is authorized for the current endpoint. | ||
| if auth_api_key not in endpoint.sudo().auth_api_key_group_id.auth_api_key_ids: |
Contributor
There was a problem hiding this comment.
As far I understand we must set an auth_api_key_group_id to make the endpoint working, is that correct?
if yes I would set the field as required or support the case there is no auth_api_key_group_id defined:
Suggested change
| if auth_api_key not in endpoint.sudo().auth_api_key_group_id.auth_api_key_ids: | |
| if endpoint.sudo().auth_api_key_group_id and auth_api_key not in endpoint.sudo().auth_api_key_group_id.auth_api_key_ids: |
Comment on lines
+81
to
+85
| # TODO enable this when we know how to filter keys based | ||
| # on endpoint's api key group. | ||
| # An exception is raised when unauthorized api key record is found | ||
| # with self.assertRaises(HTTPException) as error: | ||
| # authenticated_auth_api_key("not_authorized", self.demo_env) |
Contributor
There was a problem hiding this comment.
I'm not sure to understand the comment, maybe it's time on uncomment ?
Suggested change
| # TODO enable this when we know how to filter keys based | |
| # on endpoint's api key group. | |
| # An exception is raised when unauthorized api key record is found | |
| # with self.assertRaises(HTTPException) as error: | |
| # authenticated_auth_api_key("not_authorized", self.demo_env) | |
| with self.assertRaises(HTTPException) as error: | |
| authenticated_auth_api_key("not_authorized", self.demo_env, self.demo_endpoint) |
Contributor
|
I suppose this PR can be closed as superseded by #555 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supercedes: