@abtnode/auth 1.7.9 → 1.7.12
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 +33 -3
- package/lib/lost-passport.js +13 -2
- package/lib/server.js +20 -3
- package/package.json +12 -12
package/lib/auth.js
CHANGED
|
@@ -3,6 +3,7 @@ const semver = require('semver');
|
|
|
3
3
|
const joinUrl = require('url-join');
|
|
4
4
|
const get = require('lodash/get');
|
|
5
5
|
const { verifyPresentation, createCredentialList } = require('@arcblock/vc');
|
|
6
|
+
const formatContext = require('@abtnode/util/lib/format-context');
|
|
6
7
|
const Mcrypto = require('@ocap/mcrypto');
|
|
7
8
|
const { fromSecretKey, WalletType } = require('@ocap/wallet');
|
|
8
9
|
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
@@ -360,6 +361,7 @@ const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, loca
|
|
|
360
361
|
};
|
|
361
362
|
|
|
362
363
|
const handleInvitationResponse = async ({
|
|
364
|
+
req = {},
|
|
363
365
|
node,
|
|
364
366
|
nodeInfo,
|
|
365
367
|
teamDid,
|
|
@@ -423,7 +425,7 @@ const handleInvitationResponse = async ({
|
|
|
423
425
|
const user = await getUser(node, teamDid, userDid);
|
|
424
426
|
|
|
425
427
|
if (user) {
|
|
426
|
-
await node.updateUser({
|
|
428
|
+
const doc = await node.updateUser({
|
|
427
429
|
teamDid,
|
|
428
430
|
user: {
|
|
429
431
|
...profile,
|
|
@@ -435,8 +437,17 @@ const handleInvitationResponse = async ({
|
|
|
435
437
|
remark,
|
|
436
438
|
},
|
|
437
439
|
});
|
|
440
|
+
await node.createAuditLog(
|
|
441
|
+
{
|
|
442
|
+
action: 'updateUser',
|
|
443
|
+
args: { teamDid, userDid, passport, inviteId, reason: 'accepted invitation' },
|
|
444
|
+
context: formatContext(Object.assign(req, { user })),
|
|
445
|
+
result: doc,
|
|
446
|
+
},
|
|
447
|
+
node
|
|
448
|
+
);
|
|
438
449
|
} else {
|
|
439
|
-
await node.addUser({
|
|
450
|
+
const doc = await node.addUser({
|
|
440
451
|
teamDid,
|
|
441
452
|
user: {
|
|
442
453
|
...profile,
|
|
@@ -450,6 +461,15 @@ const handleInvitationResponse = async ({
|
|
|
450
461
|
remark,
|
|
451
462
|
},
|
|
452
463
|
});
|
|
464
|
+
await node.createAuditLog(
|
|
465
|
+
{
|
|
466
|
+
action: 'addUser',
|
|
467
|
+
args: { teamDid, userDid, passport, inviteId, reason: 'accepted invitation' },
|
|
468
|
+
context: formatContext(Object.assign(req, { user: doc })),
|
|
469
|
+
result: doc,
|
|
470
|
+
},
|
|
471
|
+
node
|
|
472
|
+
);
|
|
453
473
|
}
|
|
454
474
|
|
|
455
475
|
logger.info('login.success', { userDid });
|
|
@@ -531,6 +551,7 @@ const createIssuePassportRequest = async ({ node, nodeInfo, teamDid, id, locale
|
|
|
531
551
|
* @param {string} statusEndpointBaseUrl passport status endpoint base url
|
|
532
552
|
*/
|
|
533
553
|
const handleIssuePassportResponse = async ({
|
|
554
|
+
req = {},
|
|
534
555
|
node,
|
|
535
556
|
nodeInfo,
|
|
536
557
|
teamDid,
|
|
@@ -619,7 +640,16 @@ const handleIssuePassportResponse = async ({
|
|
|
619
640
|
}
|
|
620
641
|
|
|
621
642
|
// delete session
|
|
622
|
-
await node.processPassportIssuance({ teamDid, sessionId: id });
|
|
643
|
+
const result = await node.processPassportIssuance({ teamDid, sessionId: id });
|
|
644
|
+
await node.createAuditLog(
|
|
645
|
+
{
|
|
646
|
+
action: 'processPassportIssuance',
|
|
647
|
+
args: { teamDid, userDid, ...result, sessionId: id, reason: 'claimed passport' },
|
|
648
|
+
context: formatContext(Object.assign(req, { user })),
|
|
649
|
+
result,
|
|
650
|
+
},
|
|
651
|
+
node
|
|
652
|
+
);
|
|
623
653
|
|
|
624
654
|
if (name === ROLES.OWNER && issuerType === 'blocklet') {
|
|
625
655
|
logger.info('Bind owner for blocklet', { teamDid, userDid });
|
package/lib/lost-passport.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const joinUrl = require('url-join');
|
|
2
2
|
const uniqBy = require('lodash/uniqBy');
|
|
3
3
|
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
4
|
+
const formatContext = require('@abtnode/util/lib/format-context');
|
|
4
5
|
const getRandomMessage = require('@abtnode/util/lib/get-random-message');
|
|
5
6
|
const getNodeWallet = require('@abtnode/util/lib/get-app-wallet');
|
|
6
7
|
const { getDisplayName } = require('@blocklet/meta/lib/util');
|
|
@@ -255,15 +256,25 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
255
256
|
const vc = createPassportVC(vcParams);
|
|
256
257
|
|
|
257
258
|
const role = getRoleFromLocalPassport(get(vc, 'credentialSubject.passport'));
|
|
259
|
+
const passport = createUserPassport(vc, { role });
|
|
258
260
|
|
|
259
|
-
await node.updateUser({
|
|
261
|
+
const result = await node.updateUser({
|
|
260
262
|
teamDid,
|
|
261
263
|
user: {
|
|
262
264
|
did: userDid,
|
|
263
265
|
pk: userPk,
|
|
264
|
-
passports: upsertToPassports(user.passports || [],
|
|
266
|
+
passports: upsertToPassports(user.passports || [], passport),
|
|
265
267
|
},
|
|
266
268
|
});
|
|
269
|
+
await node.createAuditLog(
|
|
270
|
+
{
|
|
271
|
+
action: 'updateUser',
|
|
272
|
+
args: { teamDid, userDid, passport, reason: 'recovered passport' },
|
|
273
|
+
context: formatContext(Object.assign(req, { user })),
|
|
274
|
+
result,
|
|
275
|
+
},
|
|
276
|
+
node
|
|
277
|
+
);
|
|
267
278
|
|
|
268
279
|
return {
|
|
269
280
|
disposition: 'attachment',
|
package/lib/server.js
CHANGED
|
@@ -4,6 +4,7 @@ const Client = require('@ocap/client');
|
|
|
4
4
|
const { fromPublicKey } = require('@ocap/wallet');
|
|
5
5
|
const { fromBase58, toAddress } = require('@ocap/util');
|
|
6
6
|
const { toTypeInfo, isFromPublicKey } = require('@arcblock/did');
|
|
7
|
+
const formatContext = require('@abtnode/util/lib/format-context');
|
|
7
8
|
const semver = require('semver');
|
|
8
9
|
const {
|
|
9
10
|
ROLES,
|
|
@@ -274,12 +275,19 @@ const ensureBlockletPermission = async ({ authMethod, node, userDid, claims, cha
|
|
|
274
275
|
|
|
275
276
|
const createLaunchBlockletHandler =
|
|
276
277
|
(node, authMethod) =>
|
|
277
|
-
async ({ claims, challenge, userDid, updateSession, extraParams: { locale, blockletMetaUrl } }) => {
|
|
278
|
+
async ({ claims, challenge, userDid, updateSession, req, extraParams: { locale, blockletMetaUrl } }) => {
|
|
278
279
|
if (!blockletMetaUrl) {
|
|
279
280
|
throw new Error(messages.invalidParams[locale]);
|
|
280
281
|
}
|
|
281
282
|
|
|
282
|
-
const { role, passport } = await ensureBlockletPermission({
|
|
283
|
+
const { role, passport, user } = await ensureBlockletPermission({
|
|
284
|
+
authMethod,
|
|
285
|
+
node,
|
|
286
|
+
userDid,
|
|
287
|
+
claims,
|
|
288
|
+
challenge,
|
|
289
|
+
locale,
|
|
290
|
+
});
|
|
283
291
|
|
|
284
292
|
const result = await node.getBlockletMetaFromUrl({ url: blockletMetaUrl, checkPrice: true });
|
|
285
293
|
if (!result.meta) {
|
|
@@ -357,7 +365,16 @@ const createLaunchBlockletHandler =
|
|
|
357
365
|
context.blockletPurchaseVerified = blockletPurchaseVerified;
|
|
358
366
|
}
|
|
359
367
|
|
|
360
|
-
await node.installBlocklet({ url: blockletMetaUrl }, context);
|
|
368
|
+
const tmp = await node.installBlocklet({ url: blockletMetaUrl }, context);
|
|
369
|
+
await node.createAuditLog(
|
|
370
|
+
{
|
|
371
|
+
action: 'installBlocklet',
|
|
372
|
+
args: { url: blockletMetaUrl },
|
|
373
|
+
context: formatContext(Object.assign(req, { user })),
|
|
374
|
+
result: tmp,
|
|
375
|
+
},
|
|
376
|
+
node
|
|
377
|
+
);
|
|
361
378
|
logger.info('start install blocklet', { did });
|
|
362
379
|
};
|
|
363
380
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.7.
|
|
6
|
+
"version": "1.7.12",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.7.
|
|
24
|
-
"@abtnode/logger": "1.7.
|
|
25
|
-
"@abtnode/util": "1.7.
|
|
26
|
-
"@arcblock/did": "^1.16.
|
|
27
|
-
"@arcblock/vc": "^1.16.
|
|
28
|
-
"@blocklet/meta": "1.7.
|
|
29
|
-
"@ocap/client": "1.16.
|
|
30
|
-
"@ocap/mcrypto": "^1.16.
|
|
31
|
-
"@ocap/util": "^1.16.
|
|
32
|
-
"@ocap/wallet": "^1.16.
|
|
23
|
+
"@abtnode/constant": "1.7.12",
|
|
24
|
+
"@abtnode/logger": "1.7.12",
|
|
25
|
+
"@abtnode/util": "1.7.12",
|
|
26
|
+
"@arcblock/did": "^1.16.6",
|
|
27
|
+
"@arcblock/vc": "^1.16.6",
|
|
28
|
+
"@blocklet/meta": "1.7.12",
|
|
29
|
+
"@ocap/client": "1.16.6",
|
|
30
|
+
"@ocap/mcrypto": "^1.16.6",
|
|
31
|
+
"@ocap/util": "^1.16.6",
|
|
32
|
+
"@ocap/wallet": "^1.16.6",
|
|
33
33
|
"axios": "^0.26.1",
|
|
34
34
|
"joi": "^17.6.0",
|
|
35
35
|
"jsonwebtoken": "^8.5.1",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"jest": "^27.4.5"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "afc78b9cb92448676149262fb02432bc256a5524"
|
|
44
44
|
}
|