Skip to content

Validation fails when claim has boolean false as value #23

Closed

Description

Hello, I have noticed that when passing a claim that has a boolean false as value, the validation fails with Invalid claim error, e.g.:

registry = jwt.JWTClaimsRegistry(bool_claim={"essential": True})
registry.validate({"bool_claim": False})
Traceback (most recent call last):
  File "/home/schemer/test/test/main.py", line 23, in <module>
    registry.validate({"bool_claim": False})
  File "/home/schemer/test/.venv/lib/python3.12/site-packages/joserfc/rfc7519/registry.py", line 52, in validate
    self.check_value(key, value)
  File "/home/schemer/test/.venv/lib/python3.12/site-packages/joserfc/rfc7519/registry.py", line 31, in check_value
    raise InvalidClaimError(claim_name)
joserfc.errors.InvalidClaimError: invalid_claim: Invalid claim: "bool_claim"

But the same registry validates correctly when the claim has a boolean true:

registry = jwt.JWTClaimsRegistry(bool_claim={"essential": True})
registry.validate({"bool_claim": True})

I went through the code, and found that the issue is getting raised here:

if not allow_blank and not value:

Passing the "allow_blank" option does fix this, but I don't want to have a blank claim and I want to always ensure that it has a value.

Activity

  1. lepture commented on Jun 15, 2024

    @lepture
    Member

    Released 0.12.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions