@@ -43,7 +43,7 @@ interface AuthorizeService {
43
43
completeSignOut ( url : string ) : Promise < AuthenticationResult > ;
44
44
}
45
45
46
- // These are the values for the .NET logger LogLevel.
46
+ // These are the values for the .NET logger LogLevel.
47
47
// We only use debug and trace
48
48
export enum LogLevel {
49
49
Trace = 0 ,
@@ -71,7 +71,7 @@ export class Logger {
71
71
// Logs in the following format to keep consistency with the way ASP.NET Core logs to the console while avoiding the
72
72
// additional overhead of passing the logger as a JSObjectReference
73
73
// dbug: Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService[0]
74
- // <<message>>
74
+ // <<message>>
75
75
// trce: Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService[0]
76
76
// <<message>>
77
77
`${ levelString } : Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationService[0]
@@ -279,12 +279,12 @@ class MsalAuthorizeService implements AuthorizeService {
279
279
280
280
private async signInWithPopup ( request : Msal . PopupRequest ) {
281
281
try {
282
- this . debug ( 'Starting sign-in pop-up' ) ;
282
+ this . debug ( 'Starting sign-in pop-up. ' ) ;
283
283
return await this . _msalApplication . loginPopup ( request ) ;
284
284
} catch ( e ) {
285
285
// If the user explicitly cancelled the pop-up, avoid performing a redirect.
286
286
if ( this . isMsalError ( e ) && e . errorCode !== Msal . BrowserAuthErrorMessage . userCancelledError . code ) {
287
- this . debug ( 'User canceled sign-in pop-up' ) ;
287
+ this . debug ( 'User canceled sign-in pop-up. ' ) ;
288
288
this . signInWithRedirect ( request ) ;
289
289
} else {
290
290
this . debug ( `Sign-in pop-up failed: '${ ( e as Error ) . message } '.` ) ;
@@ -327,15 +327,62 @@ class MsalAuthorizeService implements AuthorizeService {
327
327
} ;
328
328
this . trace ( 'signOut-Request' , request ) ;
329
329
330
- await this . _msalApplication . logoutRedirect ( request ) ;
330
+ const result = await this . signOutCore ( request ) ;
331
+ this . trace ( 'signOut-Response' , result ) ;
332
+ if ( ! result ) {
333
+ return this . redirect ( ) ;
334
+ } else if ( this . isMsalError ( result ) ) {
335
+ return this . error ( result . errorMessage ) ;
336
+ }
331
337
332
- // We are about to be redirected.
333
- return this . redirect ( ) ;
338
+ return this . success ( state ) ;
334
339
} catch ( e ) {
340
+ const message = ( e as Error ) . message ;
341
+ this . debug ( `Sign out error '${ message } '` ) ;
335
342
return this . error ( ( e as Error ) . message ) ;
336
343
}
337
344
}
338
345
346
+ async signOutCore ( request : Partial < Msal . EndSessionRequest > ) : Promise < Msal . AuthenticationResult | Msal . AuthError | undefined > {
347
+ this . trace ( 'signOut-Request' , request ) ;
348
+ const loginMode = this . _settings . loginMode . toLowerCase ( ) ;
349
+ // shouldn't both calls await?
350
+ if ( loginMode == 'redirect' ) {
351
+ return this . signOutWithRedirect ( request as Msal . EndSessionRequest ) ;
352
+ } else {
353
+ return this . signOutWithPopup ( request as Msal . EndSessionPopupRequest ) ;
354
+ }
355
+ }
356
+
357
+ private async signOutWithRedirect ( request : Msal . EndSessionRequest ) {
358
+ try {
359
+ this . debug ( 'Starting sign-out redirect.' ) ;
360
+ return await this . _msalApplication . logoutRedirect ( request )
361
+ } catch ( e ) {
362
+ this . debug ( `Sing-out redirect failed: '${ ( e as Error ) . message } '` )
363
+ return e as any ;
364
+ }
365
+ }
366
+
367
+ private async signOutWithPopup ( request : Msal . EndSessionPopupRequest ) {
368
+ try {
369
+ this . debug ( 'Starting sign-out pop-up.' ) ;
370
+ return await this . _msalApplication . logoutPopup ( request ) ;
371
+ }
372
+ catch ( e ) {
373
+ // If the user explicitly cancelled the pop-up, avoid performing a redirect.
374
+ if ( this . isMsalError ( e ) && e . errorCode !== Msal . BrowserAuthErrorMessage . userCancelledError . code ) {
375
+ this . debug ( "User cancelled sign-out pop-up." ) ;
376
+ // shouldn't we await here? as well in signInWithPopup's fallback.
377
+ this . signOutWithRedirect ( request ) ;
378
+ }
379
+ else {
380
+ this . debug ( `Sign-out pop-up failed: '${ ( e as Error ) . message } '` ) ;
381
+ return e as any ;
382
+ }
383
+ }
384
+ }
385
+
339
386
async completeSignOut ( url : string ) {
340
387
this . trace ( 'completeSignOut-request' , url ) ;
341
388
try {
0 commit comments