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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bjx-passport

v1.3.4

Published

登录中间件

Readme


bjx_passport

bjx_passport 是一个用于 Koa 项目的登录认证中间件,支持配置化参数和动态公共参数注入。


安装

使用 npm 安装:

npm install bjx_passport

快速开始

1. 配置中间件

在项目中创建一个配置文件(例如 bjx_passport.js),用于初始化 bjx_passport 中间件。

const { initialize, BjxPassport } = require('bjx-passport');

// 设置配置文件
BjxPassport.setConfig({
  apisConfig: {
    login: 'https://api.example.com/login', // 登录服务
    common1: 'https://api.example.com/common1' // 其他服务
  },
  cookieConfig: {
    idsrv: 'idsrv.session' // cookieKey 可选参数
  },
  // 签名参数
  signConfig: {
    version: '0.9.0',
    apiVersion: '1.0.0',
    signVersion: '1.0.0',
    signKey: 'your-sign-key',
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret'
  }
});

// 设置公共参数
function bjx_passport() {
  return async (ctx, next) => {
    // 返回的是一个 Promise
    await initialize(ctx, next, {
      globalParams: { OS: '1', BA: '2', BP: '3', EQP: ctx.uuid }
    });
  };
}

module.exports = { bjx_passport };

2. 在 Koa 项目中使用

app.js 中引入并使用 bjx_passport 中间件。

const Koa = require('koa');
const { bjx_passport } = require('./bjx_passport'); // 引入中间件

const app = new Koa();

// 使用 bjx_passport 中间件
app.use(bjx_passport());

// 添加路由
app.use(async (ctx) => {
  ctx.body = 'Hello, bjx_passport!';
});

// 启动服务器
const port = 3000;
app.listen(port, () => {
  console.log(`服务器已启动,访问 http://localhost:${port}`);
});

配置说明

1. BjxPassport.setConfig

用于设置中间件的全局配置。

| 参数 | 类型 | 说明 | 示例值 | |----------------|--------|-------------------------------|-------------------------------| | apisConfig.login | string | 登录服务地址 | https://api.example.com/login | | apisConfig.common1 | string | 其他服务地址 | https://api.example.com/common1 | | cookieConfig.idsrv | string | Cookie 名称【可选】 | idsrv.session | | signConfig.version | string | 客户端版本号 | 0.9.0 | | signConfig.apiVersion | string | API 版本号【可选】 | 1.0.0 | | signConfig.signVersion | string | 签名版本号 【可选】 | 1.0.0 | | signConfig.signKey | string | 签名密钥 | your-sign-key | | signConfig.clientId | string | 客户端 ID | your-client-id | | signConfig.clientSecret | string | 客户端密钥 | your-client-secret |


2. initialize

用于初始化中间件,并注入全局参数。

| 参数 | 类型 | 说明 | 示例值 | |----------------|--------|-------------------------------|-------------------------------| | globalParams.OS | string | 操作系统参数 | 1 | | globalParams.BA | string | 浏览器参数 | 2 | | globalParams.BP | string | 浏览器版本参数 | 3 | | globalParams.EQP | string | 设备参数 | ctx.uuid |


示例

1. 设置全局配置

BjxPassport.setConfig({
  apisConfig: {
    login: 'https://api.example.com/login',
    common1: 'https://api.example.com/common1'
  },
  cookieConfig: {
    idsrv: 'idsrv.session'
  },
  signConfig: {
    version: '0.9.0',
    apiVersion: '1.0.0',
    signVersion: '1.0.0',
    signKey: 'your-sign-key',
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret'
  }
});

2. 使用中间件

app.use(bjx_passport());

发布到 npm

  1. 登录 npm:

    npm login
  2. 发布包:

    npm publish

许可证

本项目基于 ISC License 发布。