@5minds/node-red-contrib-processcube 1.5.2-feature-059ba7-m35qmr4f → 1.5.2-feature-95789a-m3625uau

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.5.2-feature-059ba7-m35qmr4f",
3
+ "version": "1.5.2-feature-95789a-m3625uau",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -37,43 +37,50 @@ module.exports = function (RED) {
37
37
  };
38
38
 
39
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;
40
+ try {
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
+ console.log('luis777', freshIdentity);
75
+
76
+ configNode.setIdentity(freshIdentity);
77
+
78
+ return freshIdentity;
79
+ } catch (e) {
80
+ console.log('Could not get fresh identity', e);
81
+ node.error('Could not get fresh identity');
82
+ node.error(e);
83
+ }
77
84
  }
78
85
 
79
86
  node.on('close', async () => {