# sp-auth

> sp-base auth managment

Latest version **2.1.0** (published 2017-11-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install sp-auth
pnpm add sp-auth
yarn add sp-auth
bun add sp-auth
```

## 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 | 2.1.0 |
| Published | 2017-11-21 |
| First published | 2017-02-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | cs_victor@126.com |
| Maintainers | dongwenxiao |
| Keywords | sp-base, sp-auth |

## Links

- npm: https://www.npmjs.com/package/sp-auth
- Repository: https://github.com/dongwenxiao/sp-auth
- Homepage: https://github.com/dongwenxiao/sp-auth#readme
- Issues: https://github.com/dongwenxiao/sp-auth/issues
- npm.io page: https://npm.io/package/sp-auth

## Dependencies (2)

- [sp-model](https://npm.io/package/sp-model.md) ^2.3.0
- [sp-functions](https://npm.io/package/sp-functions.md) ^2.1.0

## 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

- 2.1.0 (latest) — 2017-11-21
- 2.0.0 — 2017-11-21
- 1.2.1 — 2017-02-20
- 1.2.0 — 2017-02-19
- 1.1.2 — 2017-02-19
- 1.1.1 — 2017-02-19
- 1.1.0 — 2017-02-19
- 1.0.3 — 2017-02-13
- 1.0.2 — 2017-02-13
- 1.0.1 — 2017-02-08
- 1.0.0 — 2017-02-07

## README

# sp-auth 权限管理

是基于super-project的权限配置和访问控制模块，主要包含了：

 - ```user_access_token``` 创建和查找
 - ```ACL``` 判断逻辑

## 挂载middleware
```js
const acl = require('sp-auth/middleware')
const config = require('./config')
app.use(acl(config.acl, instance.authService))
```


## 使用service

```js
// file: User.js

import User from 'sp-auth/models/User'
export default class extends User {   
}
```

```js
// file: instance.js

import spMysql from 'sp-mysql'
import User from './models/User'
import AuthService from 'sp-auth/service'
import UserAccessToken from 'sp-auth/models/UserAccessToken'

const config = require('./config')
const mysql = new spMysql(config.mysql)


const userModel = new User(mysql)
const userAccessTokenModel = new UserAccessToken(mysql)

const authService = new AuthService()
authService.inject({ userModel, userAccessTokenModel })

export {
    mysql,
    userModel,
    authService
}
```

### register({ status, role })

### login(userId)

## ACL Example

```js
// acl 配置样例
// 黑名单和白名单结构一样

module.exports = {
    ANYONE: [
        '/login|*',
        '/register|get',
        '/register|post',
        '/forget|get'
    ],
    ADMIN: [
        '/dashboard|*',
        '/report|*',
        '/account/*|get'
    ]
}
```

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