Skip to content

[18.0][MIG] auth_oauth_server: Migration to 18.0 - #1069

Open
LorenzoC0 wants to merge 5 commits into
OCA:18.0from
LorenzoC0:18.0-mig-auth_oauth_server
Open

LorenzoC0 wants to merge 5 commits into
OCA:18.0from
LorenzoC0:18.0-mig-auth_oauth_server

Conversation

@LorenzoC0

Copy link
Copy Markdown

Forward port of #1032

eLBati and others added 3 commits October 20, 2026 14:26
Odoo can log users in through external providers (auth_oauth, auth_oidc,
auth_saml) and accept bearer JWTs on routes (auth_jwt), but nothing lets
it issue tokens to third-party applications. This module makes Odoo an
OAuth 2.1 authorization server, following what the MCP authorization
specification requires, so that MCP clients can connect to an MCP server
hosted in Odoo by having the user log in and approve.

- Authorization code flow with mandatory PKCE (S256). Refresh tokens are
  stored as digests and rotated on each use; reusing a code or a rotated
  refresh token revokes the authorization.
- Discovery: authorization server metadata (RFC 8414) and protected
  resource metadata (RFC 9728).
- Clients registered by an administrator, through dynamic registration
  (RFC 7591), or identified by a Client ID Metadata Document, fetched
  from public addresses only.
- Tokens bound to the resource they were asked for (RFC 8707), iss in
  authorization responses (RFC 9207), token revocation (RFC 7009).
- Access tokens are short-lived JWTs signed with an auth_jwt validator
  created for each protected resource, so routes can use
  auth="jwt_<validator>". Each token is also checked against its
  authorization, so revoking one takes effect at once.
- Login is left to Odoo's login page (password, two-factor, auth_oauth,
  ...), followed by a consent page bound to the validated request.
- Users see and revoke the applications they connected in their
  preferences; administrators manage resources, clients and
  authorizations.

Assisted-by: Claude Opus 5.5
- post_init_hook takes the environment;
- settings in a block of their own, with the 17.0 setting layout;
- attrs turned into Python expressions, tree into list; the fields only
  used in expressions are no longer declared invisible; the actions
  have a path;
- the token, revocation and registration endpoints declare a read/write
  cursor: auth="none" routes are read-only by default since 17.2;
- the tests remove the auth="jwt_..." methods auth_jwt adds to ir.http
  for the validators of the resources, which Odoo now reports as leaked;
- f-strings and no bare expression, as ruff now requires.
@LorenzoC0 LorenzoC0 changed the title [18.0][MIG] auth_oauth_server: OAuth 2.1 authorization server [18.0][MIG] auth_oauth_server: Migration to 18.0 Nov 17, 2026
…opt-in

Both were enabled at installation, and client metadata documents were
accepted from any domain: anyone could register an application under the
name of a well-known one, with redirect URIs of their own, and have users
approve it from a link. The consent page warns about it, in small print.

They now stay off until an administrator enables them in the settings;
the readme recommends listing the domains of the metadata documents to
accept. The installation hook only pins the issuer.

Tests: the hook leaves both off; the fixtures enable them for the tests
that use them.
Security:
- Used refresh tokens were deleted a day after their use, so a stolen
  copy presented later went unnoticed: they are now kept until they
  expire, and presenting one again revokes the authorization.
- Within the grace period, a used refresh token was accepted again as
  often as asked, each time starting a parallel chain of tokens: the
  refresh token issued in exchange is now derived from the one
  presented, so that all those requests get the same one.
- A request asking only for scopes unknown to the resource got all of
  its scopes: it is now refused with invalid_scope.
- Client metadata documents: the download connects to the address
  checked as public, not to a new resolution of the name (DNS
  rebinding); it is cut when its time is up, however slowly the host
  answers; and the request, including whether the user is allowed on
  the resource, is checked before any document is fetched and any
  client created.

Correctness:
- Scopes removed from a resource are left out of the tokens of the
  applications already authorized.
- Disabling dynamic registration or metadata documents stops the
  clients registered that way.
- Revoking a token of another client is refused (RFC 7009 2.1), and an
  access token expired, or of an authorization not valid for now,
  still revokes its authorization.
- The token request must repeat the redirect_uri of the authorization
  request, if it had one (RFC 6749 4.1.3).
- Commas are refused in resource paths (auth_jwt splits the audience
  on them), validator names are ASCII identifiers, and malformed host
  names or grant_types give OAuth errors instead of errors 500.

The download uses http.client rather than requests, which cannot
choose the address it connects to: the HTTPS_PROXY environment
variable no longer applies to it.
@LorenzoC0
LorenzoC0 force-pushed the 18.0-mig-auth_oauth_server branch from fc1d91d to 68541de Compare November 26, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:auth_oauth_server Module auth_oauth_server series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants