@abtnode/blocklet-services 1.16.0-beta-7a7d5d97 → 1.16.0-beta-b741bcb3
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/api/libs/auth/utils.js +30 -3
- package/api/libs/connect/session.js +48 -38
- package/api/routes/oauth.js +156 -71
- package/build/asset-manifest.json +13 -13
- package/build/index.html +1 -1
- package/build/static/css/{943.60476cc0.chunk.css → 344.d2f73ebf.chunk.css} +1 -1
- package/build/static/js/{343.5125993c.chunk.js → 343.4f9f63d5.chunk.js} +2 -2
- package/build/static/js/{943.eee42740.chunk.js → 344.080c2deb.chunk.js} +3 -3
- package/build/static/js/{663.11e67b21.chunk.js → 648.e478fa43.chunk.js} +3 -3
- package/build/static/js/{712.f88b2e9d.chunk.js → 712.9667cdcd.chunk.js} +3 -2
- package/build/static/js/712.9667cdcd.chunk.js.LICENSE.txt +5 -0
- package/build/static/js/main.2b01fa6f.js +3 -0
- package/build/static/js/{main.9f0c5d12.js.LICENSE.txt → main.2b01fa6f.js.LICENSE.txt} +0 -6
- package/package.json +23 -23
- package/build/static/js/main.9f0c5d12.js +0 -3
- /package/build/static/js/{943.eee42740.chunk.js.LICENSE.txt → 344.080c2deb.chunk.js.LICENSE.txt} +0 -0
- /package/build/static/js/{663.11e67b21.chunk.js.LICENSE.txt → 648.e478fa43.chunk.js.LICENSE.txt} +0 -0
package/api/libs/auth/utils.js
CHANGED
|
@@ -3,9 +3,12 @@ const axios = require('axios');
|
|
|
3
3
|
const logger = require('@abtnode/auth/lib/logger');
|
|
4
4
|
const { getPassportStatusEndpoint, getApplicationInfo } = require('@abtnode/auth/lib/auth');
|
|
5
5
|
const { createPassportVC } = require('@abtnode/auth/lib/passport');
|
|
6
|
-
const { VC_TYPE_NODE_PASSPORT } = require('@abtnode/constant');
|
|
6
|
+
const { VC_TYPE_NODE_PASSPORT, PASSPORT_STATUS } = require('@abtnode/constant');
|
|
7
7
|
const { parseUserAvatar } = require('@abtnode/util/lib/user-avatar');
|
|
8
|
+
const { getBlockletAppIdList } = require('@blocklet/meta/lib/util');
|
|
8
9
|
const pick = require('lodash/pick');
|
|
10
|
+
const uniq = require('lodash/uniq');
|
|
11
|
+
const uniqBy = require('lodash/uniqBy');
|
|
9
12
|
|
|
10
13
|
const { sendToUser } = require('../notification');
|
|
11
14
|
|
|
@@ -39,7 +42,27 @@ async function transferPassport(fromUser, toUser, { req, teamDid, node, nodeInfo
|
|
|
39
42
|
dataDir,
|
|
40
43
|
} = await getApplicationInfo({ node, nodeInfo, teamDid });
|
|
41
44
|
|
|
42
|
-
const
|
|
45
|
+
const blocklet = await req.getBlockletInfo();
|
|
46
|
+
const { wallet: blockletWallet } = blocklet;
|
|
47
|
+
const issuerDidList = uniq([blockletWallet.address, ...getBlockletAppIdList(blocklet)]);
|
|
48
|
+
const waitPassportList = uniqBy(
|
|
49
|
+
(fromUser.passports || []).filter((x) => {
|
|
50
|
+
if (x.status !== PASSPORT_STATUS.VALID) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!issuerDidList.includes(x.issuer.id)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return !(x.expirationDate && Date.now() > new Date(x.expirationDate).getTime());
|
|
58
|
+
}),
|
|
59
|
+
'name'
|
|
60
|
+
);
|
|
61
|
+
if (waitPassportList.length === 0) {
|
|
62
|
+
// 没有待转移的 passport,无需进行下面的步骤
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
43
66
|
const attachments = await Promise.all(
|
|
44
67
|
waitPassportList.map(async (item) => {
|
|
45
68
|
const avatar = await parseUserAvatar(toUser.avatar, { dataDir });
|
|
@@ -73,11 +96,15 @@ async function transferPassport(fromUser, toUser, { req, teamDid, node, nodeInfo
|
|
|
73
96
|
})
|
|
74
97
|
);
|
|
75
98
|
|
|
99
|
+
const passportNameList = attachments.map((x) => x.data.credential.name);
|
|
100
|
+
|
|
76
101
|
await sendToUser(
|
|
77
102
|
toUser.did,
|
|
78
103
|
{
|
|
79
104
|
title: 'Transfer passports',
|
|
80
|
-
body: `
|
|
105
|
+
body: `You received passport ${passportNameList.join(', ')} because you just bind your DID Wallet to ${
|
|
106
|
+
fromUser.email
|
|
107
|
+
}`,
|
|
81
108
|
attachments,
|
|
82
109
|
},
|
|
83
110
|
{ req }
|
|
@@ -34,6 +34,7 @@ const {
|
|
|
34
34
|
const { getKeyPairClaim } = require('@abtnode/auth/lib/server');
|
|
35
35
|
const sortBy = require('lodash/sortBy');
|
|
36
36
|
const last = require('lodash/last');
|
|
37
|
+
const merge = require('lodash/merge');
|
|
37
38
|
|
|
38
39
|
const { getRolesFromAuthConfig, getBlockletAppIdList } = require('@blocklet/meta/lib/util');
|
|
39
40
|
|
|
@@ -544,7 +545,7 @@ module.exports = {
|
|
|
544
545
|
if (bindUser.source === USER_TYPE.DERIVED) {
|
|
545
546
|
throw new Error(t('notWalletAccount'));
|
|
546
547
|
}
|
|
547
|
-
if (bindUser.derivedAccount) {
|
|
548
|
+
if (bindUser.extraConfigs?.derivedAccount) {
|
|
548
549
|
throw new Error(t('alreadyBind'));
|
|
549
550
|
}
|
|
550
551
|
}
|
|
@@ -599,22 +600,32 @@ module.exports = {
|
|
|
599
600
|
const mergePassport = (oauthUser.passports || []).reduce((sum, cur) => {
|
|
600
601
|
return upsertToPassports(sum, cur);
|
|
601
602
|
}, bindUser.passports || []);
|
|
603
|
+
const mergeProfile = merge(profile, {
|
|
604
|
+
email: bindUser.email,
|
|
605
|
+
fullName: bindUser.fullName,
|
|
606
|
+
avatar: bindUser.avatar,
|
|
607
|
+
});
|
|
608
|
+
|
|
602
609
|
// Update bindUser account
|
|
603
610
|
await node.updateUser({
|
|
604
611
|
teamDid,
|
|
605
612
|
user: {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
provider: oauthUser.sourceProvider,
|
|
614
|
-
id: oauthUser.sourceId,
|
|
615
|
-
lastLoginAt: oauthUser.lastLoginAt,
|
|
613
|
+
...mergeProfile,
|
|
614
|
+
extraConfigs: {
|
|
615
|
+
...(bindUser.extraConfigs || {}),
|
|
616
|
+
derivedAccount: {
|
|
617
|
+
provider: oauthUser.extraConfigs?.sourceProvider,
|
|
618
|
+
did: oauthUser.did,
|
|
619
|
+
pk: oauthUser.pk,
|
|
616
620
|
},
|
|
617
|
-
|
|
621
|
+
connectedAccounts: [
|
|
622
|
+
{
|
|
623
|
+
provider: oauthUser.extraConfigs?.sourceProvider,
|
|
624
|
+
id: oauthUser.extraConfigs?.sourceId,
|
|
625
|
+
lastLoginAt: oauthUser.lastLoginAt,
|
|
626
|
+
},
|
|
627
|
+
],
|
|
628
|
+
},
|
|
618
629
|
source: USER_TYPE.WALLET,
|
|
619
630
|
did: userDid,
|
|
620
631
|
pk: userPk,
|
|
@@ -624,13 +635,6 @@ module.exports = {
|
|
|
624
635
|
lastLoginIp: get(request, 'headers[x-real-ip]') || '',
|
|
625
636
|
},
|
|
626
637
|
});
|
|
627
|
-
// FIXME: @zhanghan 将来是否需要移除 derived account
|
|
628
|
-
// await node.removeUser({
|
|
629
|
-
// teamDid,
|
|
630
|
-
// user: {
|
|
631
|
-
// did: previousUserDid,
|
|
632
|
-
// },
|
|
633
|
-
// });
|
|
634
638
|
// TODO: @zhanghan 需要增加 auditLog
|
|
635
639
|
} else {
|
|
636
640
|
const doc = await node.addUser({
|
|
@@ -638,18 +642,20 @@ module.exports = {
|
|
|
638
642
|
user: {
|
|
639
643
|
...profile,
|
|
640
644
|
source: USER_TYPE.WALLET,
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
connectedAccounts: [
|
|
647
|
-
{
|
|
648
|
-
provider: oauthUser.sourceProvider,
|
|
649
|
-
id: oauthUser.sourceId,
|
|
650
|
-
lastLoginAt: oauthUser.lastLoginAt,
|
|
645
|
+
extraConfigs: {
|
|
646
|
+
derivedAccount: {
|
|
647
|
+
provider: oauthUser.extraConfigs?.sourceProvider,
|
|
648
|
+
did: oauthUser.did,
|
|
649
|
+
pk: oauthUser.pk,
|
|
651
650
|
},
|
|
652
|
-
|
|
651
|
+
connectedAccounts: [
|
|
652
|
+
{
|
|
653
|
+
provider: oauthUser.extraConfigs?.sourceProvider,
|
|
654
|
+
id: oauthUser.extraConfigs?.sourceId,
|
|
655
|
+
lastLoginAt: oauthUser.lastLoginAt,
|
|
656
|
+
},
|
|
657
|
+
],
|
|
658
|
+
},
|
|
653
659
|
avatar,
|
|
654
660
|
did: userDid,
|
|
655
661
|
pk: userPk,
|
|
@@ -662,16 +668,20 @@ module.exports = {
|
|
|
662
668
|
},
|
|
663
669
|
});
|
|
664
670
|
bindUser = doc;
|
|
665
|
-
// remove derived account (updateUser use did as key, so did can't be update)
|
|
666
|
-
// FIXME: @zhanghan 将来是否需要移除 derived account
|
|
667
|
-
// await node.removeUser({
|
|
668
|
-
// teamDid,
|
|
669
|
-
// user: {
|
|
670
|
-
// did: previousUserDid,
|
|
671
|
-
// },
|
|
672
|
-
// });
|
|
673
671
|
// TODO: @zhanghan 需要增加 auditLog
|
|
674
672
|
}
|
|
673
|
+
// 更新 oauth 用户记录的绑定信息
|
|
674
|
+
await node.updateUser({
|
|
675
|
+
teamDid,
|
|
676
|
+
user: {
|
|
677
|
+
did: oauthUser.did,
|
|
678
|
+
pk: oauthUser.pk,
|
|
679
|
+
extraConfigs: {
|
|
680
|
+
...(oauthUser.extraConfigs || {}),
|
|
681
|
+
bindDid: userDid,
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
});
|
|
675
685
|
|
|
676
686
|
await transferPassport(oauthUser, bindUser, { req: request, node, nodeInfo, teamDid });
|
|
677
687
|
|
package/api/routes/oauth.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
const { handleInvitationReceive, getApplicationInfo } = require('@abtnode/auth/lib/auth');
|
|
2
|
-
const { upsertToPassports } = require('@abtnode/auth/lib/passport');
|
|
3
|
-
const { WELLKNOWN_SERVICE_PATH_PREFIX, NODE_SERVICES, USER_TYPE } = require('@abtnode/constant');
|
|
2
|
+
const { upsertToPassports, createPassportSvg } = require('@abtnode/auth/lib/passport');
|
|
3
|
+
const { WELLKNOWN_SERVICE_PATH_PREFIX, NODE_SERVICES, USER_TYPE, PASSPORT_STATUS } = require('@abtnode/constant');
|
|
4
4
|
const { parseUserAvatar, extractUserAvatar } = require('@abtnode/util/lib/user-avatar');
|
|
5
5
|
const { types } = require('@arcblock/did');
|
|
6
6
|
const { fromAppDid } = require('@arcblock/did-ext');
|
|
7
|
+
const { getBlockletAppIdList } = require('@blocklet/meta/lib/util');
|
|
8
|
+
const { uniqBy, uniq } = require('lodash');
|
|
7
9
|
const get = require('lodash/get');
|
|
8
10
|
const last = require('lodash/last');
|
|
9
11
|
const pick = require('lodash/pick');
|
|
@@ -106,8 +108,10 @@ async function login(req, node, options) {
|
|
|
106
108
|
teamDid,
|
|
107
109
|
user: {
|
|
108
110
|
source: USER_TYPE.DERIVED,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
extraConfigs: {
|
|
112
|
+
sourceId: userInfo.sub,
|
|
113
|
+
sourceProvider: provider,
|
|
114
|
+
},
|
|
111
115
|
did: userDid,
|
|
112
116
|
pk: userWallet.publicKey,
|
|
113
117
|
fullName: userInfo.nickname,
|
|
@@ -240,35 +244,119 @@ async function invite(req, node, options) {
|
|
|
240
244
|
user: {
|
|
241
245
|
did: bindUser.did,
|
|
242
246
|
pk: bindUser.pk,
|
|
243
|
-
|
|
244
|
-
{
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
extraConfigs: {
|
|
248
|
+
...(bindUser.extraConfigs || {}),
|
|
249
|
+
connectedAccounts: [
|
|
250
|
+
{
|
|
251
|
+
provider: 'auth0',
|
|
252
|
+
id: userInfo.sub,
|
|
253
|
+
lastLoginAt: new Date().toISOString(),
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
},
|
|
250
257
|
},
|
|
251
258
|
});
|
|
252
259
|
} else {
|
|
260
|
+
const currentUserInfo = await node.getUser({ teamDid, user: { did: userDid } });
|
|
253
261
|
await node.updateUser({
|
|
254
262
|
teamDid,
|
|
255
263
|
user: {
|
|
256
264
|
did: userDid,
|
|
257
265
|
pk: userPk,
|
|
266
|
+
extraConfigs: {
|
|
267
|
+
...(currentUserInfo.extraConfigs || {}),
|
|
268
|
+
sourceId: userInfo.sub,
|
|
269
|
+
sourceProvider: 'auth0',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
const { createSessionToken } = initJwt(node, options);
|
|
275
|
+
|
|
276
|
+
const sessionToken = await createSessionToken(userDid, { passport, role });
|
|
277
|
+
return sessionToken;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// eslint-disable-next-line no-unused-vars
|
|
281
|
+
async function bind(req, node, options) {
|
|
282
|
+
const userDid = req.user.did;
|
|
283
|
+
const { token, locale = 'en', provider } = req.body;
|
|
284
|
+
const blocklet = await req.getBlocklet();
|
|
285
|
+
const oauthConfig = blocklet?.settings?.oauth || {};
|
|
286
|
+
const authClient = new AuthenticationClient({
|
|
287
|
+
domain: oauthConfig.auth0.domain,
|
|
288
|
+
});
|
|
289
|
+
const userInfo = await authClient.getProfile(token);
|
|
290
|
+
const { did: teamDid, wallet: blockletWallet } = await req.getBlockletInfo();
|
|
291
|
+
const userWallet = fromAppDid(userInfo.sub, blockletWallet.secretKey, types.RoleType.ROLE_ACCOUNT);
|
|
292
|
+
let oauthUser = await node.getUser({ teamDid, user: { did: userWallet.address } });
|
|
293
|
+
|
|
294
|
+
const bindUser = await node.getUser({ teamDid, user: { did: userDid } });
|
|
295
|
+
|
|
296
|
+
const mergePassport = (oauthUser?.passports || []).reduce((sum, cur) => {
|
|
297
|
+
return upsertToPassports(sum, cur);
|
|
298
|
+
}, bindUser.passports || []);
|
|
299
|
+
|
|
300
|
+
let { avatar } = bindUser;
|
|
301
|
+
if (!avatar) {
|
|
302
|
+
const nodeInfo = await req.getNodeInfo();
|
|
303
|
+
const { dataDir } = await getApplicationInfo({ node, nodeInfo, teamDid });
|
|
304
|
+
avatar = await getAvatarByEmail(userInfo.email);
|
|
305
|
+
avatar = await extractUserAvatar(avatar, { dataDir });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const mergeProfile = {
|
|
309
|
+
fullName: bindUser.fullName || userInfo.nickname,
|
|
310
|
+
email: bindUser.email || userInfo.email,
|
|
311
|
+
avatar,
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
await node.updateUser({
|
|
315
|
+
teamDid,
|
|
316
|
+
user: {
|
|
317
|
+
...mergeProfile,
|
|
318
|
+
did: userDid,
|
|
319
|
+
pk: bindUser.pk,
|
|
320
|
+
locale,
|
|
321
|
+
source: USER_TYPE.WALLET,
|
|
322
|
+
extraConfigs: {
|
|
323
|
+
...(bindUser.extraConfigs || {}),
|
|
324
|
+
derivedAccount: {
|
|
325
|
+
provider,
|
|
326
|
+
did: userWallet.address,
|
|
327
|
+
pk: userWallet.publicKey,
|
|
328
|
+
},
|
|
258
329
|
connectedAccounts: [
|
|
259
330
|
{
|
|
260
|
-
provider
|
|
331
|
+
provider,
|
|
261
332
|
id: userInfo.sub,
|
|
262
333
|
lastLoginAt: new Date().toISOString(),
|
|
263
334
|
},
|
|
264
335
|
],
|
|
265
336
|
},
|
|
337
|
+
passports: mergePassport,
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
if (oauthUser) {
|
|
341
|
+
// 将 oauth 绑定的 did 记录在 oauth 用户的表中
|
|
342
|
+
await node.updateUser({
|
|
343
|
+
teamDid,
|
|
344
|
+
user: {
|
|
345
|
+
did: userWallet.address,
|
|
346
|
+
pk: userWallet.publicKey,
|
|
347
|
+
extraConfigs: {
|
|
348
|
+
...(oauthUser.extraConfigs || {}),
|
|
349
|
+
bindDid: bindUser.did,
|
|
350
|
+
},
|
|
351
|
+
},
|
|
266
352
|
});
|
|
353
|
+
} else {
|
|
354
|
+
oauthUser = {
|
|
355
|
+
did: userWallet.address,
|
|
356
|
+
};
|
|
267
357
|
}
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
const sessionToken = await createSessionToken(userDid, { passport, role });
|
|
271
|
-
return sessionToken;
|
|
358
|
+
const nodeInfo = await req.getNodeInfo();
|
|
359
|
+
await transferPassport(oauthUser, bindUser, { req, node, teamDid, nodeInfo });
|
|
272
360
|
}
|
|
273
361
|
|
|
274
362
|
module.exports = {
|
|
@@ -278,68 +366,65 @@ module.exports = {
|
|
|
278
366
|
const oauthConfig = blocklet?.settings?.oauth || {};
|
|
279
367
|
res.send(oauthConfig);
|
|
280
368
|
});
|
|
281
|
-
|
|
282
|
-
server.post(`${prefix}/bind`, async (req, res) => {
|
|
369
|
+
server.get(`${prefix}/passports`, async (req, res) => {
|
|
283
370
|
const userDid = req.user.did;
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
const
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
});
|
|
290
|
-
const
|
|
291
|
-
const {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
return upsertToPassports(sum, cur);
|
|
299
|
-
}, bindUser.passports || []);
|
|
371
|
+
const blocklet = await req.getBlockletInfo();
|
|
372
|
+
const nodeInfo = await req.getNodeInfo();
|
|
373
|
+
const { did: teamDid, wallet: blockletWallet } = blocklet;
|
|
374
|
+
const { dataDir, passportColor } = await getApplicationInfo({ node, nodeInfo, teamDid });
|
|
375
|
+
const issuerDidList = uniq([blockletWallet.address, ...getBlockletAppIdList(blocklet)]);
|
|
376
|
+
const user = await node.getUser({ teamDid, user: { did: userDid } });
|
|
377
|
+
const ownerAvatarUrl = await parseUserAvatar(user?.avatar, { dataDir });
|
|
378
|
+
const { passports = [] } = user || {};
|
|
379
|
+
// NOTICE: 保持每一种 role 的 passport 只有一个即可
|
|
380
|
+
const passportTypes = uniqBy(
|
|
381
|
+
(passports || []).filter((x) => {
|
|
382
|
+
if (x.status !== PASSPORT_STATUS.VALID) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
300
385
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
],
|
|
320
|
-
passports: mergePassport,
|
|
321
|
-
},
|
|
322
|
-
});
|
|
323
|
-
if (oauthUser) {
|
|
324
|
-
// FIXME: @zhanghan 将来是否需要移除 derived account
|
|
325
|
-
// 删除 oauth 账户
|
|
326
|
-
// await node.removeUser({
|
|
327
|
-
// teamDid,
|
|
328
|
-
// user: {
|
|
329
|
-
// did: userWallet.address,
|
|
330
|
-
// },
|
|
331
|
-
// });
|
|
332
|
-
} else {
|
|
333
|
-
oauthUser = {
|
|
334
|
-
did: userWallet.address,
|
|
386
|
+
if (!issuerDidList.includes(x.issuer.id)) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
return !(x.expirationDate && Date.now() > new Date(x.expirationDate).getTime());
|
|
390
|
+
}),
|
|
391
|
+
'name'
|
|
392
|
+
).map((x) => {
|
|
393
|
+
return {
|
|
394
|
+
...x,
|
|
395
|
+
display: createPassportSvg({
|
|
396
|
+
title: x.title,
|
|
397
|
+
issuer: x.issuer.name,
|
|
398
|
+
issuerDid: x.issuer.id,
|
|
399
|
+
ownerName: user?.fullName,
|
|
400
|
+
ownerAvatarUrl,
|
|
401
|
+
isDataUrl: true,
|
|
402
|
+
preferredColor: passportColor || 'auto',
|
|
403
|
+
}),
|
|
335
404
|
};
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
405
|
+
});
|
|
406
|
+
res.send(passportTypes);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
server.post(`${prefix}/bind`, async (req, res) => {
|
|
410
|
+
await bind(req, node, options);
|
|
339
411
|
// TODO: @zhanghan 需要增加 auditLog
|
|
340
412
|
res.status(200).send('');
|
|
341
413
|
});
|
|
342
414
|
|
|
415
|
+
server.post(`${prefix}/switch`, async (req, res) => {
|
|
416
|
+
const userDid = req.user.did;
|
|
417
|
+
const { did: teamDid } = await req.getBlockletInfo();
|
|
418
|
+
const user = await node.getUser({ teamDid, user: { did: userDid } });
|
|
419
|
+
const { passports = [] } = user || {};
|
|
420
|
+
const { passportId } = req.body;
|
|
421
|
+
const passport = passports.find((item) => item.id === passportId);
|
|
422
|
+
const { createSessionToken } = initJwt(node, options);
|
|
423
|
+
const sessionToken = await createSessionToken(userDid, { passport, role: passport.role });
|
|
424
|
+
// TODO: @zhanghan 需要增加 auditLog
|
|
425
|
+
res.status(200).send(sessionToken);
|
|
426
|
+
});
|
|
427
|
+
|
|
343
428
|
/**
|
|
344
429
|
* oauth 方式登录
|
|
345
430
|
* 1. 普通配置下,登录/注册是同样的流程,登录过程中会自动注册账号
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"main.css": "/.blocklet/proxy/blocklet-service/static/css/main.632501d5.css",
|
|
4
|
-
"main.js": "/.blocklet/proxy/blocklet-service/static/js/main.
|
|
4
|
+
"main.js": "/.blocklet/proxy/blocklet-service/static/js/main.2b01fa6f.js",
|
|
5
5
|
"static/js/716.e1534c42.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/716.e1534c42.chunk.js",
|
|
6
6
|
"static/js/255.279b1bca.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/255.279b1bca.chunk.js",
|
|
7
7
|
"static/js/371.88127b62.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/371.88127b62.chunk.js",
|
|
8
8
|
"static/js/737.ed53dec5.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/737.ed53dec5.chunk.js",
|
|
9
9
|
"static/js/460.3026a774.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/460.3026a774.chunk.js",
|
|
10
10
|
"static/js/868.f2fac071.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/868.f2fac071.chunk.js",
|
|
11
|
-
"static/js/343.
|
|
11
|
+
"static/js/343.4f9f63d5.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/343.4f9f63d5.chunk.js",
|
|
12
12
|
"static/js/682.c64ae291.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/682.c64ae291.chunk.js",
|
|
13
13
|
"static/js/711.6c22b7c7.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/711.6c22b7c7.chunk.js",
|
|
14
14
|
"static/js/437.d815f0c0.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/437.d815f0c0.chunk.js",
|
|
15
15
|
"static/js/690.e2a01dd2.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/690.e2a01dd2.chunk.js",
|
|
16
|
-
"static/js/
|
|
17
|
-
"static/js/712.
|
|
16
|
+
"static/js/648.e478fa43.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/648.e478fa43.chunk.js",
|
|
17
|
+
"static/js/712.9667cdcd.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/712.9667cdcd.chunk.js",
|
|
18
18
|
"static/js/557.5f206c85.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/557.5f206c85.chunk.js",
|
|
19
|
-
"static/css/
|
|
20
|
-
"static/js/
|
|
19
|
+
"static/css/344.d2f73ebf.chunk.css": "/.blocklet/proxy/blocklet-service/static/css/344.d2f73ebf.chunk.css",
|
|
20
|
+
"static/js/344.080c2deb.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/344.080c2deb.chunk.js",
|
|
21
21
|
"static/js/199.53a84333.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/199.53a84333.chunk.js",
|
|
22
22
|
"static/js/573.2687bb44.chunk.js": "/.blocklet/proxy/blocklet-service/static/js/573.2687bb44.chunk.js",
|
|
23
23
|
"static/media/ubuntu-mono-all-400-normal.woff": "/.blocklet/proxy/blocklet-service/static/media/ubuntu-mono-all-400-normal.c879328bc62e9c68268f.woff",
|
|
@@ -42,28 +42,28 @@
|
|
|
42
42
|
"router-template-styles/styles.css": "/.blocklet/proxy/blocklet-service/router-template-styles/styles.css",
|
|
43
43
|
"index.html": "/.blocklet/proxy/blocklet-service/index.html",
|
|
44
44
|
"main.632501d5.css.map": "/.blocklet/proxy/blocklet-service/static/css/main.632501d5.css.map",
|
|
45
|
-
"main.
|
|
45
|
+
"main.2b01fa6f.js.map": "/.blocklet/proxy/blocklet-service/static/js/main.2b01fa6f.js.map",
|
|
46
46
|
"716.e1534c42.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/716.e1534c42.chunk.js.map",
|
|
47
47
|
"255.279b1bca.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/255.279b1bca.chunk.js.map",
|
|
48
48
|
"371.88127b62.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/371.88127b62.chunk.js.map",
|
|
49
49
|
"737.ed53dec5.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/737.ed53dec5.chunk.js.map",
|
|
50
50
|
"460.3026a774.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/460.3026a774.chunk.js.map",
|
|
51
51
|
"868.f2fac071.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/868.f2fac071.chunk.js.map",
|
|
52
|
-
"343.
|
|
52
|
+
"343.4f9f63d5.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/343.4f9f63d5.chunk.js.map",
|
|
53
53
|
"682.c64ae291.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/682.c64ae291.chunk.js.map",
|
|
54
54
|
"711.6c22b7c7.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/711.6c22b7c7.chunk.js.map",
|
|
55
55
|
"437.d815f0c0.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/437.d815f0c0.chunk.js.map",
|
|
56
56
|
"690.e2a01dd2.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/690.e2a01dd2.chunk.js.map",
|
|
57
|
-
"
|
|
58
|
-
"712.
|
|
57
|
+
"648.e478fa43.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/648.e478fa43.chunk.js.map",
|
|
58
|
+
"712.9667cdcd.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/712.9667cdcd.chunk.js.map",
|
|
59
59
|
"557.5f206c85.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/557.5f206c85.chunk.js.map",
|
|
60
|
-
"
|
|
61
|
-
"
|
|
60
|
+
"344.d2f73ebf.chunk.css.map": "/.blocklet/proxy/blocklet-service/static/css/344.d2f73ebf.chunk.css.map",
|
|
61
|
+
"344.080c2deb.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/344.080c2deb.chunk.js.map",
|
|
62
62
|
"199.53a84333.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/199.53a84333.chunk.js.map",
|
|
63
63
|
"573.2687bb44.chunk.js.map": "/.blocklet/proxy/blocklet-service/static/js/573.2687bb44.chunk.js.map"
|
|
64
64
|
},
|
|
65
65
|
"entrypoints": [
|
|
66
66
|
"static/css/main.632501d5.css",
|
|
67
|
-
"static/js/main.
|
|
67
|
+
"static/js/main.2b01fa6f.js"
|
|
68
68
|
]
|
|
69
69
|
}
|
package/build/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"/><meta name="theme-color" content="#000000"/><title>Blocklet Service</title><script src=".well-known/service/api/env"></script><script src="/__blocklet__.js"></script><script defer="defer" src="/.blocklet/proxy/blocklet-service/static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"/><meta name="theme-color" content="#000000"/><title>Blocklet Service</title><script src=".well-known/service/api/env"></script><script src="/__blocklet__.js"></script><script defer="defer" src="/.blocklet/proxy/blocklet-service/static/js/main.2b01fa6f.js"></script><link href="/.blocklet/proxy/blocklet-service/static/css/main.632501d5.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|