Repository navigation
Conversation
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.
…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
force-pushed
the
18.0-mig-auth_oauth_server
branch
from
November 26, 2026 15:15
fc1d91d to
68541de
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Forward port of #1032