This module provides FastAPI Depends to allow authentication with auth_jwt.
auto_awesome What this module does
AI-generated from the code · Odoo 18.0Adds JWT bearer token authentication to FastAPI endpoints in Odoo, letting API developers secure routes and identify the calling user or partner from a signed token.
This module is a developer building block for Odoo's FastAPI integration. It does not add menus, screens or buttons for end users; instead it provides ready-made authentication helpers that API developers can attach to their FastAPI routes.
- It accepts a JWT token sent in the standard Authorization header, or in a cookie when the configured validator allows cookies.
- It validates the token against the JWT validators configured in Odoo, including chained validators, and returns a clear 401 Unauthorized response when the token is missing, malformed or invalid.
- It can expose the decoded token payload, the Odoo user environment, or the
res.partnerlinked to the token, so each API route can work with the right user and access rights. - It supports optional authentication: routes can allow anonymous access and fall back to the public user when no token is supplied.
- When cookie mode is enabled, it refreshes the authentication cookie on the response.
It relies on the fastapi and auth_jwt modules and on the Python libraries pyjwt and cryptography. It touches auth.jwt.validator for validation and res.partner for partner identification. No scheduled jobs, emails or business documents are created by this module.
Required by other modules
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-03Confirmation status: 2 confirmed, 7 with no information of 9 versions.
Sources · Odoo 16.0
Confirmed on 2026-11-03 in branch 16.0 of OCA/rest-framework.
terminal Installation and usage
OCA documentation · Odoo 18.0Usage
Source · Odoo 18.0The following FastAPI dependencies are provided and importable from odoo.addons.fastapi_auth_jwt.dependencies:
def auth_jwt_authenticated_payload() -> Payload
> Return the authenticated JWT payload. Raise a 401 (unauthorized) if > absent or invalid.
def auth_jwt_optionally_authenticated_payload() -> Payload | None
> Return the authenticated JWT payload, or None if the Authorization > header and cookie are absent. Raise a 401 (unauthorized) if present > and invalid.
def auth_jwt_authenticated_partner() -> Partner
> Obtain the authenticated partner corresponding to the provided JWT > token, according to the partner strategy defined on the auth_jwt > validator. Raise a 401 (unauthorized) if the partner could not be > determined for any reason. > > This is function suitable and intended to override > odoo.addons.fastapi.dependencies.authenticated_partner_impl. > > The partner record returned by this function is bound to an > environment that uses the Odoo user obtained from the user strategy > defined on the auth_jwt validator. When used > authenticated_partner_impl this in turn ensures that > odoo.addons.fastapi.dependencies.authenticated_partner_env is also > bound to the correct Odoo user.
def auth_jwt_optionally_authenticated_partner() -> Partner
> Same as auth_jwt_partner except it returns an empty recordset bound > to the public user if the Authorization header and cookie are > absent, or if the JWT validator could not find the partner and > declares that the partner is not required.
def auth_jwt_authenticated_odoo_env() -> Environment
> Return an Odoo environment using the the Odoo user obtained from the > user strategy defined on the auth_jwt validator, if the request > could be authenticated using a JWT validator. Raise a 401 > (unauthorized) otherwise. > > This is function suitable and intended to override > odoo.addons.fastapi.dependencies.authenticated_odoo_env_impl.
def auth_jwt_default_validator_name() -> str | None
> Return the name of the default JWT validator to use. > > The default implementation returns None meaning only one active JWT > validator is allowed. This dependency is meant to be overridden.
def auth_jwt_http_header_authorization() -> str | None
> By default, return the credentials part of the Authorization header, > or None if absent. This dependency is meant to be overridden, in > particular with fastapi.security.OAuth2AuthorizationCodeBearer to > let swagger handle OAuth2 authorization (such override is only > necessary for comfort when using the swagger interface).
No verified information in OCA: Installation, Configuration.
Installation instructions, the distribution package, dependencies and configuration steps are not shown because they have not yet been verified in the module documentation for any version.
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.