1 | Auth Center (OAuth2.0 + TOTP)
|
2 | ===
|
3 |
|
4 | [![NPM version](https://img.shields.io/npm/v/auth-center.svg)](https://www.npmjs.com/package/auth-center)
|
5 | [![NPM downloads](https://img.shields.io/npm/dm/auth-center.svg)](https://www.npmjs.com/package/auth-center)
|
6 | [![Build Status](https://travis-ci.org/d-band/auth-center.svg?branch=master)](https://travis-ci.org/d-band/auth-center)
|
7 | [![Coverage Status](https://coveralls.io/repos/github/d-band/auth-center/badge.svg?branch=master)](https://coveralls.io/github/d-band/auth-center?branch=master)
|
8 | [![Dependency Status](https://david-dm.org/d-band/auth-center.svg)](https://david-dm.org/d-band/auth-center)
|
9 |
|
10 | ### 安装
|
11 |
|
12 | ```
|
13 | // 全局安装
|
14 | npm i auth-center -g
|
15 | // 非全局安装
|
16 | npm i auth-center -S
|
17 | ```
|
18 |
|
19 | ### 功能列表
|
20 |
|
21 |
|
22 | - 配置方便、简单,UI简洁
|
23 | - 多数据库支持:MySQL、Postgres、sqlite、mariadb
|
24 | - session支持redis等
|
25 | - OAuth2.0 授权码模式
|
26 | - 密码验证增强(TOTP)
|
27 | - 自带后台管理
|
28 |
|
29 | ### 使用说明
|
30 |
|
31 | > 完整配置文件参考:[config.js](./src/config.js)
|
32 |
|
33 | #### 1. 采用命令行执行
|
34 |
|
35 | ```
|
36 | $ auth-center -h
|
37 |
|
38 | Usage: auth-center [options] [command]
|
39 |
|
40 |
|
41 | Commands:
|
42 |
|
43 | init init config
|
44 | start [options] start server
|
45 |
|
46 | Options:
|
47 |
|
48 | -h, --help output usage information
|
49 | -v, --version output the version number
|
50 |
|
51 | $ auth-center init
|
52 |
|
53 | $ auth-center start -h
|
54 |
|
55 | Usage: auth-center start [options]
|
56 |
|
57 | start server
|
58 |
|
59 | Options:
|
60 |
|
61 | -h, --help output usage information
|
62 | -p, --port <port> server port
|
63 | --config <path> custom config path
|
64 | --sync sync database to generate tables
|
65 | --data <path> init data with json file
|
66 |
|
67 | ```
|
68 |
|
69 | #### 2. 采用引入方式执行
|
70 |
|
71 | ```
|
72 | const AuthServer = require('auth-center');
|
73 |
|
74 | const server = AuthServer({
|
75 | domain: 'http://passport.example.com',
|
76 | orm: {
|
77 | database: 'db_auth',
|
78 | username: 'root',
|
79 | password: 'xxxx',
|
80 | dialect: 'mysql',
|
81 | host: '127.0.0.1',
|
82 | port: 3306,
|
83 | pool: {
|
84 | maxConnections: 10,
|
85 | minConnections: 0,
|
86 | maxIdleTime: 30000
|
87 | }
|
88 | },
|
89 | mail: {
|
90 | from: '系统管理员 <admin@example.com>',
|
91 | host: 'smtp.example.com',
|
92 | port: 465,
|
93 | secure: true,
|
94 | auth: {
|
95 | user: 'admin@example.com',
|
96 | pass: 'admin'
|
97 | }
|
98 | }
|
99 | });
|
100 |
|
101 | server.listen(3000);
|
102 |
|
103 | server.orm.database().sync({
|
104 | force: true
|
105 | }).then(() => { console.log('Sync done.'); });
|
106 | ```
|
107 |
|
108 | ### 参考链接
|
109 |
|
110 | - https://github.com/oauthjs/express-oauth-server
|
111 | - https://github.com/jaredhanson/oauth2orize
|
112 | - https://tools.ietf.org/html/rfc6749#section-4
|
113 | - https://tools.ietf.org/html/rfc6750
|
114 | - http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html
|
115 | - https://developer.github.com/v3/oauth/
|
116 | - https://github.com/guyht/notp
|