jwt-simple

JWT(JSON Web Token) encode and decode module

jwt-simple downloads jwt-simple version jwt-simple license

jwt-simple类似的npm包:

npm下载趋势

3 年
🌟 在 jwt-simple 的 README.md 中显示实时使用量图表,只需复制下面的代码。
## Usage Trend
[![Usage Trend of jwt-simple](https://npm-compare.com/img/npm-trend/THREE_YEARS/jwt-simple.png)](https://npm-compare.com/jwt-simple#timeRange=THREE_YEARS)

Cumulative GitHub Star Trend

🌟 在 jwt-simple 的 README.md 中显示 GitHub stars 趋势图表,只需复制下面的代码。
## GitHub Stars Trend
[![GitHub Stars Trend of jwt-simple](https://npm-compare.com/img/github-trend/jwt-simple.png)](https://npm-compare.com/jwt-simple)

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
jwt-simple01,356-358 年前MIT

jwt-simple的README

jwt-simple

JWT(JSON Web Token) encode and decode module for node.js.

Install

$ npm install jwt-simple

Usage

var jwt = require('jwt-simple');
var payload = { foo: 'bar' };
var secret = 'xxx';

// HS256 secrets are typically 128-bit random strings, for example hex-encoded:
// var secret = Buffer.from('fe1a1915a379f3be5394b64d14794932', 'hex')

// encode
var token = jwt.encode(payload, secret);

// decode
var decoded = jwt.decode(token, secret);
console.log(decoded); //=> { foo: 'bar' }

decode params

/*
 * jwt.decode(token, key, noVerify, algorithm)
 */

// decode, by default the signature of the token is verified
var decoded = jwt.decode(token, secret);
console.log(decoded); //=> { foo: 'bar' }

// decode without verify the signature of the token,
// be sure to KNOW WHAT ARE YOU DOING because not verify the signature
// means you can't be sure that someone hasn't modified the token payload
var decoded = jwt.decode(token, secret, true);
console.log(decoded); //=> { foo: 'bar' }

// decode with a specific algorithm (not using the algorithm described in the token payload)
var decoded = jwt.decode(token, secret, false, 'HS256');
console.log(decoded); //=> { foo: 'bar' }

Algorithms

By default the algorithm to encode is HS256.

The supported algorithms for encoding and decoding are HS256, HS384, HS512 and RS256.

// encode using HS512
jwt.encode(payload, secret, 'HS512')