# ne-koa-auth-rvm

> 登录验证包

Latest version **1.0.1** (published 2019-08-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install ne-koa-auth-rvm
pnpm add ne-koa-auth-rvm
yarn add ne-koa-auth-rvm
bun add ne-koa-auth-rvm
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-08-16 |
| First published | 2019-08-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 3 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | yang |
| Maintainers | qq475998624 |

## Links

- npm: https://www.npmjs.com/package/ne-koa-auth-rvm
- npm.io page: https://npm.io/package/ne-koa-auth-rvm

## Dependencies (3)

- [dayjs](https://npm.io/package/dayjs.md) ^1.7.4
- [winston](https://npm.io/package/winston.md) ^3.0.0
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.2.2

## Recent versions

- 1.0.1 (latest) — 2019-08-16
- 1.0.0 — 2019-08-16

## README

# koa-auth handbook
>Koa用法
## use jwt
    const koaAuth = require('ne-koa-auth');
    const {jwt,utils} = koaAuth;
### use jwt sign
    jwt.sign(payload[,exp]);
        --payload: require,加密的主体
            --_id: require,用户唯一id
            --ip:  require,用户ip地址，例如：ip可以使用 utils.getIp(ctx)得到
            ... 其他任意参数
        --exp: unrequire,失效时间 默认为30m,你可以传入字符串或者数字来规定失效时间
### use jwt verify
    jwt.verify(token);
        --token: require,签名字符串

### use jwt middleware
    app.use(jwt.middleware(config[,callback]));
        --config: require,koa config
              --match:xx, unrequire,匹配xx则需要验签,可以为String,Array,RegExp,默认'/'
              --except:xx, unrequire,不匹配xx则需要验签,可以为String,Array,RegExp,如果 "match"和"except"同时存在,则只生效match
        --callback: unrequire 在解签成功后，会触发回调函数，如果回调函数返回值为false，则会抛出401错误
    如果签名成功,则会在ctx增加user属性--> ctx.user

>Egg用法

    在 middleware 文件中增加auth.js(文件名可以任意命名)文件

        'use strict';
        const { jwt } = require('ne-koa-auth');
        module.exports = jwt.middleware;

    如果想添加回调函数，则需要小小的改变
        module.exports = options=>{
          return jwt.middleware(options,callback);
        }

    在 config.default.js 文件中增加配置
**这里(auth)名称要和middleware中的(auth.js)文件名一样,当然你也可以使用任何命名，只要保持一致即可**

    config={
        middleware:[其余中间件,'auth'],
        auth:{
            match:xx, unrequire,匹配xx则需要验签,可以为String,Array,RegExp,默认'/'
            except:xx, unrequire,不匹配xx则需要验签,可以为String,Array,RegExp,如果 "match"和"except"同时存在,则只生效match
        },
        ip:false  // 不校验ip
    }

    在controller/serverAdmin.js中的serverAdmin.js中的postLogin方法内
    修改签名方式
    const { jwt, utils } = require('ne-koa-auth');
    ....
    const token = jwt.sign({
      _id: admin._id,
      ip: utils.getIp(ctx,{xRealIp:false}),
    }[,exp]);//在签名的时候，如果想延长签名失效时间，可以传入exp参数

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