fix that match_kid allways return None#1094
Conversation
…nd kid arg was str
There was a problem hiding this comment.
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_idproperty 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.
| def key_id(self) -> int | None: | ||
| """The `kid` property from the JWK. | ||
|
|
||
| :rtype: str or None |
There was a problem hiding this comment.
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.
| :rtype: str or None | |
| :rtype: int or None |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
token was got from php library https://github.com/web-token/jwt-framework |
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