OdooWiki OCA HUB

Fastapi Auth API Key

fastapi_auth_api_key folder_open OCA/rest-framework open_in_new
Others License: AGPL-3

Provides FastAPI dependencies for Api Key authentication.

auto_awesome What this module does

AI-generated from the code · Odoo 18.0

Lets you restrict which API keys can call each FastAPI endpoint by assigning an API key group to the endpoint.

This module adds an API key group field to FastAPI endpoint records. On the endpoint form, in the resources group, you can pick an auth.api.key.group.

  • If the field is left empty, every API key is allowed to access that endpoint.
  • If a group is set, only API keys belonging to that group are accepted; other keys receive an "Unauthorized" response.

The module also provides the authentication logic used when an endpoint is called: it reads the API key from the HTTP header (by default HTTP-API-KEY, configurable through an environment variable), looks the key up, and checks it against the endpoint's group. Missing or invalid keys return a 401 Unauthorized response with a WWW-Authenticate header.

It touches the fastapi.endpoint model and the auth.api.key model, and depends on the fastapi and auth_api_key_group modules. No new menus or reports are added; the only visible change is the extra field on the FastAPI endpoint form.

Models and fields (1)
  • fastapi.endpoint · extends an existing modelauth_api_key_group_id

Text generated by AI (DeepSeek) from reading the Odoo 18.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub

Availability by version

Reviewed: 2026-11-03
Confirmed (verified in repository and branch) Estimated (unverified) No information

Confirmation status: 2 confirmed, 7 with no information of 9 versions.

Sources · Odoo 18.0

Confirmed on 2026-11-03 in branch 18.0 of OCA/rest-framework.

terminal Installation and usage

OCA documentation · Odoo 18.0

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.

@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

@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.

No verified information in OCA: Installation, Configuration.

info

Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.