@abtnode/auth 1.16.32-beta-820e4cfa → 1.16.32-beta-20240921-020451-c46a81fe
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/connect-to-did-spaces.js +46 -40
- package/package.json +8 -8
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { getAppUrl, getAppName, getAppDescription } = require('@blocklet/meta/lib/util');
|
|
2
2
|
const { Joi } = require('@arcblock/validator');
|
|
3
3
|
const { DID_SPACES } = require('@blocklet/constant');
|
|
4
|
+
const formatError = require('@abtnode/util/lib/format-error');
|
|
4
5
|
const logger = require('./logger');
|
|
5
6
|
const { messages } = require('./auth');
|
|
6
7
|
const { getDidSpacesInfoByClaims, silentAuthorizationInConnect } = require('./util/spaces');
|
|
@@ -25,7 +26,7 @@ function createConnectToDidSpacesRoute(node) {
|
|
|
25
26
|
allowUnknown: true,
|
|
26
27
|
});
|
|
27
28
|
if (error) {
|
|
28
|
-
throw new Error(error);
|
|
29
|
+
throw new Error(error.message);
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
|
|
@@ -50,51 +51,56 @@ function createConnectToDidSpacesRoute(node) {
|
|
|
50
51
|
},
|
|
51
52
|
|
|
52
53
|
onAuth: async ({ claims, challenge, extraParams: { appPid, locale, referrer }, updateSession, request }) => {
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
try {
|
|
55
|
+
/** @type {import('@abtnode/client').BlockletState} */
|
|
56
|
+
const blocklet = request.getBlocklet ? await request.getBlocklet() : await node.getBlocklet({ did: appPid });
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
const existsConnectSpaceClaim = claims.some(
|
|
59
|
+
(x) => x?.meta?.purpose === 'DidSpace' && ['asset', 'verifiableCredential'].includes(x.type)
|
|
60
|
+
);
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
if (!existsConnectSpaceClaim) {
|
|
63
|
+
logger.error('Unable to find claim for DID Spaces', { claims });
|
|
64
|
+
throw new Error('Unable to find claim for DID Spaces');
|
|
65
|
+
}
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
const didSpaceInfo = await getDidSpacesInfoByClaims({ claims });
|
|
68
|
+
const appUrl = getAppUrl(blocklet);
|
|
69
|
+
const { data } = await silentAuthorizationInConnect(didSpaceInfo, {
|
|
70
|
+
appInfo: {
|
|
71
|
+
appDid: blocklet.appDid,
|
|
72
|
+
appName: getAppName(blocklet),
|
|
73
|
+
appDescription: getAppDescription(blocklet),
|
|
74
|
+
appUrl,
|
|
75
|
+
scopes: DID_SPACES.AUTHORIZE.DEFAULT_SCOPE,
|
|
76
|
+
referrer,
|
|
77
|
+
metadata: {
|
|
78
|
+
did: blocklet.meta.did,
|
|
79
|
+
},
|
|
77
80
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
});
|
|
81
|
+
verifyNFTParams: {
|
|
82
|
+
claims,
|
|
83
|
+
challenge,
|
|
84
|
+
locale,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
/**
|
|
89
|
+
* @type {Omit<import('@abtnode/client').SpaceGatewayInput, 'protected'>}
|
|
90
|
+
*/
|
|
91
|
+
const spaceGateway = {
|
|
92
|
+
did: data.did,
|
|
93
|
+
name: data.name,
|
|
94
|
+
endpoint: data.endpoint,
|
|
95
|
+
url: didSpaceInfo.didSpacesCoreUrl,
|
|
96
|
+
};
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
// 两边都要做同样的校验
|
|
99
|
+
await updateSession({ spaceGateway, ...data }, true);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
logger.error('Failed to connect to DID Spaces', error);
|
|
102
|
+
throw new Error(formatError(error));
|
|
103
|
+
}
|
|
98
104
|
},
|
|
99
105
|
};
|
|
100
106
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.32-beta-
|
|
6
|
+
"version": "1.16.32-beta-20240921-020451-c46a81fe",
|
|
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": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.16.32-beta-
|
|
24
|
-
"@abtnode/logger": "1.16.32-beta-
|
|
25
|
-
"@abtnode/util": "1.16.32-beta-
|
|
23
|
+
"@abtnode/constant": "1.16.32-beta-20240921-020451-c46a81fe",
|
|
24
|
+
"@abtnode/logger": "1.16.32-beta-20240921-020451-c46a81fe",
|
|
25
|
+
"@abtnode/util": "1.16.32-beta-20240921-020451-c46a81fe",
|
|
26
26
|
"@arcblock/did": "1.18.135",
|
|
27
27
|
"@arcblock/jwt": "^1.18.135",
|
|
28
28
|
"@arcblock/nft-display": "^2.10.33",
|
|
29
29
|
"@arcblock/validator": "^1.18.135",
|
|
30
30
|
"@arcblock/vc": "1.18.135",
|
|
31
|
-
"@blocklet/constant": "1.16.32-beta-
|
|
32
|
-
"@blocklet/meta": "1.16.32-beta-
|
|
33
|
-
"@blocklet/sdk": "1.16.32-beta-
|
|
31
|
+
"@blocklet/constant": "1.16.32-beta-20240921-020451-c46a81fe",
|
|
32
|
+
"@blocklet/meta": "1.16.32-beta-20240921-020451-c46a81fe",
|
|
33
|
+
"@blocklet/sdk": "1.16.32-beta-20240921-020451-c46a81fe",
|
|
34
34
|
"@ocap/client": "^1.18.135",
|
|
35
35
|
"@ocap/mcrypto": "1.18.135",
|
|
36
36
|
"@ocap/util": "1.18.135",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"jest": "^29.7.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "a1bd9a4a87cd1df28e39894c6817954b0ba7aa5c"
|
|
54
54
|
}
|