Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
204 changes: 204 additions & 0 deletions auth_oauth_server/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
==========================
OAuth Authorization Server
==========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:eb111f86f7a6aebcf3f080391d42a302e6f0aaa59fd74b5b059161b092f3c142
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
:target: https://github.com/OCA/server-auth/tree/18.0/auth_oauth_server
:alt: OCA/server-auth
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-auth-18-0/server-auth-18-0-auth_oauth_server
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module makes Odoo an OAuth 2.1 authorization server: applications
ask a user for access, the user logs in on the usual Odoo login page and
approves, and the application receives tokens that let it call an API of
Odoo as that user, with that user's access rights.

It supports what the `MCP authorization
specification <https://modelcontextprotocol.io/specification/latest/basic/authorization>`__
requires, so MCP clients can connect to an MCP server hosted in Odoo:

- authorization code flow with mandatory PKCE (S256), and refresh
tokens, rotated on each use;
- discovery: authorization server metadata (RFC 8414) and protected
resource metadata (RFC 9728);
- applications may be registered by an administrator, register
themselves (RFC 7591), or be identified by the URL of the details
they publish (OAuth Client ID Metadata Documents);
- tokens bound to the API they were asked for (RFC 8707 resource
indicators), ``iss`` in authorization responses (RFC 9207), token
revocation (RFC 7009).

Access tokens are short-lived JWTs checked by an ``auth_jwt`` validator,
which the module creates for each protected API. Routes can therefore be
protected with ``auth="jwt_<validator name>"``, as with any other
``auth_jwt`` validator. Each token is also checked against the
authorization it comes from, so that revoking an authorization takes
effect at once.

Logging in is left to Odoo: password, two-factor authentication, and
login through another provider (``auth_oauth``, ``auth_oidc``,
``auth_saml``) all work.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

In *Settings > General Settings > OAuth Authorization Server*:

- **OAuth Issuer URL**: the public HTTPS address of Odoo, as
applications reach it. It is set from ``web.base.url`` at
installation; check it, especially behind a reverse proxy (where
``proxy_mode`` must be enabled too). Changing it invalidates the
access tokens issued so far; applications get new ones with their
refresh tokens.
- **Accept Client Metadata Documents**: let applications identify
themselves with the URL of the details they publish, without being
registered first. Odoo then fetches that URL, from public addresses
only. Optionally, list the domains to accept.
- **Allow Dynamic Client Registration**: let applications register
themselves.

Then, in *Settings > Users & Companies > OAuth Server > Protected
Resources*, declare each API that accepts the tokens: its path on this
server, the scopes applications may ask for, the groups whose users may
give access (all internal users when empty), and the lifetime of tokens.

Applications to be registered by hand go in *OAuth Applications*. Give
them the Client ID and, for confidential ones, the secret shown by
*Generate Secret*.

With several databases on one server, set ``dbfilter`` so that each host
name selects one database: the endpoints of this module are called
without a session, so they cannot work otherwise.

Usage
=====

Applications discover the server from
``<issuer>/.well-known/oauth-authorization-server`` and each protected
API from ``<issuer>/.well-known/oauth-protected-resource<path>``. When a
user connects an application, Odoo asks them to log in if needed, then
shows what the application asks for and where the user will be sent.
Once the user allows it, the application can call the API.

Users see the applications they connected in their preferences (*Account
Security* tab) and can revoke them there. Administrators see every
authorization in *Settings > Users & Companies > OAuth Server*.

To protect a route of your own module, either use the resource's
validator in the route:

.. code:: python

@http.route("/api/orders", auth="jwt_oauth_server_api", type="http")
def orders(self):
if "orders:read" not in request.jwt_payload["scope"].split():
raise Forbidden()
...

or check the token yourself, which also gives you the
``WWW-Authenticate`` header that lets clients discover the server:

.. code:: python

resource = request.env.ref("my_module.my_resource").sudo()
try:
uid, payload = resource._authenticate_bearer(token, ["orders:read"])
except Unauthorized:
headers = [("WWW-Authenticate", resource._www_authenticate())]
...

Known issues / Roadmap
======================

- Tokens are signed with a secret (HS256) known only to this database,
so only Odoo itself can check them. Asymmetric keys published as a
JWKS would let other servers check them too.
- No OpenID Connect (ID tokens, userinfo), no token introspection, no
``private_key_jwt`` client authentication.
- Redirect URIs must use https, or http on localhost: private-use
schemes of native applications are not supported.
- Dynamic client registration is not rate limited; use a reverse proxy,
or disable it.
- A resource created while Odoo runs registers its ``auth="jwt_..."``
route method only in the worker that created it (an ``auth_jwt``
limitation): restart the workers before using it in routes.
- Users of the portal can authorize applications when a resource allows
their group, but cannot see or revoke them from the portal.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_oauth_server%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Lorenzo Battistini

Contributors
------------

- Lorenzo Battistini

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-eLBati| image:: https://github.com/eLBati.png?size=40px
:target: https://github.com/eLBati
:alt: eLBati

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-eLBati|

This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/18.0/auth_oauth_server>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions auth_oauth_server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import controllers
from . import models
from .hooks import post_init_hook
30 changes: 30 additions & 0 deletions auth_oauth_server/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2026 Lorenzo Battistini
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "OAuth Authorization Server",
"summary": "Let applications obtain OAuth 2.1 access tokens for Odoo users",
"version": "18.0.1.0.0",
"category": "Tools",
"license": "LGPL-3",
"author": "Lorenzo Battistini, Odoo Community Association (OCA)",
"maintainers": ["eLBati"],
"website": "https://github.com/OCA/server-auth",
"development_status": "Alpha",
"depends": ["auth_jwt", "base_setup"],
"external_dependencies": {"python": ["pyjwt"]},
"data": [
"security/ir.model.access.csv",
"security/oauth_server_security.xml",
"views/oauth_server_resource_views.xml",
"views/oauth_server_client_views.xml",
"views/oauth_server_authorization_views.xml",
"views/auth_jwt_validator_views.xml",
"views/res_users_views.xml",
"views/res_config_settings_views.xml",
"views/oauth_server_menus.xml",
"views/oauth_server_templates.xml",
],
"post_init_hook": "post_init_hook",
"installable": True,
}
1 change: 1 addition & 0 deletions auth_oauth_server/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
Loading
Loading