@nocobase/plugin-auth 0.11.1-alpha.4 → 0.12.0-alpha.1
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/client.d.ts +2 -2
- package/client.js +1 -1
- package/dist/client/index.js +729 -0
- package/dist/index.js +20 -0
- package/dist/locale/zh-CN.js +20 -0
- package/dist/node_modules/cron/LICENSE +8 -0
- package/dist/node_modules/cron/lib/cron.js +1 -0
- package/dist/node_modules/cron/lib/job.js +215 -0
- package/dist/node_modules/cron/lib/time.js +817 -0
- package/dist/node_modules/cron/package.json +1 -0
- package/{lib → dist}/preset.d.ts +1 -1
- package/dist/preset.js +11 -0
- package/dist/server/actions/auth.js +22 -0
- package/dist/server/actions/authenticators.js +83 -0
- package/{src/server/basic-auth.ts → dist/server/basic-auth.js} +41 -42
- package/dist/server/collections/authenticators.js +97 -0
- package/dist/server/collections/token-blacklist.js +21 -0
- package/dist/server/collections/users-authenticators.js +71 -0
- package/dist/server/index.js +21 -0
- package/dist/server/locale/en-US.js +12 -0
- package/dist/server/locale/fr-FR.js +12 -0
- package/dist/server/locale/index.js +26 -0
- package/dist/server/locale/ja-JP.js +8 -0
- package/dist/server/locale/pt-BR.js +12 -0
- package/dist/server/locale/zh-CN.js +13 -0
- package/dist/server/migrations/20230506152253-basic-authenticator.js +26 -0
- package/dist/server/migrations/20230607174500-update-basic.js +29 -0
- package/{src/server/model/authenticator.ts → dist/server/model/authenticator.js} +19 -19
- package/dist/server/plugin.js +93 -0
- package/dist/server/token-blacklist.js +62 -0
- package/package.json +17 -28
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/lib/client/AuthProvider.js +0 -56
- package/lib/client/basic/Options.js +0 -51
- package/lib/client/basic/SigninPage.js +0 -100
- package/lib/client/basic/SignupPage.js +0 -131
- package/lib/client/index.js +0 -27
- package/lib/client/locale/index.js +0 -19
- package/lib/client/settings/Authenticator.js +0 -159
- package/lib/client/settings/Options.js +0 -56
- package/lib/client/settings/authType.js +0 -27
- package/lib/client/settings/schemas/authenticators.js +0 -438
- package/lib/index.js +0 -20
- package/lib/locale/zh-CN.js +0 -23
- package/lib/preset.js +0 -12
- package/lib/server/actions/auth.js +0 -51
- package/lib/server/actions/authenticators.js +0 -131
- package/lib/server/basic-auth.js +0 -183
- package/lib/server/collections/authenticators.js +0 -94
- package/lib/server/collections/token-blacklist.js +0 -21
- package/lib/server/collections/users-authenticators.js +0 -75
- package/lib/server/index.js +0 -20
- package/lib/server/locale/en-US.js +0 -15
- package/lib/server/locale/fr-FR.js +0 -15
- package/lib/server/locale/index.js +0 -27
- package/lib/server/locale/ja-JP.js +0 -11
- package/lib/server/locale/pt-BR.js +0 -15
- package/lib/server/locale/zh-CN.js +0 -16
- package/lib/server/migrations/20230506152253-basic-authenticator.js +0 -40
- package/lib/server/migrations/20230607174500-update-basic.js +0 -43
- package/lib/server/model/authenticator.js +0 -72
- package/lib/server/plugin.js +0 -129
- package/lib/server/token-blacklist.js +0 -82
- package/src/client/AuthProvider.tsx +0 -41
- package/src/client/basic/Options.tsx +0 -31
- package/src/client/basic/SigninPage.tsx +0 -65
- package/src/client/basic/SignupPage.tsx +0 -91
- package/src/client/index.tsx +0 -10
- package/src/client/locale/index.ts +0 -7
- package/src/client/settings/Authenticator.tsx +0 -95
- package/src/client/settings/Options.tsx +0 -34
- package/src/client/settings/authType.ts +0 -18
- package/src/client/settings/schemas/authenticators.ts +0 -402
- package/src/index.ts +0 -1
- package/src/locale/zh-CN.ts +0 -17
- package/src/preset.ts +0 -4
- package/src/server/__tests__/actions.test.ts +0 -142
- package/src/server/__tests__/token-blacklist.test.ts +0 -73
- package/src/server/actions/auth.ts +0 -20
- package/src/server/actions/authenticators.ts +0 -85
- package/src/server/collections/.gitkeep +0 -0
- package/src/server/collections/authenticators.ts +0 -98
- package/src/server/collections/token-blacklist.ts +0 -19
- package/src/server/collections/users-authenticators.ts +0 -73
- package/src/server/index.ts +0 -2
- package/src/server/locale/en-US.ts +0 -10
- package/src/server/locale/fr-FR.ts +0 -10
- package/src/server/locale/index.ts +0 -3
- package/src/server/locale/ja-JP.ts +0 -4
- package/src/server/locale/pt-BR.ts +0 -10
- package/src/server/locale/zh-CN.ts +0 -9
- package/src/server/migrations/20230506152253-basic-authenticator.ts +0 -22
- package/src/server/migrations/20230607174500-update-basic.ts +0 -25
- package/src/server/plugin.ts +0 -92
- package/src/server/token-blacklist.ts +0 -66
- /package/{lib → dist}/client/AuthProvider.d.ts +0 -0
- /package/{lib → dist}/client/basic/Options.d.ts +0 -0
- /package/{lib → dist}/client/basic/SigninPage.d.ts +0 -0
- /package/{lib → dist}/client/basic/SignupPage.d.ts +0 -0
- /package/{lib → dist}/client/index.d.ts +0 -0
- /package/{lib → dist}/client/locale/index.d.ts +0 -0
- /package/{lib → dist}/client/settings/Authenticator.d.ts +0 -0
- /package/{lib → dist}/client/settings/Options.d.ts +0 -0
- /package/{lib → dist}/client/settings/authType.d.ts +0 -0
- /package/{lib → dist}/client/settings/schemas/authenticators.d.ts +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/actions/auth.d.ts +0 -0
- /package/{lib → dist}/server/actions/authenticators.d.ts +0 -0
- /package/{lib → dist}/server/basic-auth.d.ts +0 -0
- /package/{lib → dist}/server/collections/authenticators.d.ts +0 -0
- /package/{lib → dist}/server/collections/token-blacklist.d.ts +0 -0
- /package/{lib → dist}/server/collections/users-authenticators.d.ts +0 -0
- /package/{lib → dist}/server/index.d.ts +0 -0
- /package/{lib → dist}/server/locale/en-US.d.ts +0 -0
- /package/{lib → dist}/server/locale/fr-FR.d.ts +0 -0
- /package/{lib → dist}/server/locale/index.d.ts +0 -0
- /package/{lib → dist}/server/locale/ja-JP.d.ts +0 -0
- /package/{lib → dist}/server/locale/pt-BR.d.ts +0 -0
- /package/{lib → dist}/server/locale/zh-CN.d.ts +0 -0
- /package/{lib → dist}/server/migrations/20230506152253-basic-authenticator.d.ts +0 -0
- /package/{lib → dist}/server/migrations/20230607174500-update-basic.d.ts +0 -0
- /package/{lib → dist}/server/model/authenticator.d.ts +0 -0
- /package/{lib → dist}/server/plugin.d.ts +0 -0
- /package/{lib → dist}/server/token-blacklist.d.ts +0 -0
package/src/server/plugin.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { Model } from '@nocobase/database';
|
|
2
|
-
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
3
|
-
import { resolve } from 'path';
|
|
4
|
-
import { namespace, presetAuthenticator, presetAuthType } from '../preset';
|
|
5
|
-
import authActions from './actions/auth';
|
|
6
|
-
import authenticatorsActions from './actions/authenticators';
|
|
7
|
-
import { BasicAuth } from './basic-auth';
|
|
8
|
-
import { enUS, zhCN } from './locale';
|
|
9
|
-
import { AuthModel } from './model/authenticator';
|
|
10
|
-
import { TokenBlacklistService } from './token-blacklist';
|
|
11
|
-
|
|
12
|
-
export class AuthPlugin extends Plugin {
|
|
13
|
-
afterAdd() {}
|
|
14
|
-
async beforeLoad() {
|
|
15
|
-
this.app.i18n.addResources('zh-CN', namespace, zhCN);
|
|
16
|
-
this.app.i18n.addResources('en-US', namespace, enUS);
|
|
17
|
-
|
|
18
|
-
this.app.db.registerModels({ AuthModel });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async load() {
|
|
22
|
-
// Set up database
|
|
23
|
-
await this.db.import({
|
|
24
|
-
directory: resolve(__dirname, 'collections'),
|
|
25
|
-
});
|
|
26
|
-
this.db.addMigrations({
|
|
27
|
-
namespace: 'auth',
|
|
28
|
-
directory: resolve(__dirname, 'migrations'),
|
|
29
|
-
context: {
|
|
30
|
-
plugin: this,
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
// Set up auth manager and register preset auth type
|
|
34
|
-
this.app.authManager.setStorer({
|
|
35
|
-
get: async (name: string) => {
|
|
36
|
-
const repo = this.db.getRepository('authenticators');
|
|
37
|
-
const authenticators = await repo.find({ filter: { enabled: true } });
|
|
38
|
-
const authenticator = authenticators.find((authenticator: Model) => authenticator.name === name);
|
|
39
|
-
return authenticator || authenticators[0];
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (!this.app.authManager.jwt.blacklist) {
|
|
44
|
-
// If blacklist service is not set, should configure default blacklist service
|
|
45
|
-
this.app.authManager.setTokenBlacklistService(new TokenBlacklistService(this));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
this.app.authManager.registerTypes(presetAuthType, {
|
|
49
|
-
auth: BasicAuth,
|
|
50
|
-
});
|
|
51
|
-
// Register actions
|
|
52
|
-
Object.entries(authActions).forEach(([action, handler]) =>
|
|
53
|
-
this.app.resourcer.registerAction(`auth:${action}`, handler),
|
|
54
|
-
);
|
|
55
|
-
Object.entries(authenticatorsActions).forEach(([action, handler]) =>
|
|
56
|
-
this.app.resourcer.registerAction(`authenticators:${action}`, handler),
|
|
57
|
-
);
|
|
58
|
-
// Set up ACL
|
|
59
|
-
['check', 'signIn', 'signUp'].forEach((action) => this.app.acl.allow('auth', action));
|
|
60
|
-
['signOut', 'changePassword'].forEach((action) => this.app.acl.allow('auth', action, 'loggedIn'));
|
|
61
|
-
this.app.acl.allow('authenticators', 'publicList');
|
|
62
|
-
this.app.acl.registerSnippet({
|
|
63
|
-
name: `pm.${this.name}.authenticators`,
|
|
64
|
-
actions: ['authenticators:*'],
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async install(options?: InstallOptions) {
|
|
69
|
-
const repository = this.db.getRepository('authenticators');
|
|
70
|
-
const exist = await repository.findOne({ filter: { name: presetAuthenticator } });
|
|
71
|
-
if (exist) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
await repository.create({
|
|
76
|
-
values: {
|
|
77
|
-
name: presetAuthenticator,
|
|
78
|
-
authType: presetAuthType,
|
|
79
|
-
description: 'Sign in with email and password.',
|
|
80
|
-
enabled: true,
|
|
81
|
-
options: {
|
|
82
|
-
public: {
|
|
83
|
-
allowSignUp: true,
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
async remove() {}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export default AuthPlugin;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ITokenBlacklistService } from '@nocobase/auth';
|
|
2
|
-
import { Repository } from '@nocobase/database';
|
|
3
|
-
import { CronJob } from 'cron';
|
|
4
|
-
import AuthPlugin from './plugin';
|
|
5
|
-
|
|
6
|
-
export class TokenBlacklistService implements ITokenBlacklistService {
|
|
7
|
-
repo: Repository;
|
|
8
|
-
cronJob: CronJob;
|
|
9
|
-
|
|
10
|
-
constructor(protected plugin: AuthPlugin) {
|
|
11
|
-
this.repo = plugin.db.getRepository('tokenBlacklist');
|
|
12
|
-
this.cronJob = this.createCronJob();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get app() {
|
|
16
|
-
return this.plugin.app;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
createCronJob() {
|
|
20
|
-
const cronJob = new CronJob(
|
|
21
|
-
// every day at 03:00
|
|
22
|
-
'0 3 * * *', //
|
|
23
|
-
async () => {
|
|
24
|
-
this.app.logger.info(`${this.plugin.name}: Start delete expired blacklist token`);
|
|
25
|
-
await this.deleteByExpiration();
|
|
26
|
-
this.app.logger.info(`${this.plugin.name}: End delete expired blacklist token`);
|
|
27
|
-
},
|
|
28
|
-
null,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
this.app.once('beforeStart', () => {
|
|
32
|
-
cronJob.start();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
this.app.once('beforeStop', () => {
|
|
36
|
-
cronJob.stop();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return cronJob;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async has(token: string) {
|
|
43
|
-
return !!(await this.repo.findOne({
|
|
44
|
-
filter: {
|
|
45
|
-
token,
|
|
46
|
-
},
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
async add(values) {
|
|
50
|
-
return this.repo.model.findOrCreate({
|
|
51
|
-
defaults: values,
|
|
52
|
-
where: {
|
|
53
|
-
token: values.token,
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
async deleteByExpiration() {
|
|
58
|
-
return this.repo.destroy({
|
|
59
|
-
filter: {
|
|
60
|
-
expiration: {
|
|
61
|
-
$dateNotAfter: new Date(),
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{lib → dist}/index.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|