parsing tokens

196 views
Skip to first unread message

Carlton Smith III

unread,
Oct 22, 2015, 5:08:06 PM10/22/15
to ruby-jwt
Fairly new to ruby here. I'd like to know if anyone has any examples of parsing a token once it has been decoded.

excpt

unread,
Oct 27, 2015, 10:45:33 AM10/27/15
to ruby-jwt
Hi Carlton,

if you take a look at the README.md (https://github.com/jwt/ruby-jwt/blob/master/README.md) the JWT.decode method always returns an array.

The array contains two hashes which represent the payload and the header.

You can access them by using the following code:

payload, header = JWT.decode token, mySecret

# display the content
puts payload
.inspect
puts header
.inspect

Carlton Smith III

unread,
Oct 27, 2015, 11:00:09 AM10/27/15
to ruby-jwt
Thanks for the input. I actually was able to figure out why I was having so much difficulty,. I was using the variable "response" to store what JWT returned, and it turns out that is a keyword in Rails. It was displaying an object that had nothing to do with JWT and I couldn't figure out for the life of me how to get to the data. After changing the variable name I had a simple array to deal with.

excpt

unread,
Oct 27, 2015, 11:03:42 AM10/27/15
to ruby-jwt
Hi Carlton,

thanks for the update.
Reply all
Reply to author
Forward
0 new messages