Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Extracting payload from json web token #187

Open
bernicetann opened this issue Sep 26, 2017 · 1 comment
Open

Extracting payload from json web token #187

bernicetann opened this issue Sep 26, 2017 · 1 comment

Comments

@bernicetann
Copy link

So I'm trying to just grab the payload by doing this from the rails console:
original_jwt = Knock::AuthToken.new token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MDY1MzcwNjMsImF1ZCI6ZmFsc2UsInVzZXJfaWQiOjMyfQ.-DOTPr-AVmNVS_dH3NMUXhJgnYg3RdeyvZ7_1VTU4RY" => #<Knock::AuthToken:0x007f920c3ad888 @payload={"exp"=>1506537063, "aud"=>false, "user_id"=>32}, @token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MDY1MzcwNjMsImF1ZCI6ZmFsc2UsInVzZXJfaWQiOjMyfQ.-DOTPr-AVmNVS_dH3NMUXhJgnYg3RdeyvZ7_1VTU4RY">

Which means, I should be able to get the payload via:
original_jwt.payload
But it just returns as
NoMethodError: undefined method payload' for #Knock::AuthToken:0x007f920c3ad888`

However, original_jwt.token works.
Does anyone know how to extract the payload?

@krsyoung
Copy link

Hey @bernicetann, any chance you got this working?

I just took a quick look and it seems like it works for me as you expected?

irb(main):003:0> t=Knock::AuthToken.new
=> #<Knock::AuthToken:0x007f9c874dce18 @payload={:exp=>1511473651}, @token=".....">
irb(main):004:0> t.payload
=> {:exp=>1511473651}
irb(main):005:0> t.class
=> Knock::AuthToken

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants