JsonWebToken for ThinkJS 3.x.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 4e84989 Nov 15, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test update test case Nov 15, 2018
.editorconfig 🎉first commit Aug 17, 2017
.eslintrc 🎉first commit Aug 17, 2017
.gitignore 支持多种token存储方式 Aug 23, 2017
.npmignore add verify callback Nov 15, 2018
.travis.yml 分离token获取和设置的配置 Aug 23, 2017
LICENSE Initial commit Aug 17, 2017
README.md add verify callback Nov 15, 2018
index.js update test case Nov 15, 2018
package-lock.json 1.1.0 Nov 15, 2018
package.json 1.1.0 Nov 15, 2018

README.md

think-session-jwt

JsonWebToken to store session for ThinkJS 3.x base on node-jsonwebtoken

Build Status Coverage Status npm version

Install

npm install think-session-jwt --save

Quick Start

const JWTSession = require('think-session-jwt');

exports.session = {
  type: 'jwt',
  common: {
    cookie: {
      name: 'thinkjs',
    }
  },
  jwt: {
    handle: JWTSession,
    secret: 'secret', // secret is reqired
    tokenType: 'cookie', // ['query', 'body', 'header', 'cookie'], 'cookie' is default
    tokenName: 'jwt', // if tokenType not 'cookie', this will be token name, 'jwt' is default
    sign: {
      // sign options is not required
    },
    verify: {
      // verify options is not required
    },
    verifyCallback: any => any, // default verify fail callback
  }
}
  1. session数据从token中获取,通过配置tokenType指定token来源;
  2. 设置session数据后会返回token字符串;
  3. 配置verifyCallback函数,验证失败时返回该函数运行的结果;

Sign and verify options

使用node-jsonwebtoken的配置。