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

HMAC section of README outdated #421

Closed
boardfish opened this issue Jun 2, 2021 · 3 comments · Fixed by #422
Closed

HMAC section of README outdated #421

boardfish opened this issue Jun 2, 2021 · 3 comments · Fixed by #422
Assignees

Comments

@boardfish
Copy link
Contributor

This section of the README has the following code:

hmac_secret = 'my$ecretK3y'

token = JWT.encode payload, hmac_secret, 'HS256'

# eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoidGVzdCJ9.pNIWIL34Jo13LViZAJACzK6Yf0qnvT_BuwOxiMCPE-Y
puts token

decoded_token = JWT.decode token, hmac_secret, true, { algorithm: 'HS256' }

# Array
# [
#   {"data"=>"test"}, # payload
#   {"alg"=>"HS256"} # header
# ]
puts decoded_token

# Without secret key
token = JWT.encode payload, nil, 'HS256'

# eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoidGVzdCJ9.pVzcY2dX8JNM3LzIYeP2B1e1Wcpt1K3TWVvIYSF4x-o
puts token

decoded_token = JWT.decode token, nil, true, { algorithm: 'HS256' }

# Array
# [
#   {"data"=>"test"}, # payload
#   {"alg"=>"HS256"} # header
# ]
puts decoded_token

In particular, this line causes issues: decoded_token = JWT.decode token, nil, true, { algorithm: 'HS256' }

At the time of writing, this was probably fine, but now it raises a JWT::DecodeError: No verification key available.

@boardfish
Copy link
Contributor Author

There may be other sections of documentation that suffer from this too.

@anakinj
Copy link
Member

anakinj commented Jun 4, 2021

Thanks for noticing. Think something changed a few versions back. Maybe I'll remove the whole example from the readme, it does not make sense to use an empty string as secret when signing the payload.

@boardfish
Copy link
Contributor Author

I've opened a PR to do so if it makes sense to. Hope that helps!

I'm also happy to check the rest of the README examples and make sure they're up to scratch.

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

Successfully merging a pull request may close this issue.

2 participants