vue-auth icon indicating copy to clipboard operation
vue-auth copied to clipboard

How to access the payload of a jwt token?

Open chenyuejie opened this issue 9 years ago • 7 comments

Is it possible to access the content of a jwt token? I had read through the document, but found nothing about it.

chenyuejie avatar Apr 21 '17 03:04 chenyuejie

Well you can get the token with $auth.token(); it's in the docs. After that it's up to you.

On Fri, Apr 21, 2017 at 10:58 AM, Yuejie Chen [email protected] wrote:

Is it possible to access the content of a jwt token? I had read through the document, but found nothing about it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/websanova/vue-auth/issues/147, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkcy7b-uxzgki6GRJ6CXOmj_SKCQuJjks5ryClwgaJpZM4ND1jS .

-- Robert Duchnik http://www.duchnik.com

websanova avatar Apr 21 '17 04:04 websanova

@websanova I meant get the payload or JSON object of the token string, sorry for not explain clearly.

chenyuejie avatar Apr 21 '17 04:04 chenyuejie

Hmm, not sure what you're trying to do here.

you can just write your own interceptor or a custom driver if you're trying to do something different. Otherwise whatever is in the "authorization" header will be the token string.

On Fri, Apr 21, 2017 at 11:50 AM, Yuejie Chen [email protected] wrote:

@websanova https://github.com/websanova I meant get the payload or JSON object of the token string, sorry for not explain clearly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/websanova/vue-auth/issues/147#issuecomment-296063041, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkcyzOaWPC48-UL_GfAqLRuk8qkyDS0ks5ryDWhgaJpZM4ND1jS .

websanova avatar Apr 21 '17 06:04 websanova

@websanova I stored some info like user nickname in the jwt token, currently I am using jwt-client to read the JSON object content of the token. It would be nice if we can access the JSON object from the $auth object. I am not familiar with the driver mechanics, I will look into it. Thanks.

chenyuejie avatar Apr 21 '17 07:04 chenyuejie

No idea what you are doing. It's just a base64 encoded string. You can decide it if you like.

On Apr 21, 2017 2:12 PM, "Yuejie Chen" [email protected] wrote:

@websanova https://github.com/websanova I stored some info like user nickname in the jwt token, currently I am using jwt-client https://github.com/pauldijou/jwt-client to read the JSON object content of the token. It would be nice if we can access the JSON object from the $auth object. I am not familiar with the driver mechanics, I will look into it. Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/websanova/vue-auth/issues/147#issuecomment-296102534, or mute the thread https://github.com/notifications/unsubscribe-auth/ABkcy3fLtoSk7qosarXRQXWPPdRJtjCHks5ryFbLgaJpZM4ND1jS .

websanova avatar Apr 21 '17 07:04 websanova

@chenyuejie You just need to decode the token

This is a non issue

genu avatar Apr 26 '17 04:04 genu

@genu got it, I store the decoded object in other context now.

But I suggest Vue-auth can decode the token and store it in the $auth object, for sometimes we store some info like roles in the token, and can use them without another get user info request. BTW, it would be nice if Vue-auth role mechanism can use the roles store in the JWT token.

Anyway, I close the issue.

chenyuejie avatar Apr 29 '17 00:04 chenyuejie