Skip to content
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

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from

Conversation

mmequignon
Copy link
Member

This module provide FastApi dependencies for Api Key authentication

@OCA-git-bot
Copy link
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

Comment on lines +1 to +33
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.
Copy link
Sponsor Contributor

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.

@mmequignon mmequignon force-pushed the 16.0-add-fastapi_auth_api_key branch from 534a1fd to b891ce4 Compare March 1, 2024 11:31
@simahawk
Copy link
Contributor

simahawk commented Apr 8, 2024

@mmequignon ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants