@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.
Files changed (126) hide show
  1. package/client.d.ts +2 -2
  2. package/client.js +1 -1
  3. package/dist/client/index.js +729 -0
  4. package/dist/index.js +20 -0
  5. package/dist/locale/zh-CN.js +20 -0
  6. package/dist/node_modules/cron/LICENSE +8 -0
  7. package/dist/node_modules/cron/lib/cron.js +1 -0
  8. package/dist/node_modules/cron/lib/job.js +215 -0
  9. package/dist/node_modules/cron/lib/time.js +817 -0
  10. package/dist/node_modules/cron/package.json +1 -0
  11. package/{lib → dist}/preset.d.ts +1 -1
  12. package/dist/preset.js +11 -0
  13. package/dist/server/actions/auth.js +22 -0
  14. package/dist/server/actions/authenticators.js +83 -0
  15. package/{src/server/basic-auth.ts → dist/server/basic-auth.js} +41 -42
  16. package/dist/server/collections/authenticators.js +97 -0
  17. package/dist/server/collections/token-blacklist.js +21 -0
  18. package/dist/server/collections/users-authenticators.js +71 -0
  19. package/dist/server/index.js +21 -0
  20. package/dist/server/locale/en-US.js +12 -0
  21. package/dist/server/locale/fr-FR.js +12 -0
  22. package/dist/server/locale/index.js +26 -0
  23. package/dist/server/locale/ja-JP.js +8 -0
  24. package/dist/server/locale/pt-BR.js +12 -0
  25. package/dist/server/locale/zh-CN.js +13 -0
  26. package/dist/server/migrations/20230506152253-basic-authenticator.js +26 -0
  27. package/dist/server/migrations/20230607174500-update-basic.js +29 -0
  28. package/{src/server/model/authenticator.ts → dist/server/model/authenticator.js} +19 -19
  29. package/dist/server/plugin.js +93 -0
  30. package/dist/server/token-blacklist.js +62 -0
  31. package/package.json +17 -28
  32. package/server.d.ts +2 -2
  33. package/server.js +1 -1
  34. package/lib/client/AuthProvider.js +0 -56
  35. package/lib/client/basic/Options.js +0 -51
  36. package/lib/client/basic/SigninPage.js +0 -100
  37. package/lib/client/basic/SignupPage.js +0 -131
  38. package/lib/client/index.js +0 -27
  39. package/lib/client/locale/index.js +0 -19
  40. package/lib/client/settings/Authenticator.js +0 -159
  41. package/lib/client/settings/Options.js +0 -56
  42. package/lib/client/settings/authType.js +0 -27
  43. package/lib/client/settings/schemas/authenticators.js +0 -438
  44. package/lib/index.js +0 -20
  45. package/lib/locale/zh-CN.js +0 -23
  46. package/lib/preset.js +0 -12
  47. package/lib/server/actions/auth.js +0 -51
  48. package/lib/server/actions/authenticators.js +0 -131
  49. package/lib/server/basic-auth.js +0 -183
  50. package/lib/server/collections/authenticators.js +0 -94
  51. package/lib/server/collections/token-blacklist.js +0 -21
  52. package/lib/server/collections/users-authenticators.js +0 -75
  53. package/lib/server/index.js +0 -20
  54. package/lib/server/locale/en-US.js +0 -15
  55. package/lib/server/locale/fr-FR.js +0 -15
  56. package/lib/server/locale/index.js +0 -27
  57. package/lib/server/locale/ja-JP.js +0 -11
  58. package/lib/server/locale/pt-BR.js +0 -15
  59. package/lib/server/locale/zh-CN.js +0 -16
  60. package/lib/server/migrations/20230506152253-basic-authenticator.js +0 -40
  61. package/lib/server/migrations/20230607174500-update-basic.js +0 -43
  62. package/lib/server/model/authenticator.js +0 -72
  63. package/lib/server/plugin.js +0 -129
  64. package/lib/server/token-blacklist.js +0 -82
  65. package/src/client/AuthProvider.tsx +0 -41
  66. package/src/client/basic/Options.tsx +0 -31
  67. package/src/client/basic/SigninPage.tsx +0 -65
  68. package/src/client/basic/SignupPage.tsx +0 -91
  69. package/src/client/index.tsx +0 -10
  70. package/src/client/locale/index.ts +0 -7
  71. package/src/client/settings/Authenticator.tsx +0 -95
  72. package/src/client/settings/Options.tsx +0 -34
  73. package/src/client/settings/authType.ts +0 -18
  74. package/src/client/settings/schemas/authenticators.ts +0 -402
  75. package/src/index.ts +0 -1
  76. package/src/locale/zh-CN.ts +0 -17
  77. package/src/preset.ts +0 -4
  78. package/src/server/__tests__/actions.test.ts +0 -142
  79. package/src/server/__tests__/token-blacklist.test.ts +0 -73
  80. package/src/server/actions/auth.ts +0 -20
  81. package/src/server/actions/authenticators.ts +0 -85
  82. package/src/server/collections/.gitkeep +0 -0
  83. package/src/server/collections/authenticators.ts +0 -98
  84. package/src/server/collections/token-blacklist.ts +0 -19
  85. package/src/server/collections/users-authenticators.ts +0 -73
  86. package/src/server/index.ts +0 -2
  87. package/src/server/locale/en-US.ts +0 -10
  88. package/src/server/locale/fr-FR.ts +0 -10
  89. package/src/server/locale/index.ts +0 -3
  90. package/src/server/locale/ja-JP.ts +0 -4
  91. package/src/server/locale/pt-BR.ts +0 -10
  92. package/src/server/locale/zh-CN.ts +0 -9
  93. package/src/server/migrations/20230506152253-basic-authenticator.ts +0 -22
  94. package/src/server/migrations/20230607174500-update-basic.ts +0 -25
  95. package/src/server/plugin.ts +0 -92
  96. package/src/server/token-blacklist.ts +0 -66
  97. /package/{lib → dist}/client/AuthProvider.d.ts +0 -0
  98. /package/{lib → dist}/client/basic/Options.d.ts +0 -0
  99. /package/{lib → dist}/client/basic/SigninPage.d.ts +0 -0
  100. /package/{lib → dist}/client/basic/SignupPage.d.ts +0 -0
  101. /package/{lib → dist}/client/index.d.ts +0 -0
  102. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  103. /package/{lib → dist}/client/settings/Authenticator.d.ts +0 -0
  104. /package/{lib → dist}/client/settings/Options.d.ts +0 -0
  105. /package/{lib → dist}/client/settings/authType.d.ts +0 -0
  106. /package/{lib → dist}/client/settings/schemas/authenticators.d.ts +0 -0
  107. /package/{lib → dist}/index.d.ts +0 -0
  108. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  109. /package/{lib → dist}/server/actions/auth.d.ts +0 -0
  110. /package/{lib → dist}/server/actions/authenticators.d.ts +0 -0
  111. /package/{lib → dist}/server/basic-auth.d.ts +0 -0
  112. /package/{lib → dist}/server/collections/authenticators.d.ts +0 -0
  113. /package/{lib → dist}/server/collections/token-blacklist.d.ts +0 -0
  114. /package/{lib → dist}/server/collections/users-authenticators.d.ts +0 -0
  115. /package/{lib → dist}/server/index.d.ts +0 -0
  116. /package/{lib → dist}/server/locale/en-US.d.ts +0 -0
  117. /package/{lib → dist}/server/locale/fr-FR.d.ts +0 -0
  118. /package/{lib → dist}/server/locale/index.d.ts +0 -0
  119. /package/{lib → dist}/server/locale/ja-JP.d.ts +0 -0
  120. /package/{lib → dist}/server/locale/pt-BR.d.ts +0 -0
  121. /package/{lib → dist}/server/locale/zh-CN.d.ts +0 -0
  122. /package/{lib → dist}/server/migrations/20230506152253-basic-authenticator.d.ts +0 -0
  123. /package/{lib → dist}/server/migrations/20230607174500-update-basic.d.ts +0 -0
  124. /package/{lib → dist}/server/model/authenticator.d.ts +0 -0
  125. /package/{lib → dist}/server/plugin.d.ts +0 -0
  126. /package/{lib → dist}/server/token-blacklist.d.ts +0 -0
@@ -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
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