-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathgraph.js
64 lines (56 loc) · 2.09 KB
/
graph.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
60
61
62
63
64
// Helper function to call MS Graph API endpoint
// using authorization bearer token scheme
function callMSGraph(endpoint, accessToken, callback) {
const headers = new Headers();
const bearer = `Bearer ${accessToken}`;
headers.append("Authorization", bearer);
const options = {
method: "GET",
headers: headers
};
console.log('request made to Graph API at: ' + new Date().toString());
fetch(endpoint, options)
.then(response => response.json())
.then(response => callback(response, endpoint))
.catch(error => console.log(error));
}
async function seeProfile() {
const currentAcc = myMSALObj.getAccount({accountId});
if (currentAcc) {
const response = await getTokenPopup(loginRequest, currentAcc).catch(error => {
console.log(error);
});
callMSGraph(graphConfig.graphMeEndpoint, response.accessToken, updateUI);
profileButton.style.display = 'none';
}
}
async function readMail() {
const currentAcc = myMSALObj.getAccount({accountId});
if (currentAcc) {
const response = await getTokenPopup(tokenRequest, currentAcc).catch(error => {
console.log(error);
});
callMSGraph(graphConfig.graphMailEndpoint, response.accessToken, updateUI);
mailButton.style.display = 'none';
}
}
async function seeProfileRedirect() {
const currentAcc = myMSALObj.getAccount({accountId});
if (currentAcc) {
const response = await getTokenRedirect(loginRequest, currentAcc).catch(error => {
console.log(error);
});
callMSGraph(graphConfig.graphMeEndpoint, response.accessToken, updateUI);
profileButton.style.display = 'none';
}
}
async function readMailRedirect() {
const currentAcc = myMSALObj.getAccount({accountId});
if (currentAcc) {
const response = await getTokenRedirect(tokenRequest, currentAcc).catch(error => {
console.log(error);
});
callMSGraph(graphConfig.graphMailEndpoint, response.accessToken, updateUI);
mailButton.style.display = 'none';
}
}