@@ -6,7 +6,8 @@ let username = '';
66
77myMSALObj . addEventCallback ( ( event ) => {
88 if (
9- ( event . eventType === msal . EventType . LOGIN_SUCCESS || event . eventType === msal . EventType . ACQUIRE_TOKEN_SUCCESS ) &&
9+ ( event . eventType === msal . EventType . LOGIN_SUCCESS ||
10+ event . eventType === msal . EventType . ACQUIRE_TOKEN_SUCCESS ) &&
1011 event . payload . account
1112 ) {
1213 const account = event . payload . account ;
@@ -32,11 +33,11 @@ function selectAccount() {
3233 // Add choose account code here
3334 username = myMSALObj . getActiveAccount ( ) . username ;
3435 showWelcomeMessage ( username , currentAccounts ) ;
35- }
36+ }
3637}
3738
3839async function addAnotherAccount ( event ) {
39- if ( event . target . innerHTML . includes ( "@" ) ) {
40+ if ( event . target . innerHTML . includes ( '@' ) ) {
4041 const username = event . target . innerHTML ;
4142 const account = myMSALObj . getAllAccounts ( ) . find ( ( account ) => account . username === username ) ;
4243 const activeAccount = myMSALObj . getActiveAccount ( ) ;
@@ -117,7 +118,7 @@ function signOut() {
117118 const logoutRequest = {
118119 account : account ,
119120 redirectUri : '/redirect' ,
120- mainWindowRedirectUri : '/signout ' ,
121+ mainWindowRedirectUri : '/' ,
121122 } ;
122123 clearStorage ( account ) ;
123124 myMSALObj . logoutPopup ( logoutRequest ) . catch ( ( error ) => {
@@ -126,95 +127,23 @@ function signOut() {
126127}
127128
128129function seeProfile ( ) {
129- const account = myMSALObj . getAccountByUsername ( username ) ;
130- getGraphClient ( {
131- account : account ,
132- scopes : graphConfig . graphMeEndpoint . scopes ,
133- interactionType : msal . InteractionType . Popup ,
134- } )
135- . api ( '/me' )
136- . responseType ( 'raw' )
137- . get ( )
138- . then ( ( response ) => {
139- return handleClaimsChallenge ( account , response , graphConfig . graphMeEndpoint . uri ) ;
140- } )
141- . then ( ( response ) => {
142- if ( response && response . error === 'claims_challenge_occurred' ) throw response . error ;
143- return updateUI ( response , graphConfig . graphMeEndpoint . uri ) ;
144- } )
145- . catch ( ( error ) => {
146- if ( error === 'claims_challenge_occurred' ) {
147- const resource = new URL ( graphConfig . graphMeEndpoint . uri ) . hostname ;
148- const claims =
149- account &&
150- getClaimsFromStorage ( `cc.${ msalConfig . auth . clientId } .${ account . idTokenClaims . oid } .${ resource } ` )
151- ? window . atob (
152- getClaimsFromStorage (
153- `cc.${ msalConfig . auth . clientId } .${ account . idTokenClaims . oid } .${ resource } `
154- )
155- )
156- : undefined ; // e.g {"access_token":{"xms_cc":{"values":["cp1"]}}}
157- let request = {
158- account : account ,
159- scopes : graphConfig . graphMeEndpoint . scopes ,
160- claims : claims ,
161- redirectUri : '/redirect' ,
162- } ;
163-
164- myMSALObj . acquireTokenPopup ( request ) . catch ( ( error ) => {
165- console . log ( error ) ;
166- } ) ;
167- } else {
168- console . log ( error ) ;
169- }
170- } ) ;
130+ callGraph (
131+ username ,
132+ graphConfig . graphMeEndpoint . scopes ,
133+ graphConfig . graphMeEndpoint . uri ,
134+ msal . InteractionType . Popup ,
135+ myMSALObj
136+ ) ;
171137}
172138
173139function readContacts ( ) {
174- const account = myMSALObj . getAccountByUsername ( username ) ;
175- getGraphClient ( {
176- account : account ,
177- scopes : graphConfig . graphContactsEndpoint . scopes ,
178- interactionType : msal . InteractionType . Popup ,
179- } )
180- . api ( '/me/contacts' )
181- . responseType ( 'raw' )
182- . get ( )
183- . then ( ( response ) => {
184- return handleClaimsChallenge ( account , response , graphConfig . graphContactsEndpoint . uri ) ;
185- } )
186- . then ( ( response ) => {
187- if ( response && response . error === 'claims_challenge_occurred' ) throw response . error ;
188- return updateUI ( response , graphConfig . graphContactsEndpoint . uri ) ;
189- } )
190- . catch ( ( error ) => {
191- if ( error === 'claims_challenge_occurred' ) {
192- const resource = new URL ( graphConfig . graphContactsEndpoint . uri ) . hostname ;
193- const claims =
194- account &&
195- getClaimsFromStorage ( `cc.${ msalConfig . auth . clientId } .${ account . idTokenClaims . oid } .${ resource } ` )
196- ? window . atob (
197- getClaimsFromStorage (
198- `cc.${ msalConfig . auth . clientId } .${ account . idTokenClaims . oid } .${ resource } `
199- )
200- )
201- : undefined ; // e.g {"access_token":{"xms_cc":{"values":["cp1"]}}}
202- let request = {
203- account : account ,
204- scopes : graphConfig . graphContactsEndpoint . scopes ,
205- claims : claims ,
206- redirectUri : '/redirect' ,
207- } ;
208-
209- myMSALObj . acquireTokenPopup ( request ) . catch ( ( error ) => {
210- console . log ( error ) ;
211- } ) ;
212- } else if ( error . toString ( ) . includes ( '404' ) ) {
213- return updateUI ( null , graphConfig . graphContactsEndpoint . uri ) ;
214- } else {
215- console . log ( error ) ;
216- }
217- } ) ;
140+ callGraph (
141+ username ,
142+ graphConfig . graphContactsEndpoint . scopes ,
143+ graphConfig . graphContactsEndpoint . uri ,
144+ msal . InteractionType . Popup ,
145+ myMSALObj
146+ ) ;
218147}
219148
220149selectAccount ( ) ;
0 commit comments