Last active
September 8, 2019 03:07
-
-
Save promisepreston/d9e9546ca4aaff0530901cd987392b03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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