@@ -8,59 +8,60 @@ let accessToken;
88myMSALObj . handleRedirectCallback ( authRedirectCallBack ) ;
99
1010function authRedirectCallBack ( error , response ) {
11- if ( error ) {
12- console . log ( error ) ;
11+ if ( error ) {
12+ console . log ( error ) ;
13+ } else {
14+ if ( response . tokenType === "id_token" ) {
15+ console . log ( 'id_token acquired at: ' + new Date ( ) . toString ( ) ) ;
16+ myMSALObj . getAccount ( ) ;
17+ getTokenRedirect ( tokenRequest ) ;
18+ } else if ( response . tokenType === "access_token" ) {
19+ console . log ( 'access_token acquired at: ' + new Date ( ) . toString ( ) ) ;
20+ accessToken = response . accessToken ;
21+ logMessage ( "Request made to Web API:" )
22+ callApiWithAccessToken ( apiConfig . webApi , accessToken )
1323 } else {
14- if ( response . tokenType === "id_token" ) {
15- console . log ( 'id_token acquired at: ' + new Date ( ) . toString ( ) ) ;
16- myMSALObj . getAccount ( ) ;
17- getTokenRedirect ( tokenRequest ) ;
18- } else if ( response . tokenType === "access_token" ) {
19- console . log ( 'access_token acquired at: ' + new Date ( ) . toString ( ) ) ;
20- accessToken = response . accessToken ;
21- logMessage ( "Request made to Web API:" )
22- callApiWithAccessToken ( apiConfig . webApi , accessToken )
23- } else {
24- console . log ( "token type is:" + response . tokenType ) ;
25- }
24+ console . log ( "token type is:" + response . tokenType ) ;
2625 }
26+ }
2727}
2828
2929// Redirect: once login is successful and redirects with tokens, update UI
3030if ( myMSALObj . getAccount ( ) ) {
31- updateUI ( ) ;
31+ updateUI ( ) ;
3232}
3333
3434function signIn ( ) {
35- myMSALObj . loginRedirect ( loginRequest )
35+ myMSALObj . loginRedirect ( loginRequest )
3636}
3737
3838
3939// sign-out the user
4040function logout ( ) {
41- // Removes all sessions, need to call AAD endpoint to do full logout
42- myMSALObj . logout ( ) ;
41+ // Removes all sessions, need to call AAD endpoint to do full logout
42+ myMSALObj . logout ( ) ;
4343}
4444
4545// This function can be removed if you do not need to support IE
4646function getTokenRedirect ( request ) {
4747return myMSALObj . acquireTokenSilent ( request )
48- . then ( ( response ) => {
49- if ( response . accessToken ) {
50- accessToken = response . accessToken
51- logMessage ( "Request made to Web API:" )
52- callApiWithAccessToken ( apiConfig . webApi , accessToken )
53- }
54- } ) . catch ( error => {
55- console . log ( "silent token acquisition fails. acquiring token using redirect" ) ;
56- // fallback to interaction when silent call fails
57- return myMSALObj . acquireTokenRedirect ( request )
58- } ) ;
48+ . then ( ( response ) => {
49+ if ( response . accessToken ) {
50+ accessToken = response . accessToken
51+ logMessage ( "Request made to Web API:" )
52+ callApiWithAccessToken ( apiConfig . webApi , accessToken )
53+ }
54+ } ) . catch ( error => {
55+ console . log ( "silent token acquisition fails. acquiring token using redirect" ) ;
56+ console . log ( error ) ;
57+ // fallback to interaction when silent call fails
58+ return myMSALObj . acquireTokenRedirect ( request )
59+ } ) ;
5960}
6061
6162
6263// calls the resource API with the token
63- function passTokenToAPI ( ) {
64+ function passTokenToApi ( ) {
6465 if ( accessToken === null || accessToken === undefined ) {
6566 getTokenRedirect ( tokenRequest ) ;
6667 } else {
0 commit comments