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
Problem decoding token #319
Comments
Try decoding the token to utf-8: jwt.encode(data, secret, algorithm).decode('utf-8') In jwt.io, you need to get rid of the |
Didn't work @vimalloc here's the code I'm using: def get_user(info):
token = info.context.META.get('HTTP_AUTHORIZATION')
if not token:
return
try:
decoded = jwt.decode(token, 'secret', 'utf-8') # Decoding here
user = User.objects.get(pk=decoded['user_id'])
return user
except:
raise Exception('User not found') I'm definitely getting the token, because if I check with: def get_user(info):
token = info.context.META.get('HTTP_AUTHORIZATION')
print(token) I get it printed in the console
|
This isn't right: decoded = jwt.decode(token, 'secret', 'utf-8') You want to create the token like such: # The decode call here doesn't decode the jwt, it converts the encoded jwt from
# a byte string to a utf-8 string.
data = {'foo': 'bar'}
encoded_token = jwt.encode(data, 'secret', 'HS256').decode('utf-8') and decode it like: decoded_token = jwt.decode(encoded_token, 'secret', algorithms=['HS256']) |
Thanks a lot @vimalloc that solves the issue! |
@vimalloc thank you for helping out, really appreciate it 🥇 |
Thanks @vimalloc , You saved me. |
Thanks @vimalloc, after spent a whole day in this, i found this issue and, principally, your ask. |
This is related to jpadilla/pyjwt#319
where we will apply this? |
Thanks again @vimalloc, and for future googlers, this solves the following exceptions:
|
Hello, thanks for making pyjwt!
I've been trying to use it in my Django application, however, something weird is happening: I can't decode the token!
This is how I'm creating the token
And creating a token with
user_id: 1
gives me this tokenb'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxfQ.J_RIIkoOLNXtd5IZcEwaBDGKGA3VnnYmuXnmhsmDEOs'
, however it says invalid signature in https://jwt.io/ for some reason.Trying to decode my token in the server throws this error:
Why is the exception happening?
Thanks a lot!
The text was updated successfully, but these errors were encountered: