Là một công cụ bảo mật, auth0/jwt-decode đã đạt 3.4k sao trên GitHub, ngôn ngữ TypeScript. Decode JWT tokens; useful for browser applications.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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, Microsoft.AspNetCore.Authentication.JwtBearer, etc.
:books: Documentation - :rocket: Getting Started - :speech_balloon: Feedback
Documentation
Docs site - explore our docs site and learn more about Auth0.
Getting started
Installation
Install with NPM or Yarn.
Run npm install jwt-decode or yarn add jwt-decode to install the library.
Usage
import { jwtDecode } from "jwt-decode";
const token = "eyJ0eXAiO.../// jwt token";
const decoded = jwtDecode(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):
const decodedHeader = jwtDecode(token, { header: true });
console.log(decodedHeader);
/* prints:
* {
* typ: "JWT",
* alg: "HS256"
* }
*/
Note: A falsy or malformed token will throw an InvalidTokenError error; see below for more information on specific errors.
Polyfilling atob
This library relies on atob(), which is a global function available on all modern browsers as well as every supported node environment.
In order to use jwt-decode in an environment that has no access to atob() (e.g. React Native prior to version 0.74), ensure to provide the corresponding polyfill in your application by using core-js/stable/atob:
import "core-js/stable/atob";
Alternatively, you can also use base-64 and polyfill global.atob yourself:
import { decode } from "base-64";
global.atob = decode;
Errors
This library works with valid JSON web tokens. The basic format of these token is
[part1].[part2].[part3]
All parts are supposed to be valid base64 (url) encoded json.
Depending on the { header: <option> } option it will decode part 1 (only if header: true is specified) or part 2 (default)
Not adhering to the format will result in a InvalidTokenError with one of the following messages:
Invalid token specified: must be a string => the token passed was not a string, this library only works on strings.
Invalid token specified: missing part # => this probably means you are missing a dot (.) in the token
Invalid token specified: invalid base64 for part # => the part could not be base64 decoded (the message should contain the error the base64 decoder gave)
Invalid token specified: invalid json for part # => the part was correctly base64 decoded, however, the decoded value was not valid JSON (the message should contain the error the JSON parser gave)
Use with TypeScript
The return type of the jwtDecode function is determined by the header property of the object passed as the second argument. If omitted (or set to false), it'll use JwtPayload, when true it will use JwtHeader.
If needed, you can specify what the expected return type should be by passing a type argument to the jwtDecode function.
You can extend both JwtHeader and JwtPayload to include non-standard claims or properties.
import { jwtDecode } from "jwt-decode";
const token = "eyJhsw5c";
const decoded = jwtDecode<JwtPayload>(token); // Returns with the JwtPayload type
Use as a CommonJS package
const { jwtDecode } = require('jwt-decode');
...
Include with a script tag
Copy the file jwt-decode.js from the root of the build/esm folder to your project somewhere, then import jwtDecode from it inside a script tag that's marked with type="module":
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
Auth0's general contribution guidelines
Auth0's code of conduct guidelines
Raise an issue
To provide feedback or report a bug, please raise an issue on our issue tracker.
Vulnerability Reporting
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the MIT license. See the LICENSE file for more info.
auth0/jwt-decode có 3.4k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/auth0/jwt-decode. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
auth0/jwt-decode có những chủ đề gì?
GitHub topics của auth0/jwt-decode: "dx-sdk", "jwt". TopGit xếp repo vào nhóm Security.
auth0/jwt-decode có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho auth0/jwt-decode. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
auth0/jwt-decode còn đang phát triển không?
Commit gần nhất trên auth0/jwt-decode là 18 ngày trước (theo timestamp GitHub). Repo có 344 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
auth0/jwt-decode dùng license gì?
auth0/jwt-decode phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
auth0/jwt-decode viết bằng ngôn ngữ gì?
auth0/jwt-decode chủ yếu viết bằng TypeScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về auth0/jwt-decode ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/auth0/jwt-decode là nguồn chính thức.