-
Notifications
You must be signed in to change notification settings - Fork 1
/
okta_list_group.js
59 lines (48 loc) · 1.62 KB
/
okta_list_group.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module.exports = function(RED) {
function okta_list_group_Node(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function(msg) {
const https = require('https');
node.auth = RED.nodes.getNode(config.auth);
if (!node.auth || !node.auth.has_credentials) {
node.error("auth configuration is missing");
return
}
const {apiKey, oktaDomain} = config.auth;
const groupID = RED.util.evaluateNodeProperty(
config.groupID, config.userIDType, node, msg
)
const options = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'SSWS ' + apiKey
}
};
const url = 'https://' + oktaDomain + '.okta.com/api/v1/groups/' + groupID + '/users';
const req = https.get(url, options, (res) => {
let rawData = '';
users = [];
res.on('data', (chunk) => {
rawData += chunk;
});
res.on('end', () => {
try {
const parsedData = JSON.parse(rawData);
const ids = parsedData.map(item => item.id);
msg.okta_group_ids = ids;
node.send(msg);
} catch (error) {
node.error(error);
}
});
req.on('error', (error) => {
node.warn(error);
});
req.end();
});
});
}
RED.nodes.registerType("okta_list_group", okta_list_group_Node);
};