@abtnode/auth 1.16.52-beta-20251003-083412-fdfc4e36 → 1.16.52-beta-20251005-235515-42ad5caf
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/lib/auth.js +20 -3
- package/lib/invitation.js +21 -1
- package/lib/util/user-info.js +1 -1
- package/package.json +8 -8
package/lib/auth.js
CHANGED
|
@@ -413,7 +413,7 @@ const beforeInvitationRequest = async ({ node, teamDid, inviteId, locale = 'en'
|
|
|
413
413
|
}
|
|
414
414
|
};
|
|
415
415
|
|
|
416
|
-
const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, baseUrl, locale = 'en' }) => {
|
|
416
|
+
const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, baseUrl, locale = 'en', orgId = '' }) => {
|
|
417
417
|
// verify invite id
|
|
418
418
|
await node.checkInvitation({ teamDid, inviteId });
|
|
419
419
|
const inviteInfo = await node.getInvitation({ teamDid, inviteId });
|
|
@@ -425,7 +425,7 @@ const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, base
|
|
|
425
425
|
logo,
|
|
426
426
|
} = await getApplicationInfo({ node, nodeInfo, teamDid, baseUrl });
|
|
427
427
|
|
|
428
|
-
const result = await createPassport({ name: inviteInfo.role, node, teamDid, locale });
|
|
428
|
+
const result = await createPassport({ name: inviteInfo.role, node, teamDid, locale, orgId });
|
|
429
429
|
|
|
430
430
|
return {
|
|
431
431
|
description: messages.receivePassport[locale],
|
|
@@ -522,7 +522,15 @@ const handleInvitationReceive = async ({
|
|
|
522
522
|
enableConnectedAccount: true,
|
|
523
523
|
});
|
|
524
524
|
|
|
525
|
-
const
|
|
525
|
+
const { orgId = '', inviteUserDids = [] } = inviteInfo || {};
|
|
526
|
+
const isOrgInvite = !!orgId;
|
|
527
|
+
// 邀请内部成员时,接收者必须在邀请列表中
|
|
528
|
+
if (orgId && inviteUserDids.length > 0 && !inviteUserDids.includes(userDid)) {
|
|
529
|
+
// 接收者不在邀请列表中,不允许接收通行证
|
|
530
|
+
throw new CustomError(403, 'You are not allowed to receive passport');
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const result = await createPassport({ name: inviteInfo.role, node, teamDid, locale, endpoint, orgId });
|
|
526
534
|
const purpose = teamDid === nodeInfo.did || isEmpty(result.types) ? 'login' : 'verification';
|
|
527
535
|
const vcParams = {
|
|
528
536
|
issuerName,
|
|
@@ -675,11 +683,20 @@ const handleInvitationReceive = async ({
|
|
|
675
683
|
);
|
|
676
684
|
}
|
|
677
685
|
|
|
686
|
+
// 处理加入组织逻辑
|
|
687
|
+
const inviteMemberDid = user?.did || userDid;
|
|
688
|
+
if (isOrgInvite && inviteUserDids.length > 0) {
|
|
689
|
+
await node.updateOrgMember({ teamDid, orgId, userDid: inviteMemberDid, status: 'active' }, req);
|
|
690
|
+
} else if (isOrgInvite && !inviteUserDids.length) {
|
|
691
|
+
await node.addOrgMember({ teamDid, orgId, userDid: inviteMemberDid }, req);
|
|
692
|
+
}
|
|
693
|
+
|
|
678
694
|
// await node.closeInvitation({ teamDid, inviteId, status: 'success', receiver: { did: userDid, role } });
|
|
679
695
|
await node.closeInvitation({
|
|
680
696
|
teamDid,
|
|
681
697
|
inviteId,
|
|
682
698
|
status: 'success',
|
|
699
|
+
isOrgInvite,
|
|
683
700
|
receiver: { did: user?.did || userDid, role, timeout: 1000 * 9999 },
|
|
684
701
|
});
|
|
685
702
|
|
package/lib/invitation.js
CHANGED
|
@@ -65,13 +65,25 @@ async function getInvitation({ node, teamDid, inviteId, roles }) {
|
|
|
65
65
|
/**
|
|
66
66
|
* @type {Role}
|
|
67
67
|
*/
|
|
68
|
-
const role = roles.find((v) => v.name === invitationData.role);
|
|
69
68
|
const invitation = {
|
|
70
69
|
...invitationData,
|
|
71
70
|
expireDate: new Date(invitationData.expireDate).getTime(),
|
|
72
71
|
receiver: null,
|
|
73
72
|
};
|
|
74
73
|
|
|
74
|
+
let orgRoles = [];
|
|
75
|
+
if (invitation.orgId) {
|
|
76
|
+
try {
|
|
77
|
+
orgRoles = await node.getRoles({ teamDid, orgId: invitationData.orgId });
|
|
78
|
+
} catch (err) {
|
|
79
|
+
logger.error('failed to get org roles', { teamDid, orgId: invitationData.orgId, error: err });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const allRoles = [...roles, ...orgRoles];
|
|
84
|
+
|
|
85
|
+
const role = allRoles.find((v) => v.name === invitationData.role);
|
|
86
|
+
|
|
75
87
|
return {
|
|
76
88
|
invitation,
|
|
77
89
|
role,
|
|
@@ -182,6 +194,14 @@ module.exports = {
|
|
|
182
194
|
return;
|
|
183
195
|
}
|
|
184
196
|
|
|
197
|
+
// 如果是邀请内部用户加入 Org,则需要检查是否邀请了该用户
|
|
198
|
+
if (invitation.orgId && req.user && invitation.inviteUserDids?.length > 0) {
|
|
199
|
+
if (!invitation.inviteUserDids.includes(req.user.did)) {
|
|
200
|
+
res.status(404).send('You have already received the invitation or not invited you');
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
185
205
|
try {
|
|
186
206
|
role.permissions = await node.getPermissionsByRole({ teamDid, role: { name: role.name } });
|
|
187
207
|
} catch (err) {
|
package/lib/util/user-info.js
CHANGED
|
@@ -13,7 +13,7 @@ const getUserPublicInfo = async ({ req, teamDid, node }) => {
|
|
|
13
13
|
const inputSchema = Joi.DID().required();
|
|
14
14
|
const { error, value } = inputSchema.validate(req.query.did);
|
|
15
15
|
if (error) {
|
|
16
|
-
throw new CustomError(400,
|
|
16
|
+
throw new CustomError(400, 'Invalid user did');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
let _teamDid = teamDid;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.52-beta-
|
|
6
|
+
"version": "1.16.52-beta-20251005-235515-42ad5caf",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.16.52-beta-
|
|
24
|
-
"@abtnode/logger": "1.16.52-beta-
|
|
25
|
-
"@abtnode/util": "1.16.52-beta-
|
|
23
|
+
"@abtnode/constant": "1.16.52-beta-20251005-235515-42ad5caf",
|
|
24
|
+
"@abtnode/logger": "1.16.52-beta-20251005-235515-42ad5caf",
|
|
25
|
+
"@abtnode/util": "1.16.52-beta-20251005-235515-42ad5caf",
|
|
26
26
|
"@arcblock/did": "1.25.6",
|
|
27
27
|
"@arcblock/did-connect-js": "1.25.6",
|
|
28
28
|
"@arcblock/did-ext": "1.25.6",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"@arcblock/nft-display": "^3.1.44",
|
|
32
32
|
"@arcblock/validator": "1.25.6",
|
|
33
33
|
"@arcblock/vc": "1.25.6",
|
|
34
|
-
"@blocklet/constant": "1.16.52-beta-
|
|
34
|
+
"@blocklet/constant": "1.16.52-beta-20251005-235515-42ad5caf",
|
|
35
35
|
"@blocklet/error": "^0.2.5",
|
|
36
|
-
"@blocklet/meta": "1.16.52-beta-
|
|
37
|
-
"@blocklet/sdk": "1.16.52-beta-
|
|
36
|
+
"@blocklet/meta": "1.16.52-beta-20251005-235515-42ad5caf",
|
|
37
|
+
"@blocklet/sdk": "1.16.52-beta-20251005-235515-42ad5caf",
|
|
38
38
|
"@ocap/client": "1.25.6",
|
|
39
39
|
"@ocap/mcrypto": "1.25.6",
|
|
40
40
|
"@ocap/util": "1.25.6",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"jest": "^29.7.0"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "7b295929a123edac2cb292c43f2edda0d3e3e6b8"
|
|
60
60
|
}
|