fix(jaas) do not redirect to plan limit page on auth errors (#9746)

This commit is contained in:
Avram Tudor 2021-08-20 11:36:09 +03:00 committed by GitHub
parent 8e4a22bdbf
commit 49a73ac446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 88 deletions

View File

@ -17,6 +17,7 @@ import {
JitsiConnectionErrors,
JitsiConnectionEvents
} from './react/features/base/lib-jitsi-meet';
import { getCustomerDetails } from './react/features/jaas/actions.any';
import { isVpaasMeeting, getJaasJWT } from './react/features/jaas/functions';
import { setPrejoinDisplayNameRequired } from './react/features/prejoin/actions';
const logger = Logger.getLogger(__filename);
@ -90,9 +91,13 @@ export async function connect(id, password, roomName) {
let { jwt } = state['features/base/jwt'];
const { iAmRecorder, iAmSipGateway } = state['features/base/config'];
if (!iAmRecorder && !iAmSipGateway && !jwt && isVpaasMeeting(state)) {
jwt = await getJaasJWT(state);
APP.store.dispatch(setJWT(jwt));
if (!iAmRecorder && !iAmSipGateway && isVpaasMeeting(state)) {
await APP.store.dispatch(getCustomerDetails());
if (!jwt) {
jwt = await getJaasJWT(state);
APP.store.dispatch(setJWT(jwt));
}
}
// Use Websocket URL for the web app if configured. Note that there is no 'isWeb' check, because there's assumption

View File

@ -0,0 +1,46 @@
// @flow
import { SET_DETAILS } from './actionTypes';
import { getVpaasTenant, sendGetDetailsRequest } from './functions';
import logger from './logger';
/**
* Action used to set the jaas customer details in store.
*
* @param {Object} details - The customer details object.
* @returns {Object}
*/
function setCustomerDetails(details) {
return {
type: SET_DETAILS,
payload: details
};
}
/**
* Sends a request for retrieving jaas customer details.
*
* @returns {Function}
*/
export function getCustomerDetails() {
return async function(dispatch: Function, getState: Function) {
const state = getState();
const baseUrl = state['features/base/config'].jaasActuatorUrl || 'https://api-vo-pilot.jitsi.net/jaas-actuator';
const appId = getVpaasTenant(state);
const shouldSendRequest = Boolean(baseUrl && appId);
if (shouldSendRequest) {
try {
const details = await sendGetDetailsRequest({
appId,
baseUrl
});
dispatch(setCustomerDetails(details));
} catch (err) {
logger.error('Could not send request', err);
}
}
};
}

View File

@ -2,55 +2,8 @@
import { openDialog } from '../base/dialog';
import { SET_DETAILS } from './actionTypes';
import { PremiumFeatureDialog } from './components';
import { VPAAS_TENANT_PREFIX } from './constants';
import { getVpaasTenant, isFeatureDisabled, sendGetDetailsRequest } from './functions';
import logger from './logger';
/**
* Action used to set the jaas customer details in store.
*
* @param {Object} details - The customer details object.
* @returns {Object}
*/
function setCustomerDetails(details) {
return {
type: SET_DETAILS,
payload: details
};
}
/**
* Sends a request for retrieving jaas customer details.
*
* @returns {Function}
*/
export function getCustomerDetails() {
return async function(dispatch: Function, getState: Function) {
const state = getState();
const baseUrl = state['features/base/config'].jaasActuatorUrl;
const jwt = state['features/base/jwt'].jwt;
const appId = getVpaasTenant(state).replace(VPAAS_TENANT_PREFIX, '');
const shouldSendRequest = Boolean(baseUrl && jwt && appId);
if (shouldSendRequest) {
try {
const details = await sendGetDetailsRequest({
baseUrl,
jwt,
appId
});
dispatch(setCustomerDetails(details));
} catch (err) {
logger.error('Could not send request', err);
}
}
};
}
import { isFeatureDisabled } from './functions';
/**
* Shows a dialog prompting users to upgrade, if requested feature is disabled.

View File

@ -54,24 +54,16 @@ export function isVpaasMeeting(state: Object) {
* @param {Object} reqData - The request info.
* @param {string} reqData.appId - The client appId.
* @param {string} reqData.baseUrl - The base url for the request.
* @param {string} reqData.jwt - The JWT token.
* @returns {void}
*/
export async function sendGetDetailsRequest({ appId, baseUrl, jwt }: {
export async function sendGetDetailsRequest({ appId, baseUrl }: {
appId: string,
baseUrl: string,
jwt: string,
}) {
const fullUrl = `${baseUrl}/v1/customers/${encodeURIComponent(appId)}`;
const headers = {
'Authorization': `Bearer ${jwt}`
};
const fullUrl = `${baseUrl}/v1/public/tenants/${encodeURIComponent(appId)}`;
try {
const res = await fetch(fullUrl, {
method: 'GET',
headers
});
const res = await fetch(fullUrl);
if (res.ok) {
return res.json();

View File

@ -1,14 +1,9 @@
import { redirectToStaticPage } from '../app/actions';
import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
import { CONNECTION_FAILED } from '../base/connection';
import { JitsiConnectionErrors } from '../base/lib-jitsi-meet';
import { MiddlewareRegistry } from '../base/redux';
import { SET_DETAILS } from './actionTypes';
import { getCustomerDetails } from './actions';
import { STATUSES } from './constants';
import { isVpaasMeeting } from './functions';
/**
* The redux middleware for jaas.
@ -18,27 +13,6 @@ import { isVpaasMeeting } from './functions';
*/
MiddlewareRegistry.register(store => next => async action => {
switch (action.type) {
case CONFERENCE_JOINED: {
store.dispatch(getCustomerDetails());
break;
}
case CONNECTION_FAILED: {
const { error } = action;
if (!isVpaasMeeting(store.getState()) || !error) {
break;
}
if (error.name === JitsiConnectionErrors.PASSWORD_REQUIRED) {
if (error.message !== 'could not obtain public key') {
break;
}
store.dispatch(redirectToStaticPage('/static/planLimit.html'));
}
break;
}
case SET_DETAILS: {
const { status } = action.payload;