Mastering Hybrid Authentication in Odoo 18.0 or 19.0
Bridging the gap between strict OpenID Connect and standard OAuth2.
Modern enterprise environments often require a mix of strict OpenID Connect (OIDC) providers like Keycloak or AWS Cognito, alongside standard OAuth2 providers like GitHub. While the OCA auth_oidc module is the gold standard for OIDC, it traditionally struggles with OAuth2 providers that do not issue an id_token.
In our latest contribution to the OCA Server-Auth repository, we've introduced a "Hybrid" approach to solve this.
The Technical Challenge: The Missing id_token
When authenticating via GitHub, the server returns an access_token but no id_token. Standard OIDC modules expect both and will fail with an AccessDenied error if the latter is missing.
Our improvement allows the auth_oidc module to detect when an id_token is absent and gracefully fall back to the standard Odoo UserInfo validation.
The Implementation in OCA server-auth (PR #917)
The logic ensures that if you are using the Authorization Code Flow (id_token_code), Odoo will:
- Perform the secure server-to-server POST to exchange the code for a token.
- If an
id_tokenexists (Keycloak/Cognito), it performs full signature verification. - If only an
access_tokenexists (GitHub), it leverages Odoo's coresuper()logic to fetch user details from theUserInfoAPI.
Step-by-Step GitHub Integration
1. GitHub OAuth App
- Callback URL:
https://your-odoo.com - Scope:
read:user user:email
2. Odoo System Parameters
GitHub requires the token in the header. Set this in Settings > Technical > System Parameters:
- Key:
auth_oauth.authorization_header - Value:
1
3. The Odoo Provider Config
- Auth Flow:
id_token_code(Authorization Code Flow) - Token Map:
{"user_id": "id", "login": "login", "name": "name"}
Comments
Post a Comment