Skip to content

Instantly share code, notes, and snippets.

@promisepreston
Last active September 8, 2019 03:07
Show Gist options
  • Select an option

  • Save promisepreston/d9e9546ca4aaff0530901cd987392b03 to your computer and use it in GitHub Desktop.

Select an option

Save promisepreston/d9e9546ca4aaff0530901cd987392b03 to your computer and use it in GitHub Desktop.
require 'jwt'
payload = { data: 'test' }
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment