-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure_create_group.js
51 lines (41 loc) · 1.38 KB
/
azure_create_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
const axios = require('axios');
module.exports = function(RED) {
function azure_create_group(config) {
RED.nodes.createNode(this, config);
var node = this;
node.auth = RED.nodes.getNode(config.auth);
node.on('input', async function(msg) {
if (!node.auth || !node.auth.has_credentials) {
node.error("auth configuration is missing");
return
}
const access_token = await node.auth.get_access_token();
const groupName = msg.group_name;
const group_desc = msg.group_desc;
const headers = {Authorization: 'Bearer ' + access_token, "Content-Type": 'application/json' };
const url = 'https://graph.microsoft.com/v1.0/groups';
const postData = {
description: group_desc,
displayName: groupName,
groupTypes: [],
mailEnabled: false,
mailNickname: 'Authomize_' + groupName,
securityEnabled: true
};
try {
const response = await axios({
method: 'post',
url: url,
headers: headers,
data: postData
});
msg.groupID = response.data.id;
node.send(msg);
} catch (error) {
node.warn(error);
node.warn(error.message);
}
});
}
RED.nodes.registerType("azure_create_group", azure_create_group);
};