@nocobase/plugin-auth 1.2.13-alpha → 1.3.0-alpha.20240710084543

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.
Files changed (107) hide show
  1. package/package.json +2 -2
  2. package/dist/client/AuthProvider.d.ts +0 -10
  3. package/dist/client/authenticator.d.ts +0 -21
  4. package/dist/client/basic/Options.d.ts +0 -10
  5. package/dist/client/basic/SignInForm.d.ts +0 -17
  6. package/dist/client/basic/SignUpForm.d.ts +0 -21
  7. package/dist/client/basic/index.d.ts +0 -11
  8. package/dist/client/index.d.ts +0 -35
  9. package/dist/client/index.js +0 -31
  10. package/dist/client/locale/index.d.ts +0 -10
  11. package/dist/client/pages/AuthLayout.d.ts +0 -13
  12. package/dist/client/pages/SignInPage.d.ts +0 -24
  13. package/dist/client/pages/SignUpPage.d.ts +0 -29
  14. package/dist/client/pages/index.d.ts +0 -11
  15. package/dist/client/settings/Authenticator.d.ts +0 -10
  16. package/dist/client/settings/Options.d.ts +0 -12
  17. package/dist/client/settings/authType.d.ts +0 -24
  18. package/dist/client/settings/schemas/authenticators.d.ts +0 -11
  19. package/dist/externalVersion.js +0 -27
  20. package/dist/index.d.ts +0 -9
  21. package/dist/index.js +0 -49
  22. package/dist/locale/en-US.json +0 -27
  23. package/dist/locale/ko_KR.json +0 -26
  24. package/dist/locale/zh-CN.json +0 -27
  25. package/dist/node_modules/cron/LICENSE +0 -8
  26. package/dist/node_modules/cron/lib/cron.js +0 -1
  27. package/dist/node_modules/cron/lib/job.js +0 -215
  28. package/dist/node_modules/cron/lib/time.js +0 -830
  29. package/dist/node_modules/cron/node_modules/luxon/build/amd/luxon.js +0 -7826
  30. package/dist/node_modules/cron/node_modules/luxon/build/cjs-browser/luxon.js +0 -7824
  31. package/dist/node_modules/cron/node_modules/luxon/build/es6/luxon.js +0 -7217
  32. package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.js +0 -7829
  33. package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.min.js +0 -1
  34. package/dist/node_modules/cron/node_modules/luxon/build/node/luxon.js +0 -6932
  35. package/dist/node_modules/cron/node_modules/luxon/package.json +0 -85
  36. package/dist/node_modules/cron/node_modules/luxon/src/datetime.js +0 -2248
  37. package/dist/node_modules/cron/node_modules/luxon/src/duration.js +0 -948
  38. package/dist/node_modules/cron/node_modules/luxon/src/errors.js +0 -61
  39. package/dist/node_modules/cron/node_modules/luxon/src/impl/conversions.js +0 -161
  40. package/dist/node_modules/cron/node_modules/luxon/src/impl/diff.js +0 -75
  41. package/dist/node_modules/cron/node_modules/luxon/src/impl/digits.js +0 -75
  42. package/dist/node_modules/cron/node_modules/luxon/src/impl/english.js +0 -233
  43. package/dist/node_modules/cron/node_modules/luxon/src/impl/formats.js +0 -176
  44. package/dist/node_modules/cron/node_modules/luxon/src/impl/formatter.js +0 -400
  45. package/dist/node_modules/cron/node_modules/luxon/src/impl/invalid.js +0 -14
  46. package/dist/node_modules/cron/node_modules/luxon/src/impl/locale.js +0 -494
  47. package/dist/node_modules/cron/node_modules/luxon/src/impl/regexParser.js +0 -335
  48. package/dist/node_modules/cron/node_modules/luxon/src/impl/tokenParser.js +0 -444
  49. package/dist/node_modules/cron/node_modules/luxon/src/impl/util.js +0 -274
  50. package/dist/node_modules/cron/node_modules/luxon/src/impl/zoneUtil.js +0 -34
  51. package/dist/node_modules/cron/node_modules/luxon/src/info.js +0 -169
  52. package/dist/node_modules/cron/node_modules/luxon/src/interval.js +0 -637
  53. package/dist/node_modules/cron/node_modules/luxon/src/luxon.js +0 -26
  54. package/dist/node_modules/cron/node_modules/luxon/src/package.json +0 -4
  55. package/dist/node_modules/cron/node_modules/luxon/src/settings.js +0 -148
  56. package/dist/node_modules/cron/node_modules/luxon/src/zone.js +0 -91
  57. package/dist/node_modules/cron/node_modules/luxon/src/zones/IANAZone.js +0 -189
  58. package/dist/node_modules/cron/node_modules/luxon/src/zones/fixedOffsetZone.js +0 -102
  59. package/dist/node_modules/cron/node_modules/luxon/src/zones/invalidZone.js +0 -53
  60. package/dist/node_modules/cron/node_modules/luxon/src/zones/systemZone.js +0 -61
  61. package/dist/node_modules/cron/package.json +0 -1
  62. package/dist/node_modules/cron/types/index.d.ts +0 -181
  63. package/dist/node_modules/cron/types/index.test-d.ts +0 -85
  64. package/dist/preset.d.ts +0 -11
  65. package/dist/preset.js +0 -43
  66. package/dist/server/actions/auth.d.ts +0 -16
  67. package/dist/server/actions/auth.js +0 -50
  68. package/dist/server/actions/authenticators.d.ts +0 -16
  69. package/dist/server/actions/authenticators.js +0 -112
  70. package/dist/server/basic-auth.d.ts +0 -18
  71. package/dist/server/basic-auth.js +0 -192
  72. package/dist/server/collections/authenticators.d.ts +0 -13
  73. package/dist/server/collections/authenticators.js +0 -126
  74. package/dist/server/collections/token-blacklist.d.ts +0 -10
  75. package/dist/server/collections/token-blacklist.js +0 -51
  76. package/dist/server/collections/users-authenticators.d.ts +0 -14
  77. package/dist/server/collections/users-authenticators.js +0 -94
  78. package/dist/server/index.d.ts +0 -11
  79. package/dist/server/index.js +0 -51
  80. package/dist/server/locale/en-US.d.ts +0 -17
  81. package/dist/server/locale/en-US.js +0 -39
  82. package/dist/server/locale/fr-FR.d.ts +0 -17
  83. package/dist/server/locale/fr-FR.js +0 -39
  84. package/dist/server/locale/index.d.ts +0 -11
  85. package/dist/server/locale/index.js +0 -52
  86. package/dist/server/locale/ja-JP.d.ts +0 -13
  87. package/dist/server/locale/ja-JP.js +0 -35
  88. package/dist/server/locale/pt-BR.d.ts +0 -17
  89. package/dist/server/locale/pt-BR.js +0 -39
  90. package/dist/server/locale/zh-CN.d.ts +0 -19
  91. package/dist/server/locale/zh-CN.js +0 -41
  92. package/dist/server/migrations/20230506152253-basic-authenticator.d.ts +0 -14
  93. package/dist/server/migrations/20230506152253-basic-authenticator.js +0 -53
  94. package/dist/server/migrations/20230607174500-update-basic.d.ts +0 -14
  95. package/dist/server/migrations/20230607174500-update-basic.js +0 -56
  96. package/dist/server/migrations/20231218132032-fix-allow-signup.d.ts +0 -14
  97. package/dist/server/migrations/20231218132032-fix-allow-signup.js +0 -64
  98. package/dist/server/model/authenticator.d.ts +0 -17
  99. package/dist/server/model/authenticator.js +0 -78
  100. package/dist/server/plugin.d.ts +0 -19
  101. package/dist/server/plugin.js +0 -138
  102. package/dist/server/storer.d.ts +0 -24
  103. package/dist/server/storer.js +0 -78
  104. package/dist/server/token-blacklist.d.ts +0 -25
  105. package/dist/server/token-blacklist.js +0 -95
  106. package/dist/swagger/index.d.ts +0 -762
  107. package/dist/swagger/index.js +0 -796
@@ -1,138 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var plugin_exports = {};
38
- __export(plugin_exports, {
39
- PluginAuthServer: () => PluginAuthServer,
40
- default: () => plugin_default
41
- });
42
- module.exports = __toCommonJS(plugin_exports);
43
- var import_server = require("@nocobase/server");
44
- var import_path = require("path");
45
- var import_preset = require("../preset");
46
- var import_auth = __toESM(require("./actions/auth"));
47
- var import_authenticators = __toESM(require("./actions/authenticators"));
48
- var import_basic_auth = require("./basic-auth");
49
- var import_authenticator = require("./model/authenticator");
50
- var import_storer = require("./storer");
51
- var import_token_blacklist = require("./token-blacklist");
52
- var import_utils = require("@nocobase/utils");
53
- class PluginAuthServer extends import_server.Plugin {
54
- cache;
55
- afterAdd() {
56
- }
57
- async beforeLoad() {
58
- this.app.db.registerModels({ AuthModel: import_authenticator.AuthModel });
59
- }
60
- async load() {
61
- await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
62
- this.db.addMigrations({
63
- namespace: "auth",
64
- directory: (0, import_path.resolve)(__dirname, "migrations"),
65
- context: {
66
- plugin: this
67
- }
68
- });
69
- this.cache = await this.app.cacheManager.createCache({
70
- name: "auth",
71
- prefix: "auth",
72
- store: "memory"
73
- });
74
- const storer = new import_storer.Storer({
75
- db: this.db,
76
- cache: this.cache
77
- });
78
- this.app.authManager.setStorer(storer);
79
- if (!this.app.authManager.jwt.blacklist) {
80
- this.app.authManager.setTokenBlacklistService(new import_token_blacklist.TokenBlacklistService(this));
81
- }
82
- this.app.authManager.registerTypes(import_preset.presetAuthType, {
83
- auth: import_basic_auth.BasicAuth,
84
- title: (0, import_utils.tval)("Password", { ns: import_preset.namespace })
85
- });
86
- Object.entries(import_auth.default).forEach(
87
- ([action, handler]) => {
88
- var _a;
89
- return (_a = this.app.resourcer.getResource("auth")) == null ? void 0 : _a.addAction(action, handler);
90
- }
91
- );
92
- Object.entries(import_authenticators.default).forEach(
93
- ([action, handler]) => this.app.resourcer.registerAction(`authenticators:${action}`, handler)
94
- );
95
- ["check", "signIn", "signUp"].forEach((action) => this.app.acl.allow("auth", action));
96
- ["signOut", "changePassword"].forEach((action) => this.app.acl.allow("auth", action, "loggedIn"));
97
- this.app.acl.allow("authenticators", "publicList");
98
- this.app.acl.registerSnippet({
99
- name: `pm.${this.name}.authenticators`,
100
- actions: ["authenticators:*"]
101
- });
102
- this.app.db.on("users.afterSave", async (user) => {
103
- const cache = this.app.cache;
104
- await cache.set(`auth:${user.id}`, user.toJSON());
105
- });
106
- this.app.db.on("users.afterDestroy", async (user) => {
107
- const cache = this.app.cache;
108
- await cache.del(`auth:${user.id}`);
109
- });
110
- }
111
- async install(options) {
112
- const repository = this.db.getRepository("authenticators");
113
- const exist = await repository.findOne({ filter: { name: import_preset.presetAuthenticator } });
114
- if (exist) {
115
- return;
116
- }
117
- await repository.create({
118
- values: {
119
- name: import_preset.presetAuthenticator,
120
- authType: import_preset.presetAuthType,
121
- description: "Sign in with username/email.",
122
- enabled: true,
123
- options: {
124
- public: {
125
- allowSignUp: true
126
- }
127
- }
128
- }
129
- });
130
- }
131
- async remove() {
132
- }
133
- }
134
- var plugin_default = PluginAuthServer;
135
- // Annotate the CommonJS export names for ESM import in node:
136
- 0 && (module.exports = {
137
- PluginAuthServer
138
- });
@@ -1,24 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Storer as IStorer } from '@nocobase/auth';
10
- import { Cache } from '@nocobase/cache';
11
- import { Database } from '@nocobase/database';
12
- import { AuthModel } from './model/authenticator';
13
- export declare class Storer implements IStorer {
14
- db: Database;
15
- cache: Cache;
16
- key: string;
17
- constructor({ db, cache }: {
18
- db: Database;
19
- cache: Cache;
20
- });
21
- getCache(): Promise<AuthModel[]>;
22
- setCache(authenticators: AuthModel[]): Promise<void>;
23
- get(name: string): Promise<AuthModel>;
24
- }
@@ -1,78 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var storer_exports = {};
28
- __export(storer_exports, {
29
- Storer: () => Storer
30
- });
31
- module.exports = __toCommonJS(storer_exports);
32
- class Storer {
33
- db;
34
- cache;
35
- key = "authenticators";
36
- constructor({ db, cache }) {
37
- this.db = db;
38
- this.cache = cache;
39
- this.db.on("authenticators.afterSave", async (model) => {
40
- if (!model.enabled) {
41
- await this.cache.delValueInObject(this.key, model.name);
42
- return;
43
- }
44
- await this.cache.setValueInObject(this.key, model.name, model);
45
- });
46
- this.db.on("authenticators.afterDestroy", async (model) => {
47
- await this.cache.delValueInObject(this.key, model.name);
48
- });
49
- }
50
- async getCache() {
51
- const authenticators = await this.cache.get(this.key);
52
- if (!authenticators) {
53
- return [];
54
- }
55
- return Object.values(authenticators);
56
- }
57
- async setCache(authenticators) {
58
- const obj = authenticators.reduce((obj2, authenticator) => {
59
- obj2[authenticator.name] = authenticator;
60
- return obj2;
61
- }, {});
62
- await this.cache.set(this.key, obj);
63
- }
64
- async get(name) {
65
- let authenticators = await this.getCache();
66
- if (!authenticators.length) {
67
- const repo = this.db.getRepository("authenticators");
68
- authenticators = await repo.find({ filter: { enabled: true } });
69
- await this.setCache(authenticators);
70
- }
71
- const authenticator = authenticators.find((authenticator2) => authenticator2.name === name);
72
- return authenticator || authenticators[0];
73
- }
74
- }
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- Storer
78
- });
@@ -1,25 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { ITokenBlacklistService } from '@nocobase/auth';
10
- import { Repository } from '@nocobase/database';
11
- import { CronJob } from 'cron';
12
- import AuthPlugin from './plugin';
13
- import { BloomFilter } from '@nocobase/cache';
14
- export declare class TokenBlacklistService implements ITokenBlacklistService {
15
- protected plugin: AuthPlugin;
16
- repo: Repository;
17
- cronJob: CronJob;
18
- bloomFilter: BloomFilter;
19
- cacheKey: string;
20
- constructor(plugin: AuthPlugin);
21
- get app(): import("@nocobase/server").default<import("@nocobase/server").DefaultState, import("@nocobase/server").DefaultContext>;
22
- has(token: string): Promise<boolean>;
23
- add(values: any): Promise<[import("@nocobase/database").Model<any, any>, boolean]>;
24
- deleteExpiredTokens(): Promise<any>;
25
- }
@@ -1,95 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var token_blacklist_exports = {};
28
- __export(token_blacklist_exports, {
29
- TokenBlacklistService: () => TokenBlacklistService
30
- });
31
- module.exports = __toCommonJS(token_blacklist_exports);
32
- class TokenBlacklistService {
33
- constructor(plugin) {
34
- this.plugin = plugin;
35
- this.repo = plugin.db.getRepository("tokenBlacklist");
36
- plugin.app.on("beforeStart", async () => {
37
- try {
38
- this.bloomFilter = await plugin.app.cacheManager.createBloomFilter();
39
- await this.bloomFilter.reserve(this.cacheKey, 1e-3, 1e6);
40
- const data = await this.repo.find({ fields: ["token"], raw: true });
41
- const tokens = data.map((item) => item.token);
42
- await this.bloomFilter.mAdd(this.cacheKey, tokens);
43
- } catch (error) {
44
- plugin.app.logger.error("token-blacklist: create bloom filter failed", error);
45
- this.bloomFilter = null;
46
- }
47
- });
48
- }
49
- repo;
50
- cronJob;
51
- bloomFilter;
52
- cacheKey = "token-black-list";
53
- get app() {
54
- return this.plugin.app;
55
- }
56
- async has(token) {
57
- if (this.bloomFilter) {
58
- const exists = await this.bloomFilter.exists(this.cacheKey, token);
59
- if (!exists) {
60
- return false;
61
- }
62
- }
63
- return !!await this.repo.findOne({
64
- filter: {
65
- token
66
- }
67
- });
68
- }
69
- async add(values) {
70
- await this.deleteExpiredTokens();
71
- const { token } = values;
72
- if (this.bloomFilter) {
73
- await this.bloomFilter.add(this.cacheKey, token);
74
- }
75
- return this.repo.model.findOrCreate({
76
- defaults: values,
77
- where: {
78
- token
79
- }
80
- });
81
- }
82
- async deleteExpiredTokens() {
83
- return this.repo.destroy({
84
- filter: {
85
- expiration: {
86
- $dateNotAfter: /* @__PURE__ */ new Date()
87
- }
88
- }
89
- });
90
- }
91
- }
92
- // Annotate the CommonJS export names for ESM import in node:
93
- 0 && (module.exports = {
94
- TokenBlacklistService
95
- });