@abtnode/auth 1.7.17 → 1.7.20
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/invitation.js +76 -0
- package/lib/lost-passport.js +1 -5
- package/package.json +13 -13
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const { WELLKNOWN_SERVICE_PATH_PREFIX } = require('@abtnode/constant');
|
|
2
|
+
const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/meta/lib/constants');
|
|
3
|
+
const { getDisplayName } = require('@blocklet/meta/lib/util');
|
|
4
|
+
const logger = require('@abtnode/logger')(require('../package.json').name);
|
|
5
|
+
const joinUrl = require('url-join');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
init(server, node, { prefix, type } = {}) {
|
|
9
|
+
server.get(`${prefix}/invitation`, async (req, res) => {
|
|
10
|
+
const { inviteId } = req.query;
|
|
11
|
+
const groupPathPrefix = req.headers['x-group-path-prefix'] || '/';
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
let info;
|
|
15
|
+
if (type === 'blocklet') {
|
|
16
|
+
const blockletInfo = await req.getBlocklet();
|
|
17
|
+
info = {
|
|
18
|
+
did: blockletInfo.meta.did,
|
|
19
|
+
appDid: blockletInfo.appDid,
|
|
20
|
+
url: blockletInfo.environmentObj[BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_URL],
|
|
21
|
+
name: getDisplayName(blockletInfo),
|
|
22
|
+
version: blockletInfo.meta.version,
|
|
23
|
+
logo: joinUrl(groupPathPrefix, WELLKNOWN_SERVICE_PATH_PREFIX, '/blocklet/logo'),
|
|
24
|
+
// TODO: 需要将 CHAIN_HOST 纳入标准
|
|
25
|
+
chainHost: blockletInfo.configObj.CHAIN_HOST,
|
|
26
|
+
passportColor: blockletInfo.configObj[BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_PASSPORT_COLOR],
|
|
27
|
+
};
|
|
28
|
+
} else {
|
|
29
|
+
const nodeInfo = await node.getNodeInfo();
|
|
30
|
+
info = {
|
|
31
|
+
did: nodeInfo.did,
|
|
32
|
+
appDid: nodeInfo.did,
|
|
33
|
+
url: '/',
|
|
34
|
+
name: nodeInfo.name,
|
|
35
|
+
version: nodeInfo.version,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const teamDid = info.did;
|
|
40
|
+
const invitations = await node.getInvitations({ teamDid });
|
|
41
|
+
const invitation = invitations.find((v) => v.inviteId === inviteId);
|
|
42
|
+
if (!invitation) {
|
|
43
|
+
res.status(404).send('Invitation not found or invitation has been used');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const roles = await node.getRoles({ teamDid });
|
|
48
|
+
const role = roles.find((v) => v.name === invitation.role);
|
|
49
|
+
try {
|
|
50
|
+
role.permissions = await node.getPermissionsByRole({
|
|
51
|
+
teamDid,
|
|
52
|
+
role: { name: role.name },
|
|
53
|
+
});
|
|
54
|
+
} catch (err) {
|
|
55
|
+
logger.error('failed to get role permission', { teamDid, role: role.name, error: err });
|
|
56
|
+
role.permissions = [];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
res.json({
|
|
60
|
+
...invitation,
|
|
61
|
+
info,
|
|
62
|
+
inviter: {
|
|
63
|
+
did: invitation.inviter.did,
|
|
64
|
+
email: invitation.inviter.email,
|
|
65
|
+
fullName: invitation.inviter.fullName,
|
|
66
|
+
role: invitation.inviter.role,
|
|
67
|
+
},
|
|
68
|
+
role: role || {},
|
|
69
|
+
});
|
|
70
|
+
} catch (err) {
|
|
71
|
+
logger.error('failed to get invitation info', { inviteId, error: err });
|
|
72
|
+
res.status(500).end();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
};
|
package/lib/lost-passport.js
CHANGED
|
@@ -111,11 +111,7 @@ const createLostPassportListRoute = ({ node, type }) => ({
|
|
|
111
111
|
if (x.issuer.id !== issuerDid) {
|
|
112
112
|
return false;
|
|
113
113
|
}
|
|
114
|
-
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return true;
|
|
114
|
+
return !(x.expirationDate && Date.now() > new Date(x.expirationDate).getTime());
|
|
119
115
|
}),
|
|
120
116
|
'name'
|
|
121
117
|
);
|
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.20",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,17 +20,17 @@
|
|
|
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.
|
|
33
|
-
"axios": "^0.
|
|
23
|
+
"@abtnode/constant": "1.7.20",
|
|
24
|
+
"@abtnode/logger": "1.7.20",
|
|
25
|
+
"@abtnode/util": "1.7.20",
|
|
26
|
+
"@arcblock/did": "^1.16.15",
|
|
27
|
+
"@arcblock/vc": "^1.16.15",
|
|
28
|
+
"@blocklet/meta": "1.7.20",
|
|
29
|
+
"@ocap/client": "1.16.15",
|
|
30
|
+
"@ocap/mcrypto": "^1.16.15",
|
|
31
|
+
"@ocap/util": "^1.16.15",
|
|
32
|
+
"@ocap/wallet": "^1.16.15",
|
|
33
|
+
"axios": "^0.27.2",
|
|
34
34
|
"joi": "^17.6.0",
|
|
35
35
|
"jsonwebtoken": "^8.5.1",
|
|
36
36
|
"lodash": "^4.17.21",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"jest": "^27.4.5"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "7e579415aa56cc422f3e26d902cf029fbc92e47a"
|
|
44
44
|
}
|