question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Same call to decode does not work with version 2.0.0 when it does in previous versions

See original GitHub issue

In previous versions of pyjwt, we used to be able to call decode without specifying “algorithms”. Now, it is a required parameter. Even when providing the correct algorithm - or even all algorithms, I am seeing an error. This is being done with Azure Active Directory JWT tokens. It’s entirely possible (perhaps even likely) that I’m simply calling decode wrong.

Expected Result

decode runs without error

Actual Result

decode returns the following error: Traceback (most recent call last): File “/usr/local/lib/python3.6/dist-packages/jwt/algorithms.py”, line 242, in prepare_key key = load_pem_private_key(key, password=None) File “/usr/local/lib/python3.6/dist-packages/cryptography/hazmat/primitives/serialization/base.py”, line 18, in load_pem_private_key return backend.load_pem_private_key(data, password) File “/usr/local/lib/python3.6/dist-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1248, in load_pem_private_key password, File “/usr/local/lib/python3.6/dist-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1475, in _load_key self._handle_key_loading_error() File “/usr/local/lib/python3.6/dist-packages/cryptography/hazmat/backends/openssl/backend.py”, line 1518, in _handle_key_loading_error "Could not deserialize key data. The data may be in an " ValueError: Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.

Reproduction Steps

import jwt
aad_token = "AAD_JWT_TOKEN"
jwt.decode(aad_token, verify=False, algorithms=['RS256'])

System Information

{ “cryptography”: { “version”: “3.3.1” }, “implementation”: { “name”: “CPython”, “version”: “3.6.9” }, “platform”: { “release”: “4.15.0-128-generic”, “system”: “Linux” }, “pyjwt”: { “version”: “2.0.0” } }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jpadillacommented, Dec 23, 2020

Thanks @jitendra29mishra. I’m updating the changelog to call out some more of these breaking changes in #584

1reaction
jmishra01commented, Dec 23, 2020

Hello PyJWT Team,

I’m also facing the same issue, my code perfectly working with version 1.7.1 but not with version 2.0.0.

After digging into the code of both versions, I found that the verify argument value does not assign to the verify_signature variable in the new version, because of that my code not working with a new version.

The Solution which I found, pass options argument in jwt.decode method with value {“verify_signature”: False}.

@nwohlgemuth - call jwt.decode in below mention way, may your code work.

import jwt
aad_token = "AAD_JWT_TOKEN"
jwt.decode(aad_token, algorithms=['RS256'], options={"verify_signature": False})
Read more comments on GitHub >

github_iconTop Results From Across the Web

WSJT-X Stopped decoding - FT8-Digital-Mode@groups.io
Recently I was using version 2.0.0 and the sw sometimes would not decode, no stations appeared in either window. I tried everything I...
Read more >
I have problems with jsonpickle.decode and a dictionary
On Raspbian it does not work with the same versions. The error from jsonpickle.decode is as follows (however, other JSON data can be...
Read more >
Decode RTP outside of conversations (WS 2.0) - Wireshark Q&A
I recently installed the latest version of Wireshark (version 2.0.0). I am having a difficult time decoding voice traffic. In the older version...
Read more >
OAuth2 Autoconfig - Spring
This project is a port of the Spring Security OAuth support that came with Spring Boot 1.x. Support was removed in favor of...
Read more >
Case and Decode, Killing sessions - Ask TOM
Tom 1.I usually run into a situation where I run it queries against huge tables, and they run for an hour. some times...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found