# quick-token

> 开箱即用的 token 管理/生成工具，支持 express koa

Latest version **0.0.2** (published 2020-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install quick-token
pnpm add quick-token
yarn add quick-token
bun add quick-token
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2020-05-29 |
| First published | 2020-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wangyongfeng |
| Maintainers | imaoda |
| Keywords | crypto, token, auth |

## Links

- npm: https://www.npmjs.com/package/quick-token
- npm.io page: https://npm.io/package/quick-token

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.0.2 (latest) — 2020-05-29
- 0.0.1 — 2020-05-28

## README

## introduction

一个中间件

- 自动帮你创建 token + 校验 token
- 支持 express koa
- 支持 cookie 形式，也支持 query 形式的 token

```js
const quickToken = require("quick-token");

// 中间件
app.use(quickToken({ key: "xyz" }));
```

## 参数

| 参数名       | 缺省值                       | 用意                                                                          |
| ------------ | ---------------------------- | ----------------------------------------------------------------------------- |
| key          | 'maoda'                      | 加密算子                                                                      |
| authPath     | ()=>true                     | 需要校验登陆信息的路由                                                        |
| tokenName    | 'token'                      | 种植/读取 cookie 的字段名称                                                   |
| autoRedirect | undefined                    | token 失败跳转的登陆 url，缺省不跳转                                          |
| subDomain    | false                        | cookie 是否只种在子域下                                                       |
| error        | {code:2, msg:'登陆信息失效'} | 无 token/token 无效/token 过期的返回内容                                      |
| loginPath    | undefined                    | 提供登陆的路由 post 账密接口                                                  |
| map          | {}                           | 如需跳转登录，则给出账密字典 {maoda:'1024', tuzi: '1024'}，或者返回字典的函数 |

> 登陆接口 post 的格式必须为 json username password

## 常规使用

```js
const quickToken = require("quick-token");
// 在 cookie body 在静态资源中间件 之后引入，
const authIgnorePath = [];
app.use(
  quickToken({
    key: "maoda",
    authPath(path) {
      if (authIgnorePath.includes(path)) return false;
      return true;
    },
    map() {
      return { maoda: "mypassword" };
    },
    autoRedirect: "/login.html", // 登陆页面，需定义路由，指定页面
    loginPath: "/auth/login", // 提交账密的 接口，无需定义路由，直接 post 就好，
  })
);
```

---
_Source: https://npm.io/package/quick-token · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
