Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(authentication): warn when an external login is abandoned on mobile

Andrii Martyniukce3871e1d766
diff --git a/lang/main.json b/lang/main.json
index bb24fd2475..187489baec 100644
--- a/lang/main.json
+++ b/lang/main.json
@@ -418,6 +418,7 @@
"lockTitle": "Lock failed",
"login": "Login",
"loginFailed": "Login failed.",
+ "loginNotCompleted": "Login was not completed, so you are not connected to this meeting.",
"loginOnResume": "Your authentication session has expired. You need to login again to continue the meeting.",
"loginPopupBlocked": "Login popup was blocked by your browser.",
"loginQuestion": "Are you sure you want to login and leave the conference?",
diff --git a/react/features/authentication/actionTypes.ts b/react/features/authentication/actionTypes.ts
index 0749587d69..0795b07b59 100644
--- a/react/features/authentication/actionTypes.ts
+++ b/react/features/authentication/actionTypes.ts
@@ -26,6 +26,18 @@ export const LOGIN = 'LOGIN';
*/
export const LOGOUT = 'LOGOUT';
+/**
+ * The type of (redux) action which signals that an external token
+ * authentication (started by opening {@code tokenAuthUrl} in the system
+ * browser) is pending or has finished. Native only.
+ *
+ * {
+ * type: SET_TOKEN_AUTH_PENDING,
+ * pending: boolean
+ * }
+ */
+export const SET_TOKEN_AUTH_PENDING = 'SET_TOKEN_AUTH_PENDING';
+
/**
* The type of (redux) action which signals that the cyclic operation of waiting
* for conference owner has been aborted.
diff --git a/react/features/authentication/actions.native.ts b/react/features/authentication/actions.native.ts
index 4b1bc2944f..be2bd998c1 100644
--- a/react/features/authentication/actions.native.ts
+++ b/react/features/authentication/actions.native.ts
@@ -4,10 +4,13 @@ import { appNavigate } from '../app/actions.native';
import { IStore } from '../app/types';
import { conferenceLeft } from '../base/conference/actions';
import { connectionFailed } from '../base/connection/actions.native';
+import { hideDialog, openDialog } from '../base/dialog/actions';
import { set } from '../base/redux/functions';
-import { CANCEL_LOGIN } from './actionTypes';
+import { CANCEL_LOGIN, SET_TOKEN_AUTH_PENDING } from './actionTypes';
import { stopWaitForOwner } from './actions.any';
+import LoginRetryDialog from './components/native/LoginRetryDialog';
+import logger from './logger';
export * from './actions.any';
@@ -67,6 +70,25 @@ export function cancelWaitForOwner() {
};
}
+/**
+ * Hides {@link LoginRetryDialog}.
+ *
+ * @returns {Action}
+ */
+export function hideLoginRetryDialog() {
+ return hideDialog('LoginRetryDialog', LoginRetryDialog);
+}
+
+/**
+ * Opens {@link LoginRetryDialog} which warns the user that they are not
+ * connected to the meeting because the external login was not completed.
+ *
+ * @returns {Action}
+ */
+export function openLoginRetryDialog() {
+ return openDialog('LoginRetryDialog', LoginRetryDialog);
+}
+
/**
* Redirect to the default location (e.g. Welcome page).
*
@@ -76,6 +98,25 @@ export function redirectToDefaultLocation() {
return (dispatch: IStore['dispatch']) => dispatch(appNavigate(undefined));
}
+/**
+ * Sets whether an external token authentication (started by opening
+ * {@code tokenAuthUrl} in the system browser) is pending. While the flag is
+ * set, returning to the foreground without a connection means the login was
+ * abandoned and {@link LoginRetryDialog} is shown.
+ *
+ * @param {boolean} pending - Whether the external login is pending.
+ * @returns {{
+ * type: SET_TOKEN_AUTH_PENDING,
+ * pending: boolean
+ * }}
+ */
+export function setTokenAuthPending(pending: boolean) {
+ return {
+ type: SET_TOKEN_AUTH_PENDING,
+ pending
+ };
+}
+
/**
* Opens token auth URL page.
*
@@ -84,8 +125,19 @@ export function redirectToDefaultLocation() {
* @returns {Function}
*/
export function openTokenAuthUrl(tokenAuthServiceUrl: string) {
- return () => {
- Linking.openURL(tokenAuthServiceUrl);
+ return (dispatch: IStore['dispatch']) => {
+ dispatch(setTokenAuthPending(true));
+
+ // Show the dialog right away, behind the browser: if the login is
+ // completed, the deep link triggers a new connection attempt which
+ // dismisses it; if the login is abandoned, it is what the user finds
+ // when they return. The app may be put into picture-in-picture while
+ // the browser is up, in which case no AppState change is emitted on
+ // return, so the dialog cannot be reliably shown at that point.
+ dispatch(openLoginRetryDialog());
+
+ Linking.openURL(tokenAuthServiceUrl)
+ .catch(error => logger.error('Failed to open token auth URL', error));
};
}
diff --git a/react/features/authentication/components/native/LoginRetryDialog.tsx b/react/features/authentication/components/native/LoginRetryDialog.tsx
new file mode 100644
index 0000000000..6e1d8ba3ad
--- /dev/null
+++ b/react/features/authentication/components/native/LoginRetryDialog.tsx
@@ -0,0 +1,42 @@
+import React, { useCallback } from 'react';
+import { useDispatch } from 'react-redux';
+
+import ConfirmDialog from '../../../base/dialog/components/native/ConfirmDialog';
+import { cancelLogin, login, redirectToDefaultLocation } from '../../actions.native';
+
+/**
+ * Dialog shown when the app returns to the foreground while an external token
+ * authentication (started by opening {@code tokenAuthUrl} in the system
+ * browser) was not completed. It warns the user that they are not connected
+ * to the meeting and offers to either retry the login or leave.
+ *
+ * @returns {JSX.Element}
+ */
+export default function LoginRetryDialog(): JSX.Element {
+ const dispatch = useDispatch();
+ const handleSubmit = useCallback(() => {
+ dispatch(login());
+
+ return true; // close dialog
+ }, [ dispatch ]);
+ const handleCancel = useCallback(() => {
+ dispatch(cancelLogin());
+
+ // cancelLogin() only navigates away when the connection is still
+ // parked on passwordRequired; on WebSocket deployments that state is
+ // reset by the subsequent connection-dropped failure, so leave the
+ // dead conference screen explicitly.
+ dispatch(redirectToDefaultLocation());
+
+ return true; // close dialog
+ }, [ dispatch ]);
+
+ return (
+ <ConfirmDialog
+ cancelLabel = 'toolbar.leaveConference'
+ confirmLabel = 'dialog.login'
+ descriptionKey = 'dialog.loginNotCompleted'
+ onCancel = { handleCancel }
+ onSubmit = { handleSubmit } />
+ );
+}
diff --git a/react/features/authentication/middleware.ts b/react/features/authentication/middleware.any.ts
similarity index 100%
rename from react/features/authentication/middleware.ts
rename to react/features/authentication/middleware.any.ts
diff --git a/react/features/authentication/middleware.native.ts b/react/features/authentication/middleware.native.ts
new file mode 100644
index 0000000000..33fcc20628
--- /dev/null
+++ b/react/features/authentication/middleware.native.ts
@@ -0,0 +1,84 @@
+import { CONNECTION_ESTABLISHED, CONNECTION_WILL_CONNECT } from '../base/connection/actionTypes';
+import { isDialogOpen } from '../base/dialog/functions';
+import { SET_JWT } from '../base/jwt/actionTypes';
+import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
+import { APP_STATE_CHANGED } from '../mobile/background/actionTypes';
+
+import { hideLoginRetryDialog, openLoginRetryDialog, setTokenAuthPending } from './actions.native';
+import LoginRetryDialog from './components/native/LoginRetryDialog';
+import { isTokenAuthEnabled } from './functions.native';
+
+import './middleware.any';
+
+/**
+ * Middleware that detects the app returning to the foreground while an
+ * external token authentication is still pending and warns the user that they
+ * are not connected to the meeting.
+ *
+ * Opening {@code tokenAuthUrl} in the system browser is fire-and-forget: if
+ * the user abandons the login page and switches back to the app, no deep link
+ * is ever delivered and the app keeps showing the conference screen with no
+ * connection and no indication of failure. The pending state is tracked with
+ * an explicit flag (set when the browser is opened, cleared when a new
+ * connection attempt starts) because the connection-level error state cannot
+ * be relied upon: on WebSocket deployments the not-authorized failure is
+ * immediately followed by a connection-dropped failure which resets it.
+ *
+ * @param {Store} store - The redux store.
+ * @returns {Function}
+ */
+MiddlewareRegistry.register(store => next => action => {
+ switch (action.type) {
+ case APP_STATE_CHANGED: {
+ if (action.appState !== 'active') {
+ break;
+ }
+
+ const state = store.getState();
+ const { tokenAuthPending } = state['features/authentication'];
+ const { conference, room } = state['features/base/conference'];
+ const { jwt } = state['features/base/jwt'];
+
+ // The app is back in the foreground on the conference screen with the
+ // external login still pending: no conference was joined and no JWT
+ // has been delivered via a deep link, so the login was abandoned and
+ // the app is not connected.
+ if (tokenAuthPending
+ && room
+ && !conference
+ && !jwt
+ && isTokenAuthEnabled(state)
+ && !isDialogOpen(store, LoginRetryDialog)) {
+ store.dispatch(openLoginRetryDialog());
+ }
+ break;
+ }
+
+ case SET_JWT:
+ // SET_JWT with no token is the periodic clearing that happens on
+ // every navigation; only a delivered token completes the login.
+ if (!action.jwt) {
+ break;
+ }
+
+ // eslint-disable-next-line no-fallthrough
+ case CONNECTION_ESTABLISHED:
+ case CONNECTION_WILL_CONNECT: {
+ // The external login is no longer pending once the deep link delivers
+ // a JWT (the room may first land on the prejoin screen, where no
+ // connection attempt is started yet) or a new connection attempt
+ // starts.
+ const { dispatch, getState } = store;
+
+ if (getState()['features/authentication'].tokenAuthPending) {
+ dispatch(setTokenAuthPending(false));
+ }
+ if (isDialogOpen(store, LoginRetryDialog)) {
+ dispatch(hideLoginRetryDialog());
+ }
+ break;
+ }
+ }
+
+ return next(action);
+});
diff --git a/react/features/authentication/middleware.web.ts b/react/features/authentication/middleware.web.ts
new file mode 100644
index 0000000000..fefd329e8a
--- /dev/null
+++ b/react/features/authentication/middleware.web.ts
@@ -0,0 +1 @@
+import './middleware.any';
diff --git a/react/features/authentication/reducer.ts b/react/features/authentication/reducer.ts
index 886f7bd988..70f258f66c 100644
--- a/react/features/authentication/reducer.ts
+++ b/react/features/authentication/reducer.ts
@@ -5,6 +5,7 @@ import {
CANCEL_LOGIN,
DISABLE_MODERATOR_LOGIN,
ENABLE_MODERATOR_LOGIN,
+ SET_TOKEN_AUTH_PENDING,
STOP_WAIT_FOR_OWNER,
UPGRADE_ROLE_FINISHED,
UPGRADE_ROLE_STARTED,
@@ -18,6 +19,7 @@ export interface IAuthenticationState {
thenableWithCancel?: {
cancel: Function;
};
+ tokenAuthPending?: boolean;
waitForOwnerTimeoutID?: number;
}
@@ -36,7 +38,13 @@ ReducerRegistry.register<IAuthenticationState>('features/authentication',
return assign(state, {
error: undefined,
progress: undefined,
- thenableWithCancel: undefined
+ thenableWithCancel: undefined,
+ tokenAuthPending: undefined
+ });
+
+ case SET_TOKEN_AUTH_PENDING:
+ return assign(state, {
+ tokenAuthPending: action.pending || undefined
});
case ENABLE_MODERATOR_LOGIN:
return assign(state, {