Skip to content

[19.0][IMP] auth_oidc: use PyJWT instead of python-jose - #1090

Open
SparkDrago05 wants to merge 1 commit into
OCA:19.0from
SparkDrago05:19.0-auth_oidc-pyjwt
Open

SparkDrago05 wants to merge 1 commit into
OCA:19.0from
SparkDrago05:19.0-auth_oidc-pyjwt

Conversation

@SparkDrago05

Copy link
Copy Markdown

Fixes #1085.

auth_oidc now uses PyJWT to read and check the ID Token, because python-jose is no longer maintained.

The checks are the same as before:

  • only RS256 is accepted;
  • aud is checked only when the token has it;
  • iat must be an integer, but it is not compared to the clock;
  • a JWKS key that cannot be loaded stops the login.

PyJWT does not check at_hash, so the module checks it now, like python-jose did (OpenID Connect Core 3.1.3.6).

The errors raised are now PyJWT errors (jwt.InvalidTokenError and its subclasses) instead of JWTError.

How I checked it is the same:

  • I ran the old python-jose code and the new code on 21 tokens × 7 key sets, with and without an access token: 292 of 294 results are the same.
  • The other 2 use a token that is not a JWT with an empty JWKS. Both versions reject that token earlier, in get_unverified_header.
  • With PyJWT older than 2.10, the string type of sub and jti is not checked.

The tests now serve real JWKs instead of PEM keys. I added tests for at_hash, aud, exp, iat and the algorithm. All 18 tests pass on Odoo 19 with PyJWT 2.15.1.

#1074 changes the same function. To make that merge easier, the algorithm list is in one place, and the at_hash hash follows the token's alg.

AI disclosure: written with Claude Code (Claude Opus 5.5); I reviewed and tested the change.

python-jose is no longer maintained. PyJWT is already used by auth_jwt
on older branches of this repository.

The ID Token is validated as before: RS256 only, aud checked only when
the claim is present, iat must be an integer but is not compared to the
clock, a JWKS key that cannot be loaded stops the login, and at_hash is
checked against the access token (PyJWT does not do it, so this is done
here, as described in OpenID Connect Core 3.1.3.6).

The tests now serve real JWKs and cover at_hash, aud, exp, iat and the
algorithm check.

Assisted-by: Claude Opus 5.5
Signed-off-by: SparkDrago05 <huzaifa.farooq05@gmail.com>
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @sbidoul,
some modules you are maintaining are being modified, check this out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth_oidc: Dependency on python-jose which has no maintainers

2 participants