Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathauth.js
More file actions
Latest commit
52 lines (44 loc) · 1.4 KB
/
Copy pathauth.js
File metadata and controls
52 lines (44 loc) · 1.4 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
50
51
52
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// <authInitSnippet>
// Create the main MSAL instance
// configuration parameters are located in config.js
constmsalClient=newmsal.PublicClientApplication(msalConfig);
// </authInitSnippet>
// <checkAuthSnippet>
// Check for an already logged-in user
constaccount=msalClient.getActiveAccount();
if(account){
initializeGraphClient(msalClient,account,msalRequest.scopes);
}
// </checkAuthSnippet>
// <signInSnippet>
asyncfunctionsignIn(){
// Login
try{
// Use MSAL to login
constauthResult=awaitmsalClient.loginPopup(msalRequest);
console.log('id_token acquired at: '+newDate().toString());
msalClient.setActiveAccount(authResult.account);
// Initialize the Graph client
initializeGraphClient(msalClient,authResult.account,msalRequest.scopes);
// Get the user's profile from Graph
constuser=awaitgetUser();
// Save the profile in session
sessionStorage.setItem('graphUser',JSON.stringify(user));
updatePage(Views.home);
}catch(error){
console.log(error);
updatePage(Views.error,{
message: 'Error logging in',
debug: error
});
}
}
// </signInSnippet>
// <signOutSnippet>
functionsignOut(){
sessionStorage.removeItem('graphUser');
msalClient.logout();
}
// </signOutSnippet>