Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fix(authentication): close inline token auth popup when admitted to conference
damencho8634d55c750e
diff --git a/react/features/authentication/actions.native.ts b/react/features/authentication/actions.native.tsindex 2fded32359..4b1bc2944f 100644--- a/react/features/authentication/actions.native.ts+++ b/react/features/authentication/actions.native.ts@@ -98,3 +98,12 @@ export function openTokenAuthUrl(tokenAuthServiceUrl: string) {export function loginWithPopup(tokenAuthServiceUrl: string): Promise<any> {return Promise.resolve(tokenAuthServiceUrl);}++/**+ * Not used. There is no inline login popup on native.+ *+ * @returns {void}+ */+export function closeLoginPopup() {+ // No-op on native.+}diff --git a/react/features/authentication/actions.web.ts b/react/features/authentication/actions.web.tsindex 8c741b649f..afc9c7d509 100644--- a/react/features/authentication/actions.web.ts+++ b/react/features/authentication/actions.web.ts@@ -30,6 +30,27 @@ class PopupBlockedError extends Error {}}+/**+ * Custom error thrown when a pending inline login popup is closed+ * programmatically (e.g. the participant is admitted to the conference while+ * the popup is still open), as opposed to failing to authenticate.+ */+class LoginCancelledError extends Error {+ constructor(message: string = 'Login cancelled') {+ super(message);+ this.name = 'LoginCancelledError';+ Error.captureStackTrace(this, LoginCancelledError);+ }+}++/**+ * Holds a function that closes the currently open inline login popup (if any)+ * and settles its pending promise. It is set while a popup is open and cleared+ * once the popup is closed, so it can be used to dismiss the popup when it is no+ * longer needed (e.g. when the participant is admitted to the conference).+ */+let closeActiveLoginPopup: (() => void) | undefined;+/*** Cancels {@ink LoginDialog}.*@@ -142,6 +163,7 @@ export function loginWithPopup(tokenAuthServiceUrl: string, popup?: Window | nulwindow.removeEventListener('message', handler);clearInterval(closedPollInterval);popup?.close();+ closeActiveLoginPopup = undefined;try {sessionStorage.removeItem('oauth_nonce');@@ -179,6 +201,14 @@ export function loginWithPopup(tokenAuthServiceUrl: string, popup?: Window | nul// Listen for messages from the popupwindow.addEventListener('message', handler);+ // Expose a way to close this popup externally, so it can be dismissed+ // when it is no longer needed (e.g. the participant was admitted to the+ // conference while the popup was still open).+ closeActiveLoginPopup = () => {+ cleanup(handler);+ reject(new LoginCancelledError());+ };+// Detect manual popup close before authentication completesclosedPollInterval = setInterval(() => {if (popup?.closed) {@@ -220,6 +250,17 @@ export function silentLogout(tokenAuthLogoutServiceUrl: string): any {});}+/**+ * Closes the currently open inline login popup (if any) and settles its pending+ * promise. Used to dismiss the popup when it is no longer needed, e.g. when the+ * participant is admitted to the conference while the popup is still open.+ *+ * @returns {void}+ */+export function closeLoginPopup() {+ closeActiveLoginPopup?.();+}+/*** Opens token auth URL page.*@@ -285,14 +326,19 @@ export function openTokenAuthUrl(tokenAuthServiceUrl: string): any {} ],appearance: NOTIFICATION_TYPE.ERROR}, NOTIFICATION_TIMEOUT_TYPE.STICKY));-+ logger.error(err);+ } else if (err instanceof LoginCancelledError) {+ // The popup was closed programmatically (e.g. we were+ // admitted to the conference while it was still open); this+ // is not an authentication failure, so nothing to report.+ logger.info('Inline login popup closed:', err.message);} else {// let's add expand that will show the error message in the notificationdispatch(showErrorNotification({titleKey: 'dialog.loginFailed'}));+ logger.error(err);}- logger.error(err);});return;diff --git a/react/features/authentication/middleware.ts b/react/features/authentication/middleware.tsindex b5ed47c766..2e094a4067 100644--- a/react/features/authentication/middleware.ts+++ b/react/features/authentication/middleware.ts@@ -26,6 +26,7 @@ import {WAIT_FOR_OWNER} from './actionTypes';import {+ closeLoginPopup,disableModeratorLogin,enableModeratorLogin,hideLoginDialog,@@ -132,6 +133,12 @@ MiddlewareRegistry.register(store => next => action => {dispatch(stopWaitForOwner());}dispatch(hideLoginDialog());++ // We may have been admitted to the conference while an inline token+ // auth popup was still open (e.g. an authenticated participant joined+ // and the backend let us in automatically). Dismiss the popup so it+ // doesn't linger on top of the conference.+ closeLoginPopup();break;}