-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
49 lines (45 loc) · 1.14 KB
/
api.js
File metadata and controls
49 lines (45 loc) · 1.14 KB
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 request = require('request-promise');
async function authenticating(clientId, clientSecret) {
const options = {
url: 'https://triggerz.eu.auth0.com/oauth/token',
headers: {'content-type': 'application/json'},
body: {
grant_type: 'client_credentials',
client_id: clientId,
client_secret: clientSecret,
audience: 'triggerz.com/api'
},
json: true
};
const response = await request.post(options);
return response.access_token;
}
async function getting(host, endpoint, accessToken) {
const options = {
url: `${host}/api/${endpoint}`,
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${accessToken}`
}
};
const response = await request.get(options);
return response;
}
async function posting(host, endpoint, body, accessToken) {
const options = {
url: `${host}/api/${endpoint}`,
headers: {
'content-type': 'application/json',
'Authorization': `Bearer ${accessToken}`
},
body,
json: true
};
const response = await request.post(options);
return response;
}
module.exports = {
authenticating,
getting,
posting
};