Skip to content

Commit 6d6229a

Browse files
committed
minor edits
1 parent bada91c commit 6d6229a

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

2-Authorization-I/1-call-graph/App/authConfig.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ const msalConfig = {
1515
cacheLocation: 'localStorage', // This configures where your cache will be stored
1616
storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge
1717
},
18+
system: {
19+
/**
20+
* Below you can configure MSAL.js logs. For more information, visit:
21+
* https://docs.microsoft.com/azure/active-directory/develop/msal-logging-js
22+
*/
23+
loggerOptions: {
24+
loggerCallback: (level, message, containsPii) => {
25+
if (containsPii) {
26+
return;
27+
}
28+
switch (level) {
29+
case msal.LogLevel.Error:
30+
console.error(message);
31+
return;
32+
case msal.LogLevel.Info:
33+
console.info(message);
34+
return;
35+
case msal.LogLevel.Verbose:
36+
console.debug(message);
37+
return;
38+
case msal.LogLevel.Warning:
39+
console.warn(message);
40+
return;
41+
default:
42+
return;
43+
}
44+
},
45+
},
46+
},
1847
};
1948

2049
// Add here the endpoints for MS Graph API services you would like to use.

2-Authorization-I/1-call-graph/App/authPopup.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ let username = '';
66

77
myMSALObj.addEventCallback((event) => {
88
if (
9-
(event.eventType === 'msal:loginSuccess' || event.eventType === 'msal:acquireTokenSuccess') &&
9+
(event.eventType === msal.EventType.LOGIN_SUCCESS || event.eventType === msal.EventType.ACQUIRE_TOKEN_SUCCESS) &&
1010
event.payload.account
1111
) {
1212
const account = event.payload.account;
1313
myMSALObj.setActiveAccount(account);
1414
}
1515

16-
if (event.eventType === 'msal:logoutSuccess') {
16+
if (event.eventType === msal.EventType.LOGOUT_SUCCESS) {
1717
if (myMSALObj.getAllAccounts().length > 0) {
1818
myMSALObj.setActiveAccount(myMSALObj.getAllAccounts()[0]);
1919
}
@@ -28,19 +28,15 @@ function selectAccount() {
2828
const currentAccounts = myMSALObj.getAllAccounts();
2929
if (currentAccounts === null) {
3030
return;
31-
} else if (currentAccounts.length > 1) {
31+
} else if (currentAccounts.length >= 1) {
3232
// Add choose account code here
33-
console.warn('Multiple accounts detected.');
3433
username = myMSALObj.getActiveAccount().username;
3534
showWelcomeMessage(username, currentAccounts);
36-
} else if (currentAccounts.length === 1) {
37-
username = myMSALObj.getActiveAccount().username;
38-
showWelcomeMessage(username, currentAccounts);
39-
}
35+
}
4036
}
4137

4238
async function addAnotherAccount(event) {
43-
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(event.target.innerHTML)) {
39+
if (event.target.innerHTML.includes("@")) {
4440
const username = event.target.innerHTML;
4541
const account = myMSALObj.getAllAccounts().find((account) => account.username === username);
4642
const activeAccount = myMSALObj.getActiveAccount();
@@ -51,6 +47,7 @@ async function addAnotherAccount(event) {
5147
...loginRequest,
5248
account: account,
5349
});
50+
closeModal();
5451
handleResponse(res);
5552
window.location.reload();
5653
} catch (error) {
@@ -75,6 +72,7 @@ async function addAnotherAccount(event) {
7572
});
7673
handleResponse(res);
7774
closeModal();
75+
window.location.reload();
7876
} catch (error) {
7977
console.log(error);
8078
}

2-Authorization-I/1-call-graph/App/authRedirect.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ let username = '';
77

88
myMSALObj.addEventCallback((event) => {
99
if (
10-
(event.eventType === 'msal:loginSuccess' || event.eventType === 'msal:acquireTokenSuccess') &&
10+
(event.eventType === msal.EventType.LOGIN_SUCCESS ||
11+
event.eventType === msal.EventType.ACQUIRE_TOKEN_SUCCESS) &&
1112
event.payload.account
1213
) {
1314
const account = event.payload.account;
1415
myMSALObj.setActiveAccount(account);
1516
}
1617

17-
if (event.eventType === 'msal:logoutSuccess') {
18+
if (event.eventType === msal.EventType.LOGOUT_SUCCESS) {
1819
if (myMSALObj.getAllAccounts().length > 0) {
1920
myMSALObj.setActiveAccount(myMSALObj.getAllAccounts()[0]);
2021
}
@@ -43,19 +44,15 @@ function selectAccount() {
4344

4445
if (!currentAccounts) {
4546
return;
46-
} else if (currentAccounts.length > 1) {
47+
} else if (currentAccounts.length >= 1) {
4748
// Add your account choosing logic here
48-
console.warn('Multiple accounts detected.');
4949
username = myMSALObj.getActiveAccount().username;
5050
showWelcomeMessage(username, currentAccounts);
51-
} else if (currentAccounts.length === 1) {
52-
username = myMSALObj.getActiveAccount().username;
53-
showWelcomeMessage(username, currentAccounts);
54-
}
51+
}
5552
}
5653

5754
async function addAnotherAccount(event) {
58-
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(event.target.innerHTML)) {
55+
if (event.target.innerHTML.includes("@")) {
5956
const username = event.target.innerHTML;
6057
const account = myMSALObj.getAllAccounts().find((account) => account.username === username);
6158
const activeAccount = myMSALObj.getActiveAccount();
@@ -67,10 +64,11 @@ async function addAnotherAccount(event) {
6764
account: account,
6865
});
6966
handleResponse(res);
67+
closeModal();
7068
window.location.reload();
7169
} catch (error) {
7270
if (error instanceof msal.InteractionRequiredAuthError) {
73-
await instance.loginRedirect({
71+
await myMSALObj.loginRedirect({
7472
...loginRequest,
7573
prompt: 'login',
7674
});

0 commit comments

Comments
 (0)