Day 77/100 前端如何解析Token为可读的内容?

(一)使用 JWT-Decode

jwt-decode是一个小的浏览器库,用于帮助解码Base64Url编码的JWTs令牌。

周下载量 3,586,702

IMPORTANT: This library doesn't validate the token, any well formed JWT can be decoded. You should validate the token in your server-side logic by using something like express-jwt, koa-jwt, Owin Bearer JWT, etc.

只要,符合规范的JWT都能解码

(二)使用DEMO

import jwt_decode from "jwt-decode";
 
var token = "eyJ0eXAiO.../// jwt token";
var decoded = jwt_decode(token);
 
console.log(decoded);
 
/* prints:
 * { foo: "bar",
 *   exp: 1393286893,
 *   iat: 1393268893  }
 */
 
// decode header by passing in options (useful for when you need `kid` to verify a JWT):
var decodedHeader = jwt_decode(token, { header: true });
console.log(decodedHeader);
 
/* prints:
 * { typ: "JWT",
 *   alg: "HS256" }
 */

参考链接

1、jwt-decode
https://www.npmjs.com/package...

2、token在线解压地址
https://www.box3.cn/tools/jwt...

写在最后的话

学习路上,常常会懈怠

《有想学技术需要监督的同学嘛~》
https://mp.weixin.qq.com/s/Fy...

你可能感兴趣的:(Day 77/100 前端如何解析Token为可读的内容?)