如何在客户端解码JWT令牌有效载荷? [英] How to decode JWT Token payload on client side?

查看:104
本文介绍了如何在客户端解码JWT令牌有效载荷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jwt令牌进行身份验证,并想在客户端读取有效负载信息.现在我正在做这样的事情:

I'm using a jwt token for authentication and would like to read the payload information on the client-side. Right now I'm doing something like this:

var payload = JSON.parse(window.atob(token.split('.')[1])); 

是否有更好的方法在浏览器中使用jwt令牌?

Is there a better way to work with jwt tokens within the browser?

推荐答案

来自 https://github. com/auth0/jwt-decode

下载.build/jwt-decode.min.js文件,并将其包含在项目中.

download .build/jwt-decode.min.js file and include in the project.

<script src="js/jwt-decode.min.js"></script>

var token = 'eyJ0eXAiOo876jgJ96...'; // jwt token;
var decoded = jwt_decode(token);
console.log(decoded);

这篇关于如何在客户端解码JWT令牌有效载荷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆