@abtnode/auth 1.8.63 → 1.8.64-beta-0b5ede51
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 +16 -9
- package/lib/invitation.js +18 -7
- package/lib/server.js +23 -4
- package/package.json +14 -14
package/lib/auth.js
CHANGED
|
@@ -374,8 +374,7 @@ const getUser = async (node, teamDid, userDid) => {
|
|
|
374
374
|
};
|
|
375
375
|
|
|
376
376
|
const beforeInvitationRequest = async ({ node, teamDid, inviteId, locale = 'en' }) => {
|
|
377
|
-
const
|
|
378
|
-
const inviteInfo = invitations.find((d) => d.inviteId === inviteId);
|
|
377
|
+
const inviteInfo = await node.getInvitation({ teamDid, inviteId });
|
|
379
378
|
|
|
380
379
|
if (!inviteInfo) {
|
|
381
380
|
throw new Error(
|
|
@@ -399,8 +398,7 @@ const beforeInvitationRequest = async ({ node, teamDid, inviteId, locale = 'en'
|
|
|
399
398
|
|
|
400
399
|
const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, locale = 'en' }) => {
|
|
401
400
|
// verify invite id
|
|
402
|
-
const
|
|
403
|
-
const inviteInfo = invitations.find((d) => d.inviteId === inviteId);
|
|
401
|
+
const inviteInfo = await node.getInvitation({ teamDid, inviteId });
|
|
404
402
|
if (!inviteInfo) {
|
|
405
403
|
throw new Error('The invitation does not exist or has been used');
|
|
406
404
|
}
|
|
@@ -452,16 +450,17 @@ const handleInvitationResponse = async ({
|
|
|
452
450
|
const claim = claims.find((x) => x.type === 'signature');
|
|
453
451
|
verifySignature(claim, userDid, userPk, locale);
|
|
454
452
|
|
|
455
|
-
const
|
|
456
|
-
if (!
|
|
453
|
+
const inviteInfo = await node.getInvitation({ teamDid, inviteId });
|
|
454
|
+
if (!inviteInfo) {
|
|
457
455
|
throw new Error(`The invitation does not exist: ${inviteId}`);
|
|
458
456
|
}
|
|
459
457
|
|
|
460
|
-
if (
|
|
458
|
+
if (inviteInfo.role === 'owner' && userDid === nodeInfo.nodeOwner.did) {
|
|
461
459
|
throw new Error(messages.notAllowedTransferToSelf[locale]);
|
|
462
460
|
}
|
|
463
461
|
|
|
464
|
-
|
|
462
|
+
await node.checkInvitation({ teamDid, inviteId });
|
|
463
|
+
|
|
465
464
|
if (inviteInfo.role === 'owner' && get(nodeInfo, 'ownerNft.holder')) {
|
|
466
465
|
// 这种情况下是 Transfer 有 Owner NFT 的 Blocklet Server
|
|
467
466
|
const client = new Client(nodeInfo.launcher.chainHost);
|
|
@@ -599,7 +598,15 @@ const handleInvitationResponse = async ({
|
|
|
599
598
|
);
|
|
600
599
|
}
|
|
601
600
|
|
|
602
|
-
logger.info('
|
|
601
|
+
logger.info('invite success', { userDid });
|
|
602
|
+
|
|
603
|
+
// await node.closeInvitation({ teamDid, inviteId, status: 'success', receiver: { did: userDid, role } });
|
|
604
|
+
await node.closeInvitation({
|
|
605
|
+
teamDid,
|
|
606
|
+
inviteId,
|
|
607
|
+
status: 'success',
|
|
608
|
+
receiver: { did: userDid, role, timeout: 1000 * 9999 },
|
|
609
|
+
});
|
|
603
610
|
|
|
604
611
|
return {
|
|
605
612
|
passport,
|
package/lib/invitation.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
+
const omit = require('lodash/omit');
|
|
2
3
|
const joinUrl = require('url-join');
|
|
3
4
|
const { WELLKNOWN_SERVICE_PATH_PREFIX, NODE_DATA_DIR_NAME } = require('@abtnode/constant');
|
|
4
5
|
const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/constant');
|
|
@@ -28,6 +29,7 @@ module.exports = {
|
|
|
28
29
|
chainHost: blockletInfo.configObj.CHAIN_HOST,
|
|
29
30
|
passportColor: blockletInfo.configObj[BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_PASSPORT_COLOR],
|
|
30
31
|
description: blockletInfo.meta.description,
|
|
32
|
+
dataDir: blockletInfo.env.dataDir,
|
|
31
33
|
};
|
|
32
34
|
} else {
|
|
33
35
|
info = {
|
|
@@ -37,11 +39,12 @@ module.exports = {
|
|
|
37
39
|
name: nodeInfo.name,
|
|
38
40
|
version: nodeInfo.version,
|
|
39
41
|
description: nodeInfo.description,
|
|
42
|
+
dataDir: path.join(node.dataDirs.data, NODE_DATA_DIR_NAME),
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
const teamDid = info.did;
|
|
44
|
-
const invitations = await node.getInvitations({ teamDid });
|
|
47
|
+
const invitations = await node.getInvitations({ teamDid, filter: () => true });
|
|
45
48
|
const invitation = invitations.find((v) => v.inviteId === inviteId);
|
|
46
49
|
if (!invitation || Date.now() > new Date(invitation.expireDate).getTime()) {
|
|
47
50
|
res.status(404).send('Invitation not found or invitation has been used');
|
|
@@ -59,21 +62,29 @@ module.exports = {
|
|
|
59
62
|
logger.error('failed to get role permission', { teamDid, role: role.name, error: err });
|
|
60
63
|
role.permissions = [];
|
|
61
64
|
}
|
|
62
|
-
|
|
65
|
+
|
|
66
|
+
let user = await node.getUser({ teamDid: info.did, user: { did: invitation.inviter.did } });
|
|
67
|
+
let avatar = user && (await parseUserAvatar(user.avatar, { dataDir: info.dataDir }));
|
|
68
|
+
|
|
69
|
+
// blocklet 邀请链接可能是 server 的 member
|
|
70
|
+
if (!user && type === 'blocklet') {
|
|
71
|
+
user = await node.getUser({ teamDid: nodeInfo.did, user: { did: invitation.inviter.did } });
|
|
72
|
+
avatar =
|
|
73
|
+
user &&
|
|
74
|
+
(await parseUserAvatar(user.avatar, { dataDir: path.join(node.dataDirs.data, NODE_DATA_DIR_NAME) }));
|
|
75
|
+
}
|
|
63
76
|
|
|
64
77
|
const inviter = {
|
|
65
78
|
did: invitation.inviter.did,
|
|
66
79
|
email: invitation.inviter.email,
|
|
67
|
-
fullName: invitation.inviter.fullName,
|
|
80
|
+
fullName: invitation.inviter.fullName || user?.fullName,
|
|
68
81
|
role: invitation.inviter.role,
|
|
69
|
-
avatar
|
|
70
|
-
user &&
|
|
71
|
-
(await parseUserAvatar(user.avatar, { dataDir: path.join(node.dataDirs.data, NODE_DATA_DIR_NAME) })),
|
|
82
|
+
avatar,
|
|
72
83
|
};
|
|
73
84
|
|
|
74
85
|
res.json({
|
|
75
86
|
...invitation,
|
|
76
|
-
info,
|
|
87
|
+
info: omit(info, 'dataDir'),
|
|
77
88
|
inviter,
|
|
78
89
|
inviterRaw: invitation.inviter,
|
|
79
90
|
role: role || {},
|
package/lib/server.js
CHANGED
|
@@ -144,9 +144,10 @@ const authenticateByVc = async ({
|
|
|
144
144
|
return { role, user, teamDid, passport };
|
|
145
145
|
};
|
|
146
146
|
|
|
147
|
-
const authenticateByNFT = async ({ node, claims, userDid, challenge, locale, isAuth }) => {
|
|
147
|
+
const authenticateByNFT = async ({ node, claims, userDid, challenge, locale, isAuth, chainHost }) => {
|
|
148
148
|
const info = await node.getNodeInfo();
|
|
149
|
-
|
|
149
|
+
// serverless 应用通过 querystring 传递 chainHost
|
|
150
|
+
const client = new Client(chainHost || info.launcher.chainHost);
|
|
150
151
|
|
|
151
152
|
const claim = claims.find((x) => x.type === 'asset');
|
|
152
153
|
if (!claim) {
|
|
@@ -201,6 +202,7 @@ const authenticateByNFT = async ({ node, claims, userDid, challenge, locale, isA
|
|
|
201
202
|
controller: {
|
|
202
203
|
nftId: address,
|
|
203
204
|
nftOwner: state.owner,
|
|
205
|
+
chainHost,
|
|
204
206
|
appMaxCount: state.data.value.appMaxCount || 1,
|
|
205
207
|
},
|
|
206
208
|
},
|
|
@@ -339,7 +341,17 @@ const getServerlessNFTClaim = async (node, nftId, locale) => {
|
|
|
339
341
|
};
|
|
340
342
|
};
|
|
341
343
|
|
|
342
|
-
const ensureBlockletPermission = async ({
|
|
344
|
+
const ensureBlockletPermission = async ({
|
|
345
|
+
authMethod,
|
|
346
|
+
node,
|
|
347
|
+
userDid,
|
|
348
|
+
claims,
|
|
349
|
+
challenge,
|
|
350
|
+
locale,
|
|
351
|
+
blocklet,
|
|
352
|
+
isAuth,
|
|
353
|
+
chainHost,
|
|
354
|
+
}) => {
|
|
343
355
|
let result;
|
|
344
356
|
if (authMethod === 'vc') {
|
|
345
357
|
result = await authenticateByVc({
|
|
@@ -360,6 +372,7 @@ const ensureBlockletPermission = async ({ authMethod, node, userDid, claims, cha
|
|
|
360
372
|
claims,
|
|
361
373
|
challenge,
|
|
362
374
|
isAuth,
|
|
375
|
+
chainHost,
|
|
363
376
|
});
|
|
364
377
|
}
|
|
365
378
|
const { teamDid, role } = result;
|
|
@@ -375,7 +388,7 @@ const ensureBlockletPermission = async ({ authMethod, node, userDid, claims, cha
|
|
|
375
388
|
const createLaunchBlockletHandler =
|
|
376
389
|
(node, authMethod) =>
|
|
377
390
|
async ({ claims, challenge, userDid, updateSession, req, extraParams }) => {
|
|
378
|
-
const { locale, blockletMetaUrl } = extraParams;
|
|
391
|
+
const { locale, blockletMetaUrl, chainHost } = extraParams;
|
|
379
392
|
logger.info('createLaunchBlockletHandler', extraParams);
|
|
380
393
|
|
|
381
394
|
if (!blockletMetaUrl) {
|
|
@@ -383,6 +396,11 @@ const createLaunchBlockletHandler =
|
|
|
383
396
|
throw new Error(messages.invalidParams[locale]);
|
|
384
397
|
}
|
|
385
398
|
|
|
399
|
+
if (authMethod === 'nft' && !chainHost) {
|
|
400
|
+
logger.error('chainHost must be provided');
|
|
401
|
+
throw new Error(messages.invalidParams[locale]);
|
|
402
|
+
}
|
|
403
|
+
|
|
386
404
|
const { role, passport, user, extra } = await ensureBlockletPermission({
|
|
387
405
|
authMethod,
|
|
388
406
|
node,
|
|
@@ -391,6 +409,7 @@ const createLaunchBlockletHandler =
|
|
|
391
409
|
challenge,
|
|
392
410
|
locale,
|
|
393
411
|
isAuth: false,
|
|
412
|
+
chainHost,
|
|
394
413
|
});
|
|
395
414
|
|
|
396
415
|
const blocklet = await node.getBlockletMetaFromUrl({ url: blockletMetaUrl, checkPrice: true });
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.64-beta-0b5ede51",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.8.
|
|
24
|
-
"@abtnode/logger": "1.8.
|
|
25
|
-
"@abtnode/util": "1.8.
|
|
26
|
-
"@arcblock/did": "1.18.
|
|
27
|
-
"@arcblock/jwt": "^1.18.
|
|
28
|
-
"@arcblock/vc": "1.18.
|
|
29
|
-
"@blocklet/constant": "1.8.
|
|
30
|
-
"@blocklet/meta": "1.8.
|
|
31
|
-
"@ocap/client": "1.18.
|
|
32
|
-
"@ocap/mcrypto": "1.18.
|
|
33
|
-
"@ocap/util": "1.18.
|
|
34
|
-
"@ocap/wallet": "1.18.
|
|
23
|
+
"@abtnode/constant": "1.8.64-beta-0b5ede51",
|
|
24
|
+
"@abtnode/logger": "1.8.64-beta-0b5ede51",
|
|
25
|
+
"@abtnode/util": "1.8.64-beta-0b5ede51",
|
|
26
|
+
"@arcblock/did": "1.18.37",
|
|
27
|
+
"@arcblock/jwt": "^1.18.37",
|
|
28
|
+
"@arcblock/vc": "1.18.37",
|
|
29
|
+
"@blocklet/constant": "1.8.64-beta-0b5ede51",
|
|
30
|
+
"@blocklet/meta": "1.8.64-beta-0b5ede51",
|
|
31
|
+
"@ocap/client": "1.18.37",
|
|
32
|
+
"@ocap/mcrypto": "1.18.37",
|
|
33
|
+
"@ocap/util": "1.18.37",
|
|
34
|
+
"@ocap/wallet": "1.18.37",
|
|
35
35
|
"axios": "^0.27.2",
|
|
36
36
|
"joi": "17.7.0",
|
|
37
37
|
"jsonwebtoken": "^9.0.0",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"jest": "^27.5.1"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "fbb72fdf88ea44c949ea951b84ab0506805bda7d"
|
|
46
46
|
}
|