@abtnode/auth 1.17.3 → 1.17.4-beta-20251201-085909-4ab697bb
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/server.js +37 -2
- package/package.json +8 -8
package/lib/server.js
CHANGED
|
@@ -17,11 +17,13 @@ const { getBlockletChainInfo, isInProgress, isRunning } = require('@blocklet/met
|
|
|
17
17
|
const { getChainClient } = require('@abtnode/util/lib/get-chain-client');
|
|
18
18
|
|
|
19
19
|
const { getBlockletInfo } = require('@blocklet/meta/lib/info');
|
|
20
|
+
const { getBlockletAppIdList } = require('@blocklet/meta/lib/util');
|
|
20
21
|
const formatContext = require('@abtnode/util/lib/format-context');
|
|
21
22
|
const { isInServerlessMode } = require('@abtnode/util/lib/serverless');
|
|
22
23
|
const getRequestIP = require('@abtnode/util/lib/get-request-ip');
|
|
23
24
|
const { convertToMoniker } = require('@abtnode/util/lib/transfer-to-moniker');
|
|
24
25
|
const { LOGIN_PROVIDER } = require('@blocklet/constant');
|
|
26
|
+
const { getDidDomainForBlocklet } = require('@abtnode/util/lib/get-domain-for-blocklet');
|
|
25
27
|
const { getUserAvatarUrl, getAppAvatarUrl } = require('@abtnode/util/lib/user');
|
|
26
28
|
const {
|
|
27
29
|
ROLES,
|
|
@@ -124,6 +126,33 @@ const getLauncherAppIdList = async (url) => {
|
|
|
124
126
|
}
|
|
125
127
|
};
|
|
126
128
|
|
|
129
|
+
const getBlockletKnownDids = async ({ teamDid, blocklet, node }) => {
|
|
130
|
+
try {
|
|
131
|
+
let blockletInfo = blocklet;
|
|
132
|
+
if (!blockletInfo) {
|
|
133
|
+
blockletInfo = await node.getBlocklet({ did: teamDid, useCache: true });
|
|
134
|
+
}
|
|
135
|
+
return getBlockletAppIdList(blockletInfo);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return [teamDid];
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const getKnownIssuerDids = async ({ issuerDid, node }) => {
|
|
142
|
+
try {
|
|
143
|
+
// FIXME: @liushuang 多次迁移后,did 可能是第一次的 did,存在查询不到 blocklet 信息的情况,通过 domain 间接查询
|
|
144
|
+
const domain = getDidDomainForBlocklet({ did: issuerDid });
|
|
145
|
+
const blockletInfo = await node.getBlocklet({
|
|
146
|
+
did: issuerDid,
|
|
147
|
+
domain,
|
|
148
|
+
useCache: true,
|
|
149
|
+
});
|
|
150
|
+
return getBlockletAppIdList(blockletInfo);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
return [issuerDid];
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
127
156
|
const authenticateByVc = async ({
|
|
128
157
|
node,
|
|
129
158
|
locale,
|
|
@@ -193,13 +222,19 @@ const authenticateByVc = async ({
|
|
|
193
222
|
if (passportTypes.some((x) => [VC_TYPE_GENERAL_PASSPORT].includes(x))) {
|
|
194
223
|
await validatePassport(get(vc, 'credentialSubject.passport'));
|
|
195
224
|
const issuerId = get(vc, 'issuer.id');
|
|
196
|
-
|
|
225
|
+
|
|
226
|
+
// 需要考虑到 Blocklet 迁移的情况
|
|
227
|
+
const knownTeamDids = await getBlockletKnownDids({ teamDid, blocklet, node });
|
|
228
|
+
const knownIssuerDids = await getKnownIssuerDids({ issuerDid: issuerId, node });
|
|
229
|
+
|
|
230
|
+
// 如果 issuerId 存在于 blocklet 的 alsoKnownAs 中认为是相同的 blocklet
|
|
231
|
+
if (knownTeamDids.includes(issuerId)) {
|
|
197
232
|
role = getRoleFromLocalPassport(get(vc, 'credentialSubject.passport'));
|
|
198
233
|
} else {
|
|
199
234
|
// map external passport to local role
|
|
200
235
|
const trustedPassports =
|
|
201
236
|
blocklet?.trustedPassports?.length > 0 ? blocklet?.trustedPassports : info.trustedPassports || [];
|
|
202
|
-
const { mappings = [] } = trustedPassports.find((x) => x.issuerDid
|
|
237
|
+
const { mappings = [] } = trustedPassports.find((x) => knownIssuerDids.includes(x.issuerDid)) || {};
|
|
203
238
|
role = await getRoleFromExternalPassport({
|
|
204
239
|
passport: get(vc, 'credentialSubject.passport'),
|
|
205
240
|
node,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.17.
|
|
6
|
+
"version": "1.17.4-beta-20251201-085909-4ab697bb",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,9 +18,9 @@
|
|
|
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.
|
|
22
|
-
"@abtnode/logger": "1.17.
|
|
23
|
-
"@abtnode/util": "1.17.
|
|
21
|
+
"@abtnode/constant": "1.17.4-beta-20251201-085909-4ab697bb",
|
|
22
|
+
"@abtnode/logger": "1.17.4-beta-20251201-085909-4ab697bb",
|
|
23
|
+
"@abtnode/util": "1.17.4-beta-20251201-085909-4ab697bb",
|
|
24
24
|
"@arcblock/did": "^1.27.12",
|
|
25
25
|
"@arcblock/did-connect-js": "^1.27.12",
|
|
26
26
|
"@arcblock/did-ext": "^1.27.12",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@arcblock/nft-display": "^3.2.11",
|
|
30
30
|
"@arcblock/validator": "^1.27.12",
|
|
31
31
|
"@arcblock/vc": "^1.27.12",
|
|
32
|
-
"@blocklet/constant": "1.17.
|
|
32
|
+
"@blocklet/constant": "1.17.4-beta-20251201-085909-4ab697bb",
|
|
33
33
|
"@blocklet/error": "^0.3.3",
|
|
34
|
-
"@blocklet/meta": "1.17.
|
|
35
|
-
"@blocklet/sdk": "1.17.
|
|
34
|
+
"@blocklet/meta": "1.17.4-beta-20251201-085909-4ab697bb",
|
|
35
|
+
"@blocklet/sdk": "1.17.4-beta-20251201-085909-4ab697bb",
|
|
36
36
|
"@ocap/client": "^1.27.12",
|
|
37
37
|
"@ocap/mcrypto": "^1.27.12",
|
|
38
38
|
"@ocap/util": "^1.27.12",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"axios-mock-adapter": "^2.1.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "4a76a83d2c47b00686c1c0fdd7b78ffddd728f0e"
|
|
59
59
|
}
|