-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
[16.0][ADD] fastapi_auth_api_key #418
base: 16.0
Are you sure you want to change the base?
Conversation
Hi @lmignon, |
Getting an odoo environment | ||
=========================== | ||
|
||
If you need to get an odoo env based on the provided api key, you can use `authenticated_env_by_auth_api_key`. | ||
|
||
.. code-block:: python | ||
|
||
@router.get("/example_with_authenticated_env") | ||
def example_with_authenticated_env( | ||
env: Annotated[Environment, Depends(authenticated_env_by_auth_api_key)], | ||
) -> None: | ||
# env.user is the user attached to the provided key | ||
pass | ||
|
||
Getting the authenticated partner | ||
================================= | ||
|
||
If want to get the partned related to the the provided api key, you can use `authenticated_partner_by_api_key` | ||
|
||
.. code-block:: python | ||
|
||
@router.get("/example_with_authenticated_partner") | ||
def example_with_authenticated_partner( | ||
partner: Annotated[Partner, Depends(authenticated_partner_by_api_key)], | ||
) -> None: | ||
# partner is the partner related to the provided key key.user_id.partner_id | ||
pass | ||
|
||
Configuration | ||
============= | ||
|
||
For this to work, the api key must be defined on the `Endpoint`. | ||
A new field `auth_api_key_group_id` has been added to the `Endpoint` model. |
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.
@mmequignon Your endpoint should never rely on a specific authentication method. see https://github.com/OCA/rest-framework/blob/16.0/fastapi/readme/USAGE.rst#the-authentication-mechanism for more info on how to do it.
534a1fd
to
b891ce4
Compare
@mmequignon ping |
This module provide
FastApi
dependencies for Api Key authentication