@5minds/node-red-contrib-processcube 1.5.2-develop-7add47-m2xezg12 → 1.5.2-feature-059ba7-m35qmr4f
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/processcube-engine-config.js +140 -100
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@5minds/node-red-contrib-processcube",
|
3
|
-
"version": "1.5.2-
|
3
|
+
"version": "1.5.2-feature-059ba7-m35qmr4f",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "Node-RED nodes for ProcessCube",
|
6
6
|
"scripts": {
|
@@ -57,7 +57,7 @@
|
|
57
57
|
"examples": "examples"
|
58
58
|
},
|
59
59
|
"dependencies": {
|
60
|
-
"@5minds/processcube_engine_client": "
|
60
|
+
"@5minds/processcube_engine_client": "5.1.0-hotfix-a73235-m346kg1n",
|
61
61
|
"jwt-decode": "^4.0.0",
|
62
62
|
"openid-client": "^5.5.0"
|
63
63
|
},
|
@@ -36,6 +36,46 @@ module.exports = function (RED) {
|
|
36
36
|
}
|
37
37
|
};
|
38
38
|
|
39
|
+
async function getFreshIdentity(url) {
|
40
|
+
console.log('luis777');
|
41
|
+
if (
|
42
|
+
!RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node) ||
|
43
|
+
!RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node)
|
44
|
+
)
|
45
|
+
return null;
|
46
|
+
const res = await fetch(url + '/atlas_engine/api/v1/authority', {
|
47
|
+
method: 'GET',
|
48
|
+
headers: {
|
49
|
+
Authorization: `Bearer ZHVtbXlfdG9rZW4=`,
|
50
|
+
'Content-Type': 'application/json',
|
51
|
+
},
|
52
|
+
});
|
53
|
+
|
54
|
+
const issuer = await oidc.Issuer.discover(await res.json());
|
55
|
+
|
56
|
+
const client = new issuer.Client({
|
57
|
+
client_id: RED.util.evaluateNodeProperty(n.clientId, n.clientIdType, node),
|
58
|
+
client_secret: RED.util.evaluateNodeProperty(n.clientSecret, n.clientSecretType, node),
|
59
|
+
});
|
60
|
+
|
61
|
+
const tokenSet = await client.grant({
|
62
|
+
grant_type: 'client_credentials',
|
63
|
+
scope: 'engine_etw engine_read engine_write',
|
64
|
+
});
|
65
|
+
|
66
|
+
const accessToken = tokenSet.access_token;
|
67
|
+
const decodedToken = jwt.jwtDecode(accessToken);
|
68
|
+
|
69
|
+
const freshIdentity = {
|
70
|
+
token: tokenSet.access_token,
|
71
|
+
userId: decodedToken.sub,
|
72
|
+
};
|
73
|
+
|
74
|
+
configNode.setIdentity(freshIdentity);
|
75
|
+
|
76
|
+
return freshIdentity;
|
77
|
+
}
|
78
|
+
|
39
79
|
node.on('close', async () => {
|
40
80
|
if (this.engineClient) {
|
41
81
|
this.engineClient.dispose();
|
@@ -44,25 +84,25 @@ module.exports = function (RED) {
|
|
44
84
|
});
|
45
85
|
|
46
86
|
if (this.credentials.clientId && this.credentials.clientSecret) {
|
47
|
-
this.engineClient = new engine_client.EngineClient(this.url);
|
48
|
-
|
49
|
-
this.engineClient.applicationInfo
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
87
|
+
this.engineClient = new engine_client.EngineClient(this.url, () => getFreshIdentity(this.url));
|
88
|
+
|
89
|
+
// this.engineClient.applicationInfo
|
90
|
+
// .getAuthorityAddress()
|
91
|
+
// .then((authorityUrl) => {
|
92
|
+
// startRefreshingIdentityCycle(
|
93
|
+
// this.credentials.clientId,
|
94
|
+
// this.credentials.clientSecret,
|
95
|
+
// authorityUrl,
|
96
|
+
// node
|
97
|
+
// ).catch((reason) => {
|
98
|
+
// console.error(reason);
|
99
|
+
// node.error(reason);
|
100
|
+
// });
|
101
|
+
// })
|
102
|
+
// .catch((reason) => {
|
103
|
+
// console.error(reason);
|
104
|
+
// node.error(reason);
|
105
|
+
// });
|
66
106
|
} else {
|
67
107
|
this.engineClient = new engine_client.EngineClient(this.url);
|
68
108
|
}
|
@@ -75,84 +115,84 @@ module.exports = function (RED) {
|
|
75
115
|
});
|
76
116
|
};
|
77
117
|
|
78
|
-
async function getFreshTokenSet(clientId, clientSecret, authorityUrl) {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
93
|
-
|
94
|
-
function getIdentityForExternalTaskWorkers(tokenSet) {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
}
|
103
|
-
|
104
|
-
async function getExpiresInForExternalTaskWorkers(tokenSet) {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
}
|
117
|
-
|
118
|
-
/**
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
async function startRefreshingIdentityCycle(clientId, clientSecret, authorityUrl, configNode) {
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
}
|
118
|
+
// async function getFreshTokenSet(clientId, clientSecret, authorityUrl) {
|
119
|
+
// const issuer = await oidc.Issuer.discover(authorityUrl);
|
120
|
+
|
121
|
+
// const client = new issuer.Client({
|
122
|
+
// client_id: clientId,
|
123
|
+
// client_secret: clientSecret,
|
124
|
+
// });
|
125
|
+
|
126
|
+
// const tokenSet = await client.grant({
|
127
|
+
// grant_type: 'client_credentials',
|
128
|
+
// scope: 'engine_etw engine_read engine_write',
|
129
|
+
// });
|
130
|
+
|
131
|
+
// return tokenSet;
|
132
|
+
// }
|
133
|
+
|
134
|
+
// function getIdentityForExternalTaskWorkers(tokenSet) {
|
135
|
+
// const accessToken = tokenSet.access_token;
|
136
|
+
// const decodedToken = jwt.jwtDecode(accessToken);
|
137
|
+
|
138
|
+
// return {
|
139
|
+
// token: tokenSet.access_token,
|
140
|
+
// userId: decodedToken.sub,
|
141
|
+
// };
|
142
|
+
// }
|
143
|
+
|
144
|
+
// async function getExpiresInForExternalTaskWorkers(tokenSet) {
|
145
|
+
// let expiresIn = tokenSet.expires_in;
|
146
|
+
|
147
|
+
// if (!expiresIn && tokenSet.expires_at) {
|
148
|
+
// expiresIn = Math.floor(tokenSet.expires_at - Date.now() / 1000);
|
149
|
+
// }
|
150
|
+
|
151
|
+
// if (expiresIn === undefined) {
|
152
|
+
// throw new Error('Could not determine the time until the access token for external task workers expires');
|
153
|
+
// }
|
154
|
+
|
155
|
+
// return expiresIn;
|
156
|
+
// }
|
157
|
+
|
158
|
+
// /**
|
159
|
+
// * Start refreshing the identity in regular intervals.
|
160
|
+
// * @param {TokenSet | null} tokenSet The token set to refresh the identity for
|
161
|
+
// * @returns {Promise<void>} A promise that resolves when the timer for refreshing the identity is initialized
|
162
|
+
// * */
|
163
|
+
// async function startRefreshingIdentityCycle(clientId, clientSecret, authorityUrl, configNode) {
|
164
|
+
// let retries = 5;
|
165
|
+
|
166
|
+
// const refresh = async () => {
|
167
|
+
// try {
|
168
|
+
// const newTokenSet = await getFreshTokenSet(clientId, clientSecret, authorityUrl);
|
169
|
+
// const expiresIn = await getExpiresInForExternalTaskWorkers(newTokenSet);
|
170
|
+
// const delay = expiresIn * DELAY_FACTOR * 1000;
|
171
|
+
|
172
|
+
// freshIdentity = getIdentityForExternalTaskWorkers(newTokenSet);
|
173
|
+
|
174
|
+
// configNode.setIdentity(freshIdentity);
|
175
|
+
|
176
|
+
// retries = 5;
|
177
|
+
// setTimeout(refresh, delay);
|
178
|
+
// } catch (error) {
|
179
|
+
// if (retries === 0) {
|
180
|
+
// console.error(
|
181
|
+
// 'Could not refresh identity for external task worker processes. Stopping all external task workers.',
|
182
|
+
// { error }
|
183
|
+
// );
|
184
|
+
// return;
|
185
|
+
// }
|
186
|
+
// console.error('Could not refresh identity for external task worker processes.', {
|
187
|
+
// error,
|
188
|
+
// retryCount: retries,
|
189
|
+
// });
|
190
|
+
// retries--;
|
191
|
+
|
192
|
+
// const delay = 2 * 1000;
|
193
|
+
// setTimeout(refresh, delay);
|
194
|
+
// }
|
195
|
+
// };
|
196
|
+
|
197
|
+
// await refresh();
|
198
|
+
// }
|