-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathokta_suspend_user.js
49 lines (41 loc) · 1.42 KB
/
okta_suspend_user.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
const axios = require('axios');
module.exports = function(RED) {
function okta_suspend_user(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function(msg) {
node.auth = RED.nodes.getNode(config.auth);
if (!node.auth || !node.auth.has_credentials) {
node.error("auth configuration is missing");
return
}
const userID = RED.util.evaluateNodeProperty(
config.userID, config.userIDType, node, msg
)
const userName = RED.util.evaluateNodeProperty(
config.userName, config.userNameType, node, msg
)
const {apiKey, oktaDomain} = config.auth;
try{
const userID = msg.payload.data.entities[0].originId;
const userName = msg.payload.data.entities[0].email;
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'SSWS ' + apiKey
};
const url = 'https://' + oktaDomain + '.okta.com/api/v1/users/' + userID + '/lifecycle/suspend';
axios.post(url, {}, { headers }).then(response => {
node.warn(userName + ' (id: ' + userID + ') was suspended');
node.send(msg);
})
.catch(error => {
node.warn(error);
});
} catch(error) {
node.warn(error);
}
});
}
RED.nodes.registerType("okta_suspend_user", okta_suspend_user);
};