@abtnode/auth 1.17.8-beta-20260121-102603-f9d0176f → 1.17.8-beta-20260125-093329-64b43854
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 +76 -63
- package/lib/lost-passport.js +3 -3
- package/lib/oauth.js +0 -2
- package/lib/passkey.js +0 -6
- package/lib/server.js +2 -1
- package/lib/util/user-info.js +18 -6
- package/package.json +20 -20
package/lib/auth.js
CHANGED
|
@@ -544,14 +544,21 @@ const handleInvitationReceive = async ({
|
|
|
544
544
|
|
|
545
545
|
const { orgId = '', inviteUserDids = [] } = inviteInfo || {};
|
|
546
546
|
const isOrgInvite = !!orgId;
|
|
547
|
+
if (isOrgInvite && !user) {
|
|
548
|
+
throw new CustomError(403, 'Please log in with your account to accept this organization invitation.');
|
|
549
|
+
}
|
|
547
550
|
// 邀请内部成员时,接收者必须在邀请列表中
|
|
548
551
|
if (orgId && inviteUserDids.length > 0 && !inviteUserDids.includes(userDid)) {
|
|
549
552
|
// 接收者不在邀请列表中,不允许接收通行证
|
|
550
|
-
throw new CustomError(403, 'You are not
|
|
553
|
+
throw new CustomError(403, 'You are not invited to this org');
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const result = await createPassport({ name: inviteInfo.role, node, teamDid, locale, endpoint });
|
|
557
|
+
let purpose = teamDid === nodeInfo.did || isEmpty(result.types) ? 'login' : 'verification';
|
|
558
|
+
if (isOrgInvite) {
|
|
559
|
+
purpose = 'accept-invitation';
|
|
551
560
|
}
|
|
552
561
|
|
|
553
|
-
const result = await createPassport({ name: inviteInfo.role, node, teamDid, locale, endpoint, orgId });
|
|
554
|
-
const purpose = teamDid === nodeInfo.did || isEmpty(result.types) ? 'login' : 'verification';
|
|
555
562
|
const vcParams = {
|
|
556
563
|
issuerName,
|
|
557
564
|
issuerWallet,
|
|
@@ -581,7 +588,7 @@ const handleInvitationReceive = async ({
|
|
|
581
588
|
}
|
|
582
589
|
|
|
583
590
|
const vc = await createPassportVC(vcParams);
|
|
584
|
-
|
|
591
|
+
let role = getRoleFromLocalPassport(get(vc, 'credentialSubject.passport'));
|
|
585
592
|
const passport = createUserPassport(vc, { role, display: inviteInfo.display, source });
|
|
586
593
|
|
|
587
594
|
// NOTICE: owner 目前必须是 did-wallet 的账户,暂不做额外 did 判断
|
|
@@ -618,68 +625,74 @@ const handleInvitationReceive = async ({
|
|
|
618
625
|
|
|
619
626
|
let doc;
|
|
620
627
|
|
|
621
|
-
if (
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
628
|
+
if (!isOrgInvite) {
|
|
629
|
+
if (user) {
|
|
630
|
+
doc = await node.loginUser({
|
|
631
|
+
teamDid,
|
|
632
|
+
user: {
|
|
633
|
+
...profile,
|
|
634
|
+
...kycUpdates,
|
|
635
|
+
avatar,
|
|
636
|
+
did: user.did,
|
|
637
|
+
pk: user.pk,
|
|
638
|
+
locale,
|
|
639
|
+
passport,
|
|
640
|
+
lastLoginIp: getRequestIP(req),
|
|
641
|
+
remark: inviteInfo.remark,
|
|
642
|
+
inviter: inviteInfo.inviter?.did,
|
|
643
|
+
connectedAccount: {
|
|
644
|
+
...connectedAccountUpdates,
|
|
645
|
+
provider,
|
|
646
|
+
did: userDid,
|
|
647
|
+
pk: userPk,
|
|
648
|
+
},
|
|
640
649
|
},
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
avatar,
|
|
659
|
-
did: userDid,
|
|
660
|
-
pk: userPk,
|
|
661
|
-
locale,
|
|
662
|
-
passport,
|
|
663
|
-
lastLoginIp: getRequestIP(req),
|
|
664
|
-
inviter: inviteInfo.inviter?.did,
|
|
665
|
-
remark: inviteInfo.remark,
|
|
666
|
-
connectedAccount: {
|
|
667
|
-
...connectedAccountUpdates,
|
|
668
|
-
provider,
|
|
650
|
+
});
|
|
651
|
+
await node.createAuditLog(
|
|
652
|
+
{
|
|
653
|
+
action: 'updateUser',
|
|
654
|
+
args: { teamDid, userDid: user.did, passport, inviteId, reason: 'accepted invitation' },
|
|
655
|
+
context: formatContext(Object.assign(req, { user })),
|
|
656
|
+
result: doc,
|
|
657
|
+
},
|
|
658
|
+
node
|
|
659
|
+
);
|
|
660
|
+
} else {
|
|
661
|
+
doc = await node.loginUser({
|
|
662
|
+
teamDid,
|
|
663
|
+
user: {
|
|
664
|
+
...profile,
|
|
665
|
+
...kycUpdates,
|
|
666
|
+
avatar,
|
|
669
667
|
did: userDid,
|
|
670
668
|
pk: userPk,
|
|
669
|
+
locale,
|
|
670
|
+
passport,
|
|
671
|
+
lastLoginIp: getRequestIP(req),
|
|
672
|
+
inviter: inviteInfo.inviter?.did,
|
|
673
|
+
remark: inviteInfo.remark,
|
|
674
|
+
connectedAccount: {
|
|
675
|
+
...connectedAccountUpdates,
|
|
676
|
+
provider,
|
|
677
|
+
did: userDid,
|
|
678
|
+
pk: userPk,
|
|
679
|
+
},
|
|
671
680
|
},
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
681
|
+
});
|
|
682
|
+
await node.createAuditLog(
|
|
683
|
+
{
|
|
684
|
+
action: 'addUser',
|
|
685
|
+
args: { teamDid, userDid: user?.did || userDid, passport, inviteId, reason: 'accepted invitation' },
|
|
686
|
+
context: formatContext(Object.assign(req, { user: doc })),
|
|
687
|
+
result: doc,
|
|
688
|
+
},
|
|
689
|
+
node
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
} else {
|
|
693
|
+
const roles = await node.getRoles({ teamDid });
|
|
694
|
+
const orgPassports = roles.filter((r) => r.orgId).map((r) => r.name);
|
|
695
|
+
role = (user.passports || []).filter((p) => !orgPassports.includes(p.role))[0]?.role || 'guest';
|
|
683
696
|
}
|
|
684
697
|
|
|
685
698
|
logger.info('invite success', { userDid: user?.did || userDid, inviter: inviteInfo?.inviter });
|
|
@@ -729,7 +742,7 @@ const handleInvitationReceive = async ({
|
|
|
729
742
|
data: vc,
|
|
730
743
|
},
|
|
731
744
|
profile,
|
|
732
|
-
user: doc,
|
|
745
|
+
user: isOrgInvite ? user : doc,
|
|
733
746
|
inviteInfo,
|
|
734
747
|
purpose,
|
|
735
748
|
};
|
package/lib/lost-passport.js
CHANGED
|
@@ -146,8 +146,10 @@ const createLostPassportListRoute = ({ node, type }) => ({
|
|
|
146
146
|
throw new CustomError(403, messages.notAllowedAppUser[locale]);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
const roles = await node.getRoles({ teamDid });
|
|
150
|
+
const orgPassportList = roles.filter((x) => x.orgId).map((x) => x.name);
|
|
149
151
|
const passportList = getActivePassports(user, issuerDidList);
|
|
150
|
-
user.passportTypes = passportList.filter((x) => x.scope === scope);
|
|
152
|
+
user.passportTypes = passportList.filter((x) => x.scope === scope && !orgPassportList.includes(x.name));
|
|
151
153
|
if (!user.passportTypes.length) {
|
|
152
154
|
throw new CustomError(404, messages.noPassportFound[locale]);
|
|
153
155
|
}
|
|
@@ -477,7 +479,6 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix, createTok
|
|
|
477
479
|
});
|
|
478
480
|
}
|
|
479
481
|
|
|
480
|
-
const org = await request?.getUserOrg?.();
|
|
481
482
|
const { sessionToken, refreshToken } = await createToken(
|
|
482
483
|
userPid,
|
|
483
484
|
{
|
|
@@ -491,7 +492,6 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix, createTok
|
|
|
491
492
|
elevated: canSessionBeElevated(role, blocklet?.settings),
|
|
492
493
|
emailVerified: !!updatedUser.emailVerified,
|
|
493
494
|
phoneVerified: !!updatedUser.phoneVerified,
|
|
494
|
-
org,
|
|
495
495
|
},
|
|
496
496
|
{ ...sessionConfig, didConnectVersion: getDidConnectVersion(req) }
|
|
497
497
|
);
|
package/lib/oauth.js
CHANGED
|
@@ -120,7 +120,6 @@ function createPassportSwitcher(node, createToken, mode = 'server') {
|
|
|
120
120
|
);
|
|
121
121
|
|
|
122
122
|
const role = passport.scope === 'passport' ? passport.role : ROLES.GUEST;
|
|
123
|
-
const org = typeof req.getUserOrg === 'function' ? await req.getUserOrg(role) : '';
|
|
124
123
|
const { sessionToken, refreshToken } = await createToken(
|
|
125
124
|
userDid,
|
|
126
125
|
{
|
|
@@ -132,7 +131,6 @@ function createPassportSwitcher(node, createToken, mode = 'server') {
|
|
|
132
131
|
walletOS: 'web',
|
|
133
132
|
emailVerified: !!user?.emailVerified,
|
|
134
133
|
phoneVerified: !!user?.phoneVerified,
|
|
135
|
-
org,
|
|
136
134
|
},
|
|
137
135
|
{ ...(await getSessionConfig(req)) }
|
|
138
136
|
);
|
package/lib/passkey.js
CHANGED
|
@@ -620,7 +620,6 @@ function createPasskeyHandlers(node, mode, createToken) {
|
|
|
620
620
|
|
|
621
621
|
const createTokens = async (updated, passport, role, profile, result) => {
|
|
622
622
|
const { secret } = await getApplicationInfo({ node, nodeInfo: info, teamDid });
|
|
623
|
-
const org = typeof req.getUserOrg === 'function' ? await req.getUserOrg(role) : '';
|
|
624
623
|
const { sessionToken, refreshToken } = await createToken(
|
|
625
624
|
updated.did,
|
|
626
625
|
{
|
|
@@ -636,7 +635,6 @@ function createPasskeyHandlers(node, mode, createToken) {
|
|
|
636
635
|
role,
|
|
637
636
|
mode === 'service' ? (await node.getBlocklet({ did: teamDid }))?.settings : info
|
|
638
637
|
),
|
|
639
|
-
org,
|
|
640
638
|
},
|
|
641
639
|
{ ...(await getSessionConfig(req)) }
|
|
642
640
|
);
|
|
@@ -788,7 +786,6 @@ function createPasskeyHandlers(node, mode, createToken) {
|
|
|
788
786
|
result.refreshToken = refreshToken;
|
|
789
787
|
} else {
|
|
790
788
|
const { secret } = await getApplicationInfo({ node, nodeInfo: info, teamDid });
|
|
791
|
-
const org = typeof req.getUserOrg === 'function' ? await req.getUserOrg() : '';
|
|
792
789
|
const { sessionToken, refreshToken } = await createToken(
|
|
793
790
|
user.did,
|
|
794
791
|
{
|
|
@@ -801,7 +798,6 @@ function createPasskeyHandlers(node, mode, createToken) {
|
|
|
801
798
|
emailVerified: user.emailVerified,
|
|
802
799
|
phoneVerified: user.phoneVerified,
|
|
803
800
|
elevated,
|
|
804
|
-
org,
|
|
805
801
|
},
|
|
806
802
|
{ ...(await getSessionConfig(req)) }
|
|
807
803
|
);
|
|
@@ -846,14 +842,12 @@ function createPasskeyHandlers(node, mode, createToken) {
|
|
|
846
842
|
action: passkeySession.data.action,
|
|
847
843
|
});
|
|
848
844
|
logger.info('passkey.auth.issuePassportToUser', { teamDid, userDid: user.did });
|
|
849
|
-
const org = typeof req.getUserOrg === 'function' ? await req.getUserOrg() : '';
|
|
850
845
|
const { sessionToken, refreshToken } = await createToken(user.did, {
|
|
851
846
|
secret: await node.getSessionSecret(),
|
|
852
847
|
passport: null,
|
|
853
848
|
role: ROLES.OWNER,
|
|
854
849
|
fullName: user.fullName,
|
|
855
850
|
elevated: true,
|
|
856
|
-
org,
|
|
857
851
|
});
|
|
858
852
|
|
|
859
853
|
result.sessionToken = sessionToken;
|
package/lib/server.js
CHANGED
|
@@ -1285,6 +1285,7 @@ const getVerifyAccessClaims = ({
|
|
|
1285
1285
|
types = BLOCKLET_SERVER_VC_TYPES,
|
|
1286
1286
|
source = 'server',
|
|
1287
1287
|
trustedIssuers = [],
|
|
1288
|
+
optional = false,
|
|
1288
1289
|
}) => {
|
|
1289
1290
|
return async ({ extraParams: { locale }, context: { didwallet, baseUrl } }) => {
|
|
1290
1291
|
checkWalletVersion({ didwallet, locale });
|
|
@@ -1313,7 +1314,7 @@ const getVerifyAccessClaims = ({
|
|
|
1313
1314
|
return {
|
|
1314
1315
|
description: messages.requestPassport[locale],
|
|
1315
1316
|
claimUrl: getPassportClaimUrl(baseUrl, source === 'server' ? info.routing.adminPath : ''),
|
|
1316
|
-
optional
|
|
1317
|
+
optional,
|
|
1317
1318
|
filters: targets.map((x) => ({
|
|
1318
1319
|
type: types,
|
|
1319
1320
|
target: x.id,
|
package/lib/util/user-info.js
CHANGED
|
@@ -10,10 +10,13 @@ const { omit, pick } = require('lodash');
|
|
|
10
10
|
const { getUserAvatarUrl } = require('./federated');
|
|
11
11
|
|
|
12
12
|
const getUserPublicInfo = async ({ req, teamDid, node }) => {
|
|
13
|
-
const inputSchema = Joi.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const inputSchema = Joi.object({
|
|
14
|
+
did: Joi.DID().optional(),
|
|
15
|
+
name: Joi.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
const { error, value } = inputSchema.validate(req.query);
|
|
18
|
+
if (error || (!value.did && !value.name)) {
|
|
19
|
+
throw new CustomError(400, 'Invalid user did or name');
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
let _teamDid = teamDid;
|
|
@@ -33,7 +36,16 @@ const getUserPublicInfo = async ({ req, teamDid, node }) => {
|
|
|
33
36
|
|
|
34
37
|
const isService = !nodeInfo || nodeInfo.did !== _teamDid;
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
let options;
|
|
40
|
+
if (value.name) {
|
|
41
|
+
options = { name: value.name };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const user = await node.getUser({
|
|
45
|
+
teamDid: _teamDid,
|
|
46
|
+
user: { did: value.did },
|
|
47
|
+
options,
|
|
48
|
+
});
|
|
37
49
|
if (!user || !user?.approved) {
|
|
38
50
|
return null;
|
|
39
51
|
}
|
|
@@ -48,7 +60,7 @@ const getUserPublicInfo = async ({ req, teamDid, node }) => {
|
|
|
48
60
|
}
|
|
49
61
|
}
|
|
50
62
|
|
|
51
|
-
let returnFields = ['avatar', 'did', 'fullName', 'sourceAppPid', 'createdAt', 'metadata'];
|
|
63
|
+
let returnFields = ['avatar', 'did', 'name', 'fullName', 'sourceAppPid', 'createdAt', 'metadata'];
|
|
52
64
|
|
|
53
65
|
// 默认隐藏 phone,请求者是本人时显示完整信息
|
|
54
66
|
const isOwner = req.user?.did === user.did;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.17.8-beta-
|
|
6
|
+
"version": "1.17.8-beta-20260125-093329-64b43854",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,25 +18,25 @@
|
|
|
18
18
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.17.8-beta-
|
|
22
|
-
"@abtnode/logger": "1.17.8-beta-
|
|
23
|
-
"@abtnode/util": "1.17.8-beta-
|
|
24
|
-
"@arcblock/did": "^1.28.
|
|
25
|
-
"@arcblock/did-connect-js": "^1.28.
|
|
26
|
-
"@arcblock/did-ext": "^1.28.
|
|
27
|
-
"@arcblock/did-util": "^1.28.
|
|
28
|
-
"@arcblock/jwt": "^1.28.
|
|
29
|
-
"@arcblock/nft-display": "^3.4.
|
|
30
|
-
"@arcblock/validator": "^1.28.
|
|
31
|
-
"@arcblock/vc": "^1.28.
|
|
32
|
-
"@blocklet/constant": "1.17.8-beta-
|
|
21
|
+
"@abtnode/constant": "1.17.8-beta-20260125-093329-64b43854",
|
|
22
|
+
"@abtnode/logger": "1.17.8-beta-20260125-093329-64b43854",
|
|
23
|
+
"@abtnode/util": "1.17.8-beta-20260125-093329-64b43854",
|
|
24
|
+
"@arcblock/did": "^1.28.6",
|
|
25
|
+
"@arcblock/did-connect-js": "^1.28.6",
|
|
26
|
+
"@arcblock/did-ext": "^1.28.6",
|
|
27
|
+
"@arcblock/did-util": "^1.28.6",
|
|
28
|
+
"@arcblock/jwt": "^1.28.6",
|
|
29
|
+
"@arcblock/nft-display": "^3.4.10",
|
|
30
|
+
"@arcblock/validator": "^1.28.6",
|
|
31
|
+
"@arcblock/vc": "^1.28.6",
|
|
32
|
+
"@blocklet/constant": "1.17.8-beta-20260125-093329-64b43854",
|
|
33
33
|
"@blocklet/error": "^0.3.5",
|
|
34
|
-
"@blocklet/meta": "1.17.8-beta-
|
|
35
|
-
"@blocklet/sdk": "1.17.8-beta-
|
|
36
|
-
"@ocap/client": "^1.28.
|
|
37
|
-
"@ocap/mcrypto": "^1.28.
|
|
38
|
-
"@ocap/util": "^1.28.
|
|
39
|
-
"@ocap/wallet": "^1.28.
|
|
34
|
+
"@blocklet/meta": "1.17.8-beta-20260125-093329-64b43854",
|
|
35
|
+
"@blocklet/sdk": "1.17.8-beta-20260125-093329-64b43854",
|
|
36
|
+
"@ocap/client": "^1.28.6",
|
|
37
|
+
"@ocap/mcrypto": "^1.28.6",
|
|
38
|
+
"@ocap/util": "^1.28.6",
|
|
39
|
+
"@ocap/wallet": "^1.28.6",
|
|
40
40
|
"@simplewebauthn/server": "^13.1.1",
|
|
41
41
|
"axios": "^1.7.9",
|
|
42
42
|
"flat": "^5.0.2",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"axios-mock-adapter": "^2.1.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "241254785bda907be2296228869b4fc9c1679a6b"
|
|
59
59
|
}
|