Skip to content

Conversation

@krakozybra
Copy link

@krakozybra krakozybra commented Sep 19, 2025

Hello ! I worked with auth using jwk client. I ran get_signing_key_from_jwt method to check token. I faced with error jwt.exceptions.PyJWKClientError: Unable to find a signing key that matches: "1399593380". I checked api from where i got jwks.json. And this kid was there. i began debugging process. As result i found that match_kid method return None every time. After a short time and several prints i found that key_id was int, but in type hints was string. The problem was that python couldn't compare sting and int correctly. I fix it using type conversion to string. And it works ! And i fix type hint for kid_id, too. I got it php service and library for jwt. As i understood kid could be as string as int, depending on implementation for different languages and libraries. Thanks

here is example of my keys

"keys": [
    {
        "alg": "ES256",
        "crv": "P-256",
        "kid": 1399593380,
        "kty": "EC",
        "use": "sig",
        "x": "N_GHdF-7ExmKs-HgldA3LcDpTMjBHQSp9zUwyRhHyeYsaf",
        "y": "zFt09hBgGv0uRWerpGZSMPrYHhyAZMr5z3QgzJCasfKy2k"
    },
]

@auvipy auvipy requested review from auvipy and Copilot and removed request for Copilot September 20, 2025 03:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes a bug where JWT key matching fails when the key ID (kid) is provided as an integer in the JWK instead of a string. The issue prevented successful JWT signature verification when the JWK provider returns numeric key IDs.

  • Converts key ID to string during comparison to handle both string and integer key IDs
  • Updates type hint for key_id property to reflect that it can be an integer

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
jwt/jwks_client.py Converts key_id to string in comparison to handle numeric key IDs
jwt/api_jwk.py Updates type hint for key_id property to indicate it can be an integer

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

jwt/api_jwk.py Outdated
def key_id(self) -> int | None:
"""The `kid` property from the JWK.
:rtype: str or None
Copy link

Copilot AI Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring annotation :rtype: str or None is inconsistent with the updated type hint int | None. It should be updated to :rtype: int or None or better yet :rtype: int | str | None to reflect that the kid can be either type in practice.

Suggested change
:rtype: str or None
:rtype: int or None

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <[email protected]>
@krakozybra
Copy link
Author

token was got from php library https://github.com/web-token/jwt-framework

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.

1 participant