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: Fixes redirect to token auth URL from welcome page.

damenchoc9f6de1371c9
diff --git a/react/features/app/getRouteToRender.web.ts b/react/features/app/getRouteToRender.web.ts
index b394895bd5..ce14d3d4f1 100644
--- a/react/features/app/getRouteToRender.web.ts
+++ b/react/features/app/getRouteToRender.web.ts
@@ -1,6 +1,7 @@
// @ts-expect-error
import { generateRoomWithoutSeparator } from '@jitsi/js-utils/random';
+import { getTokenAuthUrl } from '../authentication/functions';
import { IStateful } from '../base/app/types';
import { isRoomValid } from '../base/conference/functions';
import { isSupportedBrowser } from '../base/environment/environment';
@@ -36,11 +37,24 @@ export function _getRouteToRender(stateful: IStateful) {
* @returns {Promise|undefined}
*/
function _getWebConferenceRoute(state: IReduxState) {
- if (!isRoomValid(state['features/base/conference'].room)) {
+ const room = state['features/base/conference'].room;
+
+ if (!isRoomValid(room)) {
return;
}
const route = _getEmptyRoute();
+ const config = state['features/base/config'];
+
+ // if we have auto redirect enabled, and we have previously logged in successfully
+ // let's redirect to the auth url to get the token and login again
+ if (config.tokenAuthUrl && config.tokenAuthUrlAutoRedirect
+ && state['features/authentication'].tokenAuthUrlSuccessful
+ && !state['features/base/jwt'].jwt && room) {
+ route.href = getTokenAuthUrl(config, room);
+
+ return Promise.resolve(route);
+ }
// Update the location if it doesn't match. This happens when a room is
// joined from the welcome page. The reason for doing this instead of using
diff --git a/react/features/app/middleware.ts b/react/features/app/middleware.ts
index 96dd8715ad..4b7b0e970b 100644
--- a/react/features/app/middleware.ts
+++ b/react/features/app/middleware.ts
@@ -2,6 +2,7 @@ import { AnyAction } from 'redux';
import { createConnectionEvent } from '../analytics/AnalyticsEvents';
import { sendAnalytics } from '../analytics/functions';
+import { appWillNavigate } from '../base/app/actions';
import { SET_ROOM } from '../base/conference/actionTypes';
import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../base/connection/actionTypes';
import { getURLWithoutParams } from '../base/connection/utils';
@@ -146,11 +147,15 @@ function _isMaybeSplitBrainError(getState: IStore['getState'], action: AnyAction
* @private
* @returns {void}
*/
-function _navigate({ getState }: IStore) {
+function _navigate({ dispatch, getState }: IStore) {
const state = getState();
const { app } = state['features/base/app'];
- _getRouteToRender(state).then(route => app._navigate(route));
+ _getRouteToRender(state).then((route: Object) => {
+ dispatch(appWillNavigate(app, route));
+
+ return app._navigate(route);
+ });
}
/**
diff --git a/react/features/authentication/functions.ts b/react/features/authentication/functions.ts
index b7200f7e83..9657338036 100644
--- a/react/features/authentication/functions.ts
+++ b/react/features/authentication/functions.ts
@@ -1,6 +1,4 @@
import { IConfig } from '../base/config/configType';
-import JitsiMeetJS from '../base/lib-jitsi-meet';
-
/**
* Checks if the token for authentication is available.
@@ -12,13 +10,30 @@ export const isTokenAuthEnabled = (config: IConfig) =>
typeof config.tokenAuthUrl === 'string'
&& config.tokenAuthUrl.length;
-
/**
- * Token url.
+ * Creates the URL pointing to JWT token authentication service. It is
+ * formatted from the 'urlPattern' argument which can contain the following
+ * constants:
+ * '{room}' - name of the conference room passed as <tt>roomName</tt>
+ * argument to this method.
+ * '{roleUpgrade}' - will contain 'true' if the URL will be used for
+ * the role upgrade scenario, where user connects from anonymous domain and
+ * then gets upgraded to the moderator by logging-in from the popup window.
*
- * @param {Object} config - Configuration state object from store.
- * @returns {string}
+ * @param {Object} config - Configuration state object from store. A URL pattern pointing to the login service.
+ * @param {string} roomName - The name of the conference room for which the user will be authenticated.
+ *
+ * @returns {string|undefined} - The URL pointing to JWT login service or
+ * <tt>undefined</tt> if the pattern stored in config is not a string and the URL can not be
+ * constructed.
*/
-export const getTokenAuthUrl = (config: IConfig) =>
- JitsiMeetJS.util.AuthUtil.getTokenAuthUrl.bind(null,
- config.tokenAuthUrl);
+export const getTokenAuthUrl = (config: IConfig, roomName: string) => {
+
+ const url = config.tokenAuthUrl;
+
+ if (typeof url !== 'string' || !roomName) {
+ return undefined;
+ }
+
+ return url.replace('{room}', roomName);
+};
diff --git a/react/features/authentication/middleware.ts b/react/features/authentication/middleware.ts
index 5ccc97f517..cff08930c2 100644
--- a/react/features/authentication/middleware.ts
+++ b/react/features/authentication/middleware.ts
@@ -1,9 +1,9 @@
import { IStore } from '../app/types';
+import { APP_WILL_NAVIGATE } from '../base/app/actionTypes';
import {
CONFERENCE_FAILED,
CONFERENCE_JOINED,
- CONFERENCE_LEFT,
- SET_ROOM
+ CONFERENCE_LEFT
} from '../base/conference/actionTypes';
import { isRoomValid } from '../base/conference/functions';
import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../base/connection/actionTypes';
@@ -194,20 +194,21 @@ MiddlewareRegistry.register(store => next => action => {
break;
}
- case SET_ROOM: {
+ case APP_WILL_NAVIGATE: {
const { dispatch, getState } = store;
const state = getState();
const config = state['features/base/config'];
- const { room } = action;
+ const room = state['features/base/conference'].room;
- if (isRoomValid(room) && isTokenAuthEnabled(config) && config.tokenAuthUrlAutoRedirect
+ if (isRoomValid(room)
+ && config.tokenAuthUrl && config.tokenAuthUrlAutoRedirect
&& state['features/authentication'].tokenAuthUrlSuccessful
&& !state['features/base/jwt'].jwt) {
// if we have auto redirect enabled, and we have previously logged in successfully
- // let's redirect to the auth url to get the token and login again
+ // we will redirect to the auth url to get the token and login again
+ // we want to mark token auth success to false as if login is unsuccessful
+ // the participant can join anonymously and not go in login loop
dispatch(setTokenAuthUrlSuccess(false));
-
- window.location.href = getTokenAuthUrl(config)(room, false);
}
break;
@@ -293,11 +294,18 @@ function _handleLogin({ dispatch, getState }: IStore) {
return;
}
+ if (!room) {
+ return;
+ }
+
// FIXME: This method will not preserve the other URL params that were originally passed.
- const tokenAuthServiceUrl = getTokenAuthUrl(config)(room, false);
+ const tokenAuthServiceUrl = getTokenAuthUrl(config, room);
- // we have already shown the prejoin screen so no need to show it again(if enabled) after obtaining the token
- window.location.href = `${tokenAuthServiceUrl}${tokenAuthServiceUrl.includes('#') ? '&' : '#'}skipPrejoin=true`;
+ if (tokenAuthServiceUrl) {
+ // we have already shown the prejoin screen, so no need to show it again after obtaining the token
+ window.location.href = `${tokenAuthServiceUrl}${
+ tokenAuthServiceUrl.includes('#') ? '&' : '#'}skipPrejoin=true`;
+ }
} else {
dispatch(openLoginDialog());
}
diff --git a/react/features/base/app/actionTypes.ts b/react/features/base/app/actionTypes.ts
index ca9fba3e5a..c0f3678004 100644
--- a/react/features/base/app/actionTypes.ts
+++ b/react/features/base/app/actionTypes.ts
@@ -19,3 +19,15 @@ export const APP_WILL_MOUNT = 'APP_WILL_MOUNT';
* }
*/
export const APP_WILL_UNMOUNT = 'APP_WILL_UNMOUNT';
+
+/**
+ * The type of (redux) action which signals that a specific App will navigate using a route (in
+ * React terms).
+ *
+ * {
+ * type: APP_WILL_NAVIGATE,
+ * app: App,
+ * route: Route
+ * }
+ */
+export const APP_WILL_NAVIGATE = 'APP_WILL_NAVIGATE';
diff --git a/react/features/base/app/actions.ts b/react/features/base/app/actions.ts
index 208531ad6c..302611e61d 100644
--- a/react/features/base/app/actions.ts
+++ b/react/features/base/app/actions.ts
@@ -1,6 +1,10 @@
import { IStore } from '../../app/types';
-import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes';
+import {
+ APP_WILL_MOUNT,
+ APP_WILL_NAVIGATE,
+ APP_WILL_UNMOUNT
+} from './actionTypes';
/**
* Signals that a specific App will mount (in the terms of React).
@@ -44,3 +48,22 @@ export function appWillUnmount(app: Object) {
app
};
}
+
+/**
+ * Signals that a specific App will navigate (in the terms of React).
+ *
+ * @param {App} app - The App which will navigate.
+ * @param {Object} route - The route which will be used.
+ * @returns {{
+ * type: APP_WILL_NAVIGATE,
+ * app: App,
+ * route: Object
+ * }}
+ */
+export function appWillNavigate(app: Object, route: Object) {
+ return {
+ type: APP_WILL_NAVIGATE,
+ app,
+ route
+ };
+}