npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

think-session-jwt-multi

v1.1.2

Published

JsonWebToken for ThinkJS 3.x.增加token获取方式,支持多个。

Downloads

12

Readme

think-session-jwt-multi

仅对 think-session-jwt 做了几行改动。

 let token;
const { tokenType = 'cookie', tokenName = 'jwt' } = this.options;
//支持多个类型
if (tokenType instanceof Array) {
  for (let ttype of tokenType){
    switch (ttype) {
      case 'header':
        token = this.ctx.headers[tokenName];
        break;
      case 'body':
        token = this.ctx.post(tokenName);
        break;
      case 'query':
        token = this.ctx.query[tokenName];
        break;
      default:
        token = this.ctx.cookie(tokenName, undefined, this.options);
        break;
    }
    if (token) {
      break;
    }
  }
} else {
  switch (tokenType) {
    case 'header':
      token = this.ctx.headers[tokenName];
      break;
    case 'body':
      token = this.ctx.post(tokenName);
      break;
    case 'query':
      token = this.ctx.query[tokenName];
      break;
    default:
      token = this.ctx.cookie(tokenName, undefined, this.options);
      break;
  }
}

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

Build Status Coverage Status npm version

Install

npm install think-session-jwt-multi --save

Quick Start

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

exports.session = {
  type: 'jwt',
  common: {
    cookie: {
      name: 'thinkjs',
    }
  },
  jwt: {
    handle: JWTSession,
    secret: 'secret', // secret is reqired
    //此处变更,项目中可能用到多个场景。支持header+cookie
    tokenType: ['header','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的配置。