Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when using jwks_client.get_signing_key_from_jwt #593

Closed
namelivia opened this issue Jan 3, 2021 · 1 comment · Fixed by #598
Closed

TypeError when using jwks_client.get_signing_key_from_jwt #593

namelivia opened this issue Jan 3, 2021 · 1 comment · Fixed by #598
Labels

Comments

@namelivia
Copy link

namelivia commented Jan 3, 2021

Hello! First of all thank you for your package, it implements just the solution I was looking for. Also sorry if this report does not have the standard structure but I found it to be easier to explain this way.

When I try jwks_client.get_signing_key_from_jwt I always end up with the following TypeError:

TypeError: the JSON object must be str, bytes or bytearray, not dict

I've done some debugging and this is what I've found out, fetching the data from the endpoint using urllib and doing json_loadson the response returns something like this:

>>> json_response
{'keys': [{'use': 'sig', 'kty': 'EC', 'kid': 'XXX', 'crv': 'P-256', 'alg': 'ES256', 'x': 'XXX', 'y': 'XXX'}]}

The type of this is data is dict, then this is iterated and correctly transformed into a PyJWKSet, and during this construction the instances of PyJWK are initialized receiving each of these keys as the jwk_data in my case these will get:

>>> jwk_data
{'use': 'sig', 'kty': 'EC', 'kid': 'XXX', 'crv': 'P-256', 'alg': 'ES256', 'x': 'XXX', 'y': 'XXX'}

And the type of this is dict too.
Later this data is meant to be read on self.Algorithm.from_jwk(self._jwk_data) and on algorithms.py line 429 tries to convert the expected json data, but for this particular case this is already a dict, and that's why it's rising the TypeError.

obj = json.loads(jwk)

I suppose the most straightforward one would be turning that line into:

obj = jwk if isinstance(jwk, dict) else json.loads(jwk)

I can think of some other ways of fixing this, but probably someone more experienced with this codebase can think of a better solution. In any case if you are interested on me giving a try let me know.

@namelivia
Copy link
Author

Thanks! 👏

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 a pull request may close this issue.

2 participants