@@ -77,6 +77,11 @@ export enum AuthStatus {
77
77
* @version SDK: 1.19.0
78
78
*/
79
79
WAITING_FOR_POPUP = 'WAITING_FOR_POPUP' ,
80
+
81
+ /**
82
+ * Emitted when the SAML popup is closed without authentication
83
+ */
84
+ SAML_POPUP_CLOSED_NO_AUTH = 'SAML_POPUP_CLOSED_NO_AUTH' ,
80
85
}
81
86
82
87
/**
@@ -96,13 +101,13 @@ export interface AuthEventEmitter {
96
101
* @param listener
97
102
*/
98
103
on (
99
- event : AuthStatus . SDK_SUCCESS | AuthStatus . LOGOUT | AuthStatus . WAITING_FOR_POPUP ,
104
+ event : AuthStatus . SDK_SUCCESS | AuthStatus . LOGOUT | AuthStatus . WAITING_FOR_POPUP | AuthStatus . SAML_POPUP_CLOSED_NO_AUTH ,
100
105
listener : ( ) => void ,
101
106
) : this;
102
107
on ( event : AuthStatus . SUCCESS , listener : ( sessionInfo : any ) => void ) : this;
103
108
once ( event : AuthStatus . FAILURE , listener : ( failureType : AuthFailureType ) => void ) : this;
104
109
once (
105
- event : AuthStatus . SDK_SUCCESS | AuthStatus . LOGOUT | AuthStatus . WAITING_FOR_POPUP ,
110
+ event : AuthStatus . SDK_SUCCESS | AuthStatus . LOGOUT | AuthStatus . WAITING_FOR_POPUP | AuthStatus . SAML_POPUP_CLOSED_NO_AUTH ,
106
111
listener : ( ) => void ,
107
112
) : this;
108
113
once ( event : AuthStatus . SUCCESS , listener : ( sessionInfo : any ) => void ) : this;
@@ -364,17 +369,29 @@ export const doBasicAuth = async (embedConfig: EmbedConfig): Promise<boolean> =>
364
369
* @param triggerText
365
370
*/
366
371
async function samlPopupFlow ( ssoURL : string , triggerContainer : DOMSelector , triggerText : string ) {
372
+ let popupClosedCheck : NodeJS . Timeout ;
367
373
const openPopup = ( ) => {
368
374
if ( samlAuthWindow === null || samlAuthWindow . closed ) {
369
375
samlAuthWindow = window . open (
370
376
ssoURL ,
371
377
'_blank' ,
372
378
'location=no,height=570,width=520,scrollbars=yes,status=yes' ,
373
379
) ;
380
+ if ( samlAuthWindow ) {
381
+ popupClosedCheck = setInterval ( ( ) => {
382
+ if ( samlAuthWindow . closed ) {
383
+ clearInterval ( popupClosedCheck ) ;
384
+ if ( samlCompletionPromise && ! samlCompletionResolved ) {
385
+ authEE ?. emit ( AuthStatus . SAML_POPUP_CLOSED_NO_AUTH ) ;
386
+ }
387
+ }
388
+ } , 500 ) ;
389
+ }
374
390
} else {
375
391
samlAuthWindow . focus ( ) ;
376
392
}
377
393
} ;
394
+ let samlCompletionResolved = false ;
378
395
authEE ?. emit ( AuthStatus . WAITING_FOR_POPUP ) ;
379
396
const containerEl = getDOMNode ( triggerContainer ) ;
380
397
if ( containerEl ) {
@@ -386,6 +403,10 @@ async function samlPopupFlow(ssoURL: string, triggerContainer: DOMSelector, trig
386
403
samlCompletionPromise = samlCompletionPromise || new Promise < void > ( ( resolve , reject ) => {
387
404
window . addEventListener ( 'message' , ( e ) => {
388
405
if ( e . data . type === EmbedEvent . SAMLComplete ) {
406
+ samlCompletionResolved = true ;
407
+ if ( popupClosedCheck ) {
408
+ clearInterval ( popupClosedCheck ) ;
409
+ }
389
410
( e . source as Window ) . close ( ) ;
390
411
resolve ( ) ;
391
412
}
0 commit comments