kriasoft / web-auth-library

Authentication library for the browser environment using Web Crypto API
https://developer.mozilla.org/docs/Web/API/Web_Crypto_API
MIT License
102 stars 9 forks source link

feat: Add `jwt.decode(...)` function #3

Closed koistya closed 2 years ago

koistya commented 2 years ago

Decoding a JWT token

import { jwt } from "web-auth-library";

jwt.decode("eyJ0eXAiOiJKV1QiLC...");
// => {
//   header: { alg: "HS256", typ: "JWT" },
//   payload: { iss: "...", aud: "...", iat: ..., exp: ... },
//   signature: "xxx"
// }

jwt.decode("eyJ0eXAiOiJKV1QiLC...", { header: false, signature: false });
// => {
//   payload: { iss: "...", aud: "...", iat: ..., exp: ... },
// }