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

Failed to decode in jwt #5

Closed
openedhardware opened this issue Feb 6, 2017 · 3 comments
Closed

Failed to decode in jwt #5

openedhardware opened this issue Feb 6, 2017 · 3 comments

Comments

@openedhardware
Copy link

openedhardware commented Feb 6, 2017

I got this error while running your sample code.

File "C:\Python34\lib\site-packages\jwt\api_jwt.py", line 61, in decode
    payload, signing_input, header, signature = self._load(jwt)
  File "C:\Python34\lib\site-packages\jwt\api_jws.py", line 138, in _load
    raise DecodeError('Not enough segments')

  File "C:\Python34\lib\site-packages\jwt\api_jws.py", line 135, in _load
    signing_input, crypto_segment = jwt.rsplit(b'.', 1)
ValueError: need more than 1 value to unpack

It seems like api_jws expects token value to contain b'.'
But my token was just ZSuxk8aa8KAh5idJ

Any idea?

P.S. I just checked the pyjwt library, and it says that it needs comma-based token value.
http://pyjwt.readthedocs.io/en/latest/

>>> import jwt

>>> jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg'

>>> jwt.decode('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg', 'secret')
{'some': 'payload'}
@opyate
Copy link

opyate commented Jun 15, 2017

I'm confused by this too. I ended up using my id_token (which makes python-jose happy), yet Auth0 just recommend I just use auth as per https://auth0.com/docs/api-auth/tutorials/adoption/api-tokens

What did you end up doing?

@chenkie
Copy link
Contributor

chenkie commented Jun 15, 2017

The correct way to do it is to use access tokens

@ryanalane
Copy link

ryanalane commented Mar 14, 2019

I had this same error, but when the token was actually not making it to the server-side (typo when setting the Authorization header on the client).

The access token (and thus the value of jwt, before the jwt.encode('utf-8') call in that class), should be valid a JWT. Try validating it here: https://jwt.io/.

ZSuxk8aa8KAh5idJ can't be a valid JWT.

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

No branches or pull requests

4 participants