-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
38 lines (34 loc) · 974 Bytes
/
auth.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// <authInit>
// Create the main MSAL instance
// configuration parameters are located in config.js
const msalClient = new Msal.UserAgentApplication(msalConfig);
if (msalClient.getAccount() && !msalClient.isCallback(window.location.hash)) {
// avoid duplicate code execution on page load in case of iframe and Popup window.
updatePage(msalClient.getAccount(), Views.home);
}
// </authInit>
// <signIn>
async function signIn() {
// Login
try {
await msalClient.loginPopup(loginRequest);
console.log('id_token acquired at: ' + new Date().toString());
if (msalClient.getAccount()) {
updatePage(msalClient.getAccount(), Views.home);
}
} catch (error) {
console.log(error);
updatePage(null, Views.error, {
message: 'Error logging in',
debug: error
});
}
}
// </signIn>
// <signOut>
function signOut() {
msalClient.logout();
}
// </signOut>