@5minds/node-red-contrib-processcube 1.5.2-feature-059ba7-m35qmr4f → 1.5.2-feature-03d546-m361r6u4

Sign up to get free protection for your applications and to get access to all the features.
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-03d546-m361r6u4",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -37,43 +37,48 @@ 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
+ configNode.setIdentity(freshIdentity);
75
+
76
+ return freshIdentity;
77
+ } catch (e) {
78
+ console.log('Could not get fresh identity', e);
79
+ node.error('Could not get fresh identity');
80
+ node.error(e);
81
+ }
77
82
  }
78
83
 
79
84
  node.on('close', async () => {