Skip to content

fix: treat claims option "value" as the expected claim value - #108

Merged
lepture merged 1 commit into
authlib:mainfrom
choksi2212:fix/claims-value-list-option
Oct 23, 2026
Merged

lepture merged 1 commit into
authlib:mainfrom
choksi2212:fix/claims-value-list-option

Conversation

@choksi2212

Copy link
Copy Markdown
Contributor

As confirmed in #107, when the "value" option is a list, the claim should match it as a whole. Today the option value gets wrapped into a nested list and only element membership is checked, so this fails:

jwt.JWTClaimsRegistry(aud={"essential": True, "value": ["id1"]}).validate({"aud": ["id1"]})
# InvalidClaimError: aud

This PR compares the claim with the configured value itself. A list claim matches when it equals the configured value or contains it (so aud arriving as ["id1"] against value: "id1" keeps working), and a scalar claim still has to equal it, so {"aud": "id1"} against {"value": ["id1", "id2"]} keeps raising like before. The values path is untouched.

I also widened the value field in ClaimsOption, since a list there is now valid input.

Added regression tests for the list shapes. On main the new tests raise InvalidClaimError; on this branch the full suite result is unchanged apart from them (the jwe chacha20 and okp pem failures also happen on pristine main in my local environment, they are dependency-dependent).

A list passed to the "value" option was wrapped into a nested list
before the membership check, so a claim equal to the configured
value was rejected, e.g.::

    JWTClaimsRegistry(aud={"essential": True, "value": ["id1"]}).validate({"aud": ["id1"]})

Compare the claim with the configured value itself: a list claim
matches when it equals the configured value or contains it, and a
scalar claim still has to equal it.

Fixes authlib#107

Signed-off-by: choksi2212 <choksi2212@users.noreply.github.com>
@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.86%. Comparing base (7422af8) to head (232d647).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #108   +/-   ##
=======================================
  Coverage   99.86%   99.86%           
=======================================
  Files          47       47           
  Lines        3010     3014    +4     
  Branches      360      362    +2     
=======================================
+ Hits         3006     3010    +4     
  Misses          2        2           
  Partials        2        2           
Flag Coverage Δ
unittests 99.86% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lepture
lepture merged commit bc06b26 into authlib:main Oct 23, 2026
9 checks passed
@lepture

lepture commented Oct 23, 2026

Copy link
Copy Markdown
Member

Thanks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants