@nocobase/plugin-auth-sms 1.0.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/LICENSE +661 -0
- package/README.md +23 -0
- package/client.d.ts +2 -0
- package/client.js +65 -0
- package/dist/client/Options.d.ts +2 -0
- package/dist/client/SigninPage.d.ts +5 -0
- package/dist/client/VerificationCode.d.ts +7 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +4 -0
- package/dist/client/locale/index.d.ts +2 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +31 -0
- package/dist/externalVersion.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +5 -0
- package/dist/locale/ko_KR.json +5 -0
- package/dist/locale/zh-CN.json +5 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/locale/en-US.d.ts +9 -0
- package/dist/server/locale/en-US.js +30 -0
- package/dist/server/locale/fr-FR.d.ts +9 -0
- package/dist/server/locale/fr-FR.js +30 -0
- package/dist/server/locale/index.d.ts +3 -0
- package/dist/server/locale/index.js +43 -0
- package/dist/server/locale/ja-JP.d.ts +5 -0
- package/dist/server/locale/ja-JP.js +26 -0
- package/dist/server/locale/pt-BR.d.ts +9 -0
- package/dist/server/locale/pt-BR.js +30 -0
- package/dist/server/locale/zh-CN.d.ts +10 -0
- package/dist/server/locale/zh-CN.js +31 -0
- package/dist/server/migrations/20230607180000-sms-authenticator.d.ts +6 -0
- package/dist/server/migrations/20230607180000-sms-authenticator.js +54 -0
- package/dist/server/migrations/20240425230310-change-locale-module.d.ts +6 -0
- package/dist/server/migrations/20240425230310-change-locale-module.js +42 -0
- package/dist/server/plugin.d.ts +10 -0
- package/dist/server/plugin.js +66 -0
- package/dist/server/sms-auth.d.ts +6 -0
- package/dist/server/sms-auth.js +81 -0
- package/package.json +32 -0
- package/server.d.ts +2 -0
- package/server.js +65 -0
|
@@ -0,0 +1,42 @@
|
|
|
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 change_locale_module_exports = {};
|
|
19
|
+
__export(change_locale_module_exports, {
|
|
20
|
+
default: () => change_locale_module_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(change_locale_module_exports);
|
|
23
|
+
var import_server = require("@nocobase/server");
|
|
24
|
+
class change_locale_module_default extends import_server.Migration {
|
|
25
|
+
on = "afterLoad";
|
|
26
|
+
// 'beforeLoad' or 'afterLoad'
|
|
27
|
+
appVersion = "<1.0.0-alpha.1";
|
|
28
|
+
async up() {
|
|
29
|
+
const repo = this.db.getRepository("localizationTexts");
|
|
30
|
+
if (!repo) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
await repo.update({
|
|
34
|
+
filter: {
|
|
35
|
+
module: "resources.sms-auth"
|
|
36
|
+
},
|
|
37
|
+
values: {
|
|
38
|
+
module: "resources.auth-sms"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
2
|
+
export declare class PluginAuthSMSServer extends Plugin {
|
|
3
|
+
afterAdd(): void;
|
|
4
|
+
load(): Promise<void>;
|
|
5
|
+
install(options?: InstallOptions): Promise<void>;
|
|
6
|
+
afterEnable(): Promise<void>;
|
|
7
|
+
afterDisable(): Promise<void>;
|
|
8
|
+
remove(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export default PluginAuthSMSServer;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 plugin_exports = {};
|
|
19
|
+
__export(plugin_exports, {
|
|
20
|
+
PluginAuthSMSServer: () => PluginAuthSMSServer,
|
|
21
|
+
default: () => plugin_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
24
|
+
var import_server = require("@nocobase/server");
|
|
25
|
+
var import_constants = require("../constants");
|
|
26
|
+
var import_sms_auth = require("./sms-auth");
|
|
27
|
+
class PluginAuthSMSServer extends import_server.Plugin {
|
|
28
|
+
afterAdd() {
|
|
29
|
+
}
|
|
30
|
+
async load() {
|
|
31
|
+
const verificationPlugin = this.app.getPlugin("verification");
|
|
32
|
+
if (!verificationPlugin) {
|
|
33
|
+
this.app.logger.warn("auth-sms: @nocobase/plugin-verification is required");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
verificationPlugin.interceptors.register("auth:signIn", {
|
|
37
|
+
manual: true,
|
|
38
|
+
getReceiver: (ctx) => {
|
|
39
|
+
return ctx.action.params.values.phone;
|
|
40
|
+
},
|
|
41
|
+
expiresIn: 120,
|
|
42
|
+
validate: async (ctx, phone) => {
|
|
43
|
+
if (!phone) {
|
|
44
|
+
throw new Error(ctx.t("Not a valid cellphone number, please re-enter"));
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
this.app.authManager.registerTypes(import_constants.authType, {
|
|
50
|
+
auth: import_sms_auth.SMSAuth
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async install(options) {
|
|
54
|
+
}
|
|
55
|
+
async afterEnable() {
|
|
56
|
+
}
|
|
57
|
+
async afterDisable() {
|
|
58
|
+
}
|
|
59
|
+
async remove() {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
var plugin_default = PluginAuthSMSServer;
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
PluginAuthSMSServer
|
|
66
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
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 sms_auth_exports = {};
|
|
19
|
+
__export(sms_auth_exports, {
|
|
20
|
+
SMSAuth: () => SMSAuth
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(sms_auth_exports);
|
|
23
|
+
var import_auth = require("@nocobase/auth");
|
|
24
|
+
var import_constants = require("../constants");
|
|
25
|
+
class SMSAuth extends import_auth.BaseAuth {
|
|
26
|
+
constructor(config) {
|
|
27
|
+
const { ctx } = config;
|
|
28
|
+
super({
|
|
29
|
+
...config,
|
|
30
|
+
userCollection: ctx.db.getCollection("users")
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async validate() {
|
|
34
|
+
const ctx = this.ctx;
|
|
35
|
+
const verificationPlugin = ctx.app.getPlugin("verification");
|
|
36
|
+
if (!verificationPlugin) {
|
|
37
|
+
throw new Error("auth-sms: @nocobase/plugin-verification is required");
|
|
38
|
+
}
|
|
39
|
+
let user;
|
|
40
|
+
await verificationPlugin.intercept(ctx, async () => {
|
|
41
|
+
var _a;
|
|
42
|
+
const {
|
|
43
|
+
values: { phone }
|
|
44
|
+
} = ctx.action.params;
|
|
45
|
+
try {
|
|
46
|
+
user = await this.userRepository.findOne({
|
|
47
|
+
filter: { phone }
|
|
48
|
+
});
|
|
49
|
+
if (user) {
|
|
50
|
+
await this.authenticator.addUser(user, {
|
|
51
|
+
through: {
|
|
52
|
+
uuid: phone
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const { autoSignup } = ((_a = this.authenticator.options) == null ? void 0 : _a.public) || {};
|
|
58
|
+
const authenticator = this.authenticator;
|
|
59
|
+
if (autoSignup) {
|
|
60
|
+
user = await authenticator.findOrCreateUser(phone, {
|
|
61
|
+
nickname: phone,
|
|
62
|
+
phone
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
user = await authenticator.findUser(phone);
|
|
67
|
+
if (!user) {
|
|
68
|
+
throw new Error(ctx.t("The phone number is not registered, please register first", { ns: import_constants.namespace }));
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.log(err);
|
|
72
|
+
throw new Error(err.message);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return user;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
SMSAuth
|
|
81
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-auth-sms",
|
|
3
|
+
"displayName": "Auth: SMS",
|
|
4
|
+
"displayName.zh-CN": "认证:短信",
|
|
5
|
+
"description": "SMS authentication.",
|
|
6
|
+
"description.zh-CN": "通过短信验证码认证身份。",
|
|
7
|
+
"version": "1.0.0-alpha.1",
|
|
8
|
+
"main": "./dist/server/index.js",
|
|
9
|
+
"homepage": "https://docs.nocobase.com/handbook/auth-sms",
|
|
10
|
+
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/auth-sms",
|
|
11
|
+
"license": "AGPL-3.0",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@formily/react": "2.x",
|
|
14
|
+
"antd": "5.x",
|
|
15
|
+
"react": "18.x",
|
|
16
|
+
"react-i18next": "^11.15.1"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"@nocobase/actions": "1.x",
|
|
20
|
+
"@nocobase/auth": "1.x",
|
|
21
|
+
"@nocobase/client": "1.x",
|
|
22
|
+
"@nocobase/database": "1.x",
|
|
23
|
+
"@nocobase/plugin-auth": ">=0.17.0-alpha.7",
|
|
24
|
+
"@nocobase/plugin-verification": "1.x",
|
|
25
|
+
"@nocobase/server": "1.x",
|
|
26
|
+
"@nocobase/test": "1.x"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "c73b6d2032a6151fdfeebeb0ec923d766578c53c",
|
|
29
|
+
"keywords": [
|
|
30
|
+
"Authentication"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
4
|
+
if (typeof WeakMap !== 'function') return null;
|
|
5
|
+
var cacheBabelInterop = new WeakMap();
|
|
6
|
+
var cacheNodeInterop = new WeakMap();
|
|
7
|
+
return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) {
|
|
8
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
9
|
+
})(nodeInterop);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
13
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
14
|
+
return obj;
|
|
15
|
+
}
|
|
16
|
+
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
|
17
|
+
return { default: obj };
|
|
18
|
+
}
|
|
19
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
20
|
+
if (cache && cache.has(obj)) {
|
|
21
|
+
return cache.get(obj);
|
|
22
|
+
}
|
|
23
|
+
var newObj = {};
|
|
24
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
25
|
+
for (var key in obj) {
|
|
26
|
+
if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
27
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
28
|
+
if (desc && (desc.get || desc.set)) {
|
|
29
|
+
Object.defineProperty(newObj, key, desc);
|
|
30
|
+
} else {
|
|
31
|
+
newObj[key] = obj[key];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
newObj.default = obj;
|
|
36
|
+
if (cache) {
|
|
37
|
+
cache.set(obj, newObj);
|
|
38
|
+
}
|
|
39
|
+
return newObj;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var _index = _interopRequireWildcard(require('./dist/server'));
|
|
43
|
+
|
|
44
|
+
Object.defineProperty(exports, '__esModule', {
|
|
45
|
+
value: true,
|
|
46
|
+
});
|
|
47
|
+
var _exportNames = {};
|
|
48
|
+
Object.defineProperty(exports, 'default', {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function get() {
|
|
51
|
+
return _index.default;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
Object.keys(_index).forEach(function (key) {
|
|
56
|
+
if (key === 'default' || key === '__esModule') return;
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
58
|
+
if (key in exports && exports[key] === _index[key]) return;
|
|
59
|
+
Object.defineProperty(exports, key, {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function get() {
|
|
62
|
+
return _index[key];
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
});
|