@nocobase/plugin-auth 0.17.0-alpha.3 → 0.17.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/externalVersion.js +6 -5
- package/dist/node_modules/cron/package.json +1 -1
- package/dist/server/plugin.d.ts +2 -0
- package/dist/server/plugin.js +19 -7
- package/dist/server/storer.d.ts +16 -0
- package/dist/server/storer.js +69 -0
- package/dist/server/token-blacklist.d.ts +3 -0
- package/dist/server/token-blacklist.js +25 -1
- package/package.json +2 -2
package/dist/externalVersion.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
"@nocobase/client": "0.17.0-alpha.
|
|
2
|
+
"@nocobase/client": "0.17.0-alpha.5",
|
|
3
3
|
"react": "18.2.0",
|
|
4
4
|
"react-router-dom": "6.14.1",
|
|
5
|
-
"@nocobase/auth": "0.17.0-alpha.
|
|
6
|
-
"@nocobase/database": "0.17.0-alpha.
|
|
7
|
-
"@nocobase/server": "0.17.0-alpha.
|
|
5
|
+
"@nocobase/auth": "0.17.0-alpha.5",
|
|
6
|
+
"@nocobase/database": "0.17.0-alpha.5",
|
|
7
|
+
"@nocobase/server": "0.17.0-alpha.5",
|
|
8
|
+
"@nocobase/cache": "0.17.0-alpha.5",
|
|
8
9
|
"antd": "5.8.6",
|
|
9
10
|
"@formily/react": "2.2.27",
|
|
10
11
|
"@formily/shared": "2.2.27",
|
|
11
12
|
"react-i18next": "11.18.6",
|
|
12
13
|
"@ant-design/icons": "5.1.4",
|
|
13
|
-
"@nocobase/actions": "0.17.0-alpha.
|
|
14
|
+
"@nocobase/actions": "0.17.0-alpha.5"
|
|
14
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"cron","description":"Cron jobs for your node","version":"2.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage"},"dependencies":{"luxon":"^3.2.1"},"devDependencies":{"chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","jest":"~29.5.x","prettier":"~2.8.x","sinon":"^15.0.x"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-12-
|
|
1
|
+
{"name":"cron","description":"Cron jobs for your node","version":"2.3.1","author":"Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)","bugs":{"url":"https://github.com/kelektiv/node-cron/issues"},"repository":{"type":"git","url":"https://github.com/kelektiv/node-cron.git"},"main":"lib/cron","scripts":{"lint":"eslint {lib,tests}/*.js","test":"jest --coverage","test:watch":"jest --watch --coverage"},"dependencies":{"luxon":"^3.2.1"},"devDependencies":{"chai":"~4.2.x","eslint":"~8.36.x","eslint-config-prettier":"^8.7.x","eslint-config-standard":"~17.0.x","eslint-plugin-import":"~2.27.x","eslint-plugin-jest":"~27.2.x","eslint-plugin-n":"~15.6.x","eslint-plugin-prettier":"~4.2.x","eslint-plugin-promise":"~6.1.x","jest":"~29.5.x","prettier":"~2.8.x","sinon":"^15.0.x"},"keywords":["cron","node cron","node-cron","schedule","scheduler","cronjob","cron job"],"license":"MIT","contributors":["Brandon der Blätter <https://interlucid.com/contact/> (https://github.com/intcreator)","Romain Beauxis <toots@rastageeks.org> (https://github.com/toots)","James Padolsey <> (https://github.com/jamespadolsey)","Finn Herpich <fh@three-heads.de> (https://github.com/ErrorProne)","Clifton Cunningham <clifton.cunningham@gmail.com> (https://github.com/cliftonc)","Eric Abouaf <eric.abouaf@gmail.com> (https://github.com/neyric)","humanchimp <morphcham@gmail.com> (https://github.com/humanchimp)","Craig Condon <craig@spiceapps.com> (https://github.com/spiceapps)","Dan Bear <daniel@hulu.com> (https://github.com/danhbear)","Vadim Baryshev <vadimbaryshev@gmail.com> (https://github.com/baryshev)","Leandro Ferrari <lfthomaz@gmail.com> (https://github.com/lfthomaz)","Gregg Zigler <greggzigler@gmail.com> (https://github.com/greggzigler)","Jordan Abderrachid <jabderrachid@gmail.com> (https://github.com/jordanabderrachid)","Masakazu Matsushita <matsukaz@gmail.com> (matsukaz)","Christopher Lunt <me@kirisu.co.uk> (https://github.com/kirisu)"],"jest":{"collectCoverage":true,"collectCoverageFrom":["lib/*.js"],"coverageThreshold":{"global":{"statements":80,"branches":80,"functions":70,"lines":80}}},"files":["lib","CHANGELOG.md","LICENSE","README.md"],"_lastModified":"2023-12-12T15:14:36.703Z"}
|
package/dist/server/plugin.d.ts
CHANGED
package/dist/server/plugin.js
CHANGED
|
@@ -40,7 +40,9 @@ var import_basic_auth = require("./basic-auth");
|
|
|
40
40
|
var import_locale = require("./locale");
|
|
41
41
|
var import_authenticator = require("./model/authenticator");
|
|
42
42
|
var import_token_blacklist = require("./token-blacklist");
|
|
43
|
+
var import_storer = require("./storer");
|
|
43
44
|
class AuthPlugin extends import_server.Plugin {
|
|
45
|
+
cache;
|
|
44
46
|
afterAdd() {
|
|
45
47
|
}
|
|
46
48
|
async beforeLoad() {
|
|
@@ -59,14 +61,16 @@ class AuthPlugin extends import_server.Plugin {
|
|
|
59
61
|
plugin: this
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
|
-
this.app.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
this.cache = await this.app.cacheManager.createCache({
|
|
65
|
+
name: "auth",
|
|
66
|
+
prefix: "auth",
|
|
67
|
+
store: "memory"
|
|
68
|
+
});
|
|
69
|
+
const storer = new import_storer.Storer({
|
|
70
|
+
db: this.db,
|
|
71
|
+
cache: this.cache
|
|
69
72
|
});
|
|
73
|
+
this.app.authManager.setStorer(storer);
|
|
70
74
|
if (!this.app.authManager.jwt.blacklist) {
|
|
71
75
|
this.app.authManager.setTokenBlacklistService(new import_token_blacklist.TokenBlacklistService(this));
|
|
72
76
|
}
|
|
@@ -90,6 +94,14 @@ class AuthPlugin extends import_server.Plugin {
|
|
|
90
94
|
name: `pm.${this.name}.authenticators`,
|
|
91
95
|
actions: ["authenticators:*"]
|
|
92
96
|
});
|
|
97
|
+
this.app.db.on("users.afterSave", async (user) => {
|
|
98
|
+
const cache = this.app.cache;
|
|
99
|
+
await cache.set(`auth:${user.id}`, user.toJSON());
|
|
100
|
+
});
|
|
101
|
+
this.app.db.on("users.afterDestroy", async (user) => {
|
|
102
|
+
const cache = this.app.cache;
|
|
103
|
+
await cache.del(`auth:${user.id}`);
|
|
104
|
+
});
|
|
93
105
|
}
|
|
94
106
|
async install(options) {
|
|
95
107
|
const repository = this.db.getRepository("authenticators");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Storer as IStorer } from '@nocobase/auth';
|
|
2
|
+
import { Cache } from '@nocobase/cache';
|
|
3
|
+
import { Database } from '@nocobase/database';
|
|
4
|
+
import { AuthModel } from './model/authenticator';
|
|
5
|
+
export declare class Storer implements IStorer {
|
|
6
|
+
db: Database;
|
|
7
|
+
cache: Cache;
|
|
8
|
+
key: string;
|
|
9
|
+
constructor({ db, cache }: {
|
|
10
|
+
db: Database;
|
|
11
|
+
cache: Cache;
|
|
12
|
+
});
|
|
13
|
+
getCache(): Promise<AuthModel[]>;
|
|
14
|
+
setCache(authenticators: AuthModel[]): Promise<void>;
|
|
15
|
+
get(name: string): Promise<AuthModel>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var storer_exports = {};
|
|
19
|
+
__export(storer_exports, {
|
|
20
|
+
Storer: () => Storer
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(storer_exports);
|
|
23
|
+
class Storer {
|
|
24
|
+
db;
|
|
25
|
+
cache;
|
|
26
|
+
key = "authenticators";
|
|
27
|
+
constructor({ db, cache }) {
|
|
28
|
+
this.db = db;
|
|
29
|
+
this.cache = cache;
|
|
30
|
+
this.db.on("authenticators.afterSave", async (model) => {
|
|
31
|
+
if (!model.enabled) {
|
|
32
|
+
await this.cache.delValueInObject(this.key, model.name);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await this.cache.setValueInObject(this.key, model.name, model);
|
|
36
|
+
});
|
|
37
|
+
this.db.on("authenticators.afterDestroy", async (model) => {
|
|
38
|
+
await this.cache.delValueInObject(this.key, model.name);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async getCache() {
|
|
42
|
+
const authenticators = await this.cache.get(this.key);
|
|
43
|
+
if (!authenticators) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return Object.values(authenticators);
|
|
47
|
+
}
|
|
48
|
+
async setCache(authenticators) {
|
|
49
|
+
const obj = authenticators.reduce((obj2, authenticator) => {
|
|
50
|
+
obj2[authenticator.name] = authenticator;
|
|
51
|
+
return obj2;
|
|
52
|
+
}, {});
|
|
53
|
+
await this.cache.set(this.key, obj);
|
|
54
|
+
}
|
|
55
|
+
async get(name) {
|
|
56
|
+
let authenticators = await this.getCache();
|
|
57
|
+
if (!authenticators.length) {
|
|
58
|
+
const repo = this.db.getRepository("authenticators");
|
|
59
|
+
authenticators = await repo.find({ filter: { enabled: true } });
|
|
60
|
+
await this.setCache(authenticators);
|
|
61
|
+
}
|
|
62
|
+
const authenticator = authenticators.find((authenticator2) => authenticator2.name === name);
|
|
63
|
+
return authenticator || authenticators[0];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
Storer
|
|
69
|
+
});
|
|
@@ -2,10 +2,13 @@ import { ITokenBlacklistService } from '@nocobase/auth';
|
|
|
2
2
|
import { Repository } from '@nocobase/database';
|
|
3
3
|
import { CronJob } from 'cron';
|
|
4
4
|
import AuthPlugin from './plugin';
|
|
5
|
+
import { BloomFilter } from '@nocobase/cache';
|
|
5
6
|
export declare class TokenBlacklistService implements ITokenBlacklistService {
|
|
6
7
|
protected plugin: AuthPlugin;
|
|
7
8
|
repo: Repository;
|
|
8
9
|
cronJob: CronJob;
|
|
10
|
+
bloomFilter: BloomFilter;
|
|
11
|
+
cacheKey: string;
|
|
9
12
|
constructor(plugin: AuthPlugin);
|
|
10
13
|
get app(): import("@nocobase/server").default<import("@nocobase/server").DefaultState, import("@nocobase/server").DefaultContext>;
|
|
11
14
|
has(token: string): Promise<boolean>;
|
|
@@ -24,13 +24,33 @@ class TokenBlacklistService {
|
|
|
24
24
|
constructor(plugin) {
|
|
25
25
|
this.plugin = plugin;
|
|
26
26
|
this.repo = plugin.db.getRepository("tokenBlacklist");
|
|
27
|
+
plugin.app.on("beforeStart", async () => {
|
|
28
|
+
try {
|
|
29
|
+
this.bloomFilter = await plugin.app.cacheManager.createBloomFilter();
|
|
30
|
+
await this.bloomFilter.reserve(this.cacheKey, 1e-3, 1e6);
|
|
31
|
+
const data = await this.repo.find({ fields: ["token"], raw: true });
|
|
32
|
+
const tokens = data.map((item) => item.token);
|
|
33
|
+
await this.bloomFilter.mAdd(this.cacheKey, tokens);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
plugin.app.logger.error("token-blacklist: create bloom filter failed", error);
|
|
36
|
+
this.bloomFilter = null;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
27
39
|
}
|
|
28
40
|
repo;
|
|
29
41
|
cronJob;
|
|
42
|
+
bloomFilter;
|
|
43
|
+
cacheKey = "token-black-list";
|
|
30
44
|
get app() {
|
|
31
45
|
return this.plugin.app;
|
|
32
46
|
}
|
|
33
47
|
async has(token) {
|
|
48
|
+
if (this.bloomFilter) {
|
|
49
|
+
const exists = await this.bloomFilter.exists(this.cacheKey, token);
|
|
50
|
+
if (!exists) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
34
54
|
return !!await this.repo.findOne({
|
|
35
55
|
filter: {
|
|
36
56
|
token
|
|
@@ -39,10 +59,14 @@ class TokenBlacklistService {
|
|
|
39
59
|
}
|
|
40
60
|
async add(values) {
|
|
41
61
|
await this.deleteExpiredTokens();
|
|
62
|
+
const { token } = values;
|
|
63
|
+
if (this.bloomFilter) {
|
|
64
|
+
await this.bloomFilter.add(this.cacheKey, token);
|
|
65
|
+
}
|
|
42
66
|
return this.repo.model.findOrCreate({
|
|
43
67
|
defaults: values,
|
|
44
68
|
where: {
|
|
45
|
-
token
|
|
69
|
+
token
|
|
46
70
|
}
|
|
47
71
|
});
|
|
48
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-auth",
|
|
3
|
-
"version": "0.17.0-alpha.
|
|
3
|
+
"version": "0.17.0-alpha.5",
|
|
4
4
|
"main": "./dist/server/index.js",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@ant-design/icons": "5.x",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"displayName.zh-CN": "用户认证",
|
|
25
25
|
"description": "Basic authentication and authenticator management",
|
|
26
26
|
"description.zh-CN": "提供基础认证功能和扩展认证器管理功能",
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "80ae6768a0f4108afa8ac342463627ef3960663f"
|
|
28
28
|
}
|