feat(JaaS-JWT) Get JWT for JaaS (#9512)
* Added get JWT for JaaS * Code review fix
This commit is contained in:
parent
dc60418613
commit
bad58f6508
|
@ -11,11 +11,14 @@ import {
|
||||||
connectionFailed
|
connectionFailed
|
||||||
} from './react/features/base/connection/actions';
|
} from './react/features/base/connection/actions';
|
||||||
import { openDialog } from './react/features/base/dialog/actions';
|
import { openDialog } from './react/features/base/dialog/actions';
|
||||||
|
import { setJWT } from './react/features/base/jwt';
|
||||||
import {
|
import {
|
||||||
isFatalJitsiConnectionError,
|
isFatalJitsiConnectionError,
|
||||||
JitsiConnectionErrors,
|
JitsiConnectionErrors,
|
||||||
JitsiConnectionEvents
|
JitsiConnectionEvents
|
||||||
} from './react/features/base/lib-jitsi-meet';
|
} from './react/features/base/lib-jitsi-meet';
|
||||||
|
import { isVpaasMeeting } from './react/features/billing-counter/functions';
|
||||||
|
import { getJaasJWT } from './react/features/jaas/functions';
|
||||||
import { setPrejoinDisplayNameRequired } from './react/features/prejoin/actions';
|
import { setPrejoinDisplayNameRequired } from './react/features/prejoin/actions';
|
||||||
const logger = Logger.getLogger(__filename);
|
const logger = Logger.getLogger(__filename);
|
||||||
|
|
||||||
|
@ -82,9 +85,15 @@ function checkForAttachParametersAndConnect(id, password, connection) {
|
||||||
* @returns {Promise<JitsiConnection>} connection if
|
* @returns {Promise<JitsiConnection>} connection if
|
||||||
* everything is ok, else error.
|
* everything is ok, else error.
|
||||||
*/
|
*/
|
||||||
export function connect(id, password, roomName) {
|
export async function connect(id, password, roomName) {
|
||||||
const connectionConfig = Object.assign({}, config);
|
const connectionConfig = Object.assign({}, config);
|
||||||
const { jwt } = APP.store.getState()['features/base/jwt'];
|
const state = APP.store.getState();
|
||||||
|
let { jwt } = state['features/base/jwt'];
|
||||||
|
|
||||||
|
if (!jwt && isVpaasMeeting(state)) {
|
||||||
|
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
|
// Use Websocket URL for the web app if configured. Note that there is no 'isWeb' check, because there's assumption
|
||||||
// that this code executes only on web browsers/electron. This needs to be changed when mobile and web are unified.
|
// that this code executes only on web browsers/electron. This needs to be changed when mobile and web are unified.
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
|
import { getVpaasTenant } from '../billing-counter/functions';
|
||||||
|
|
||||||
|
import logger from './logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a request for retrieving jaas customer details.
|
* Sends a request for retrieving jaas customer details.
|
||||||
*
|
*
|
||||||
|
@ -46,3 +50,59 @@ export async function sendGetDetailsRequest({ appId, baseUrl, jwt }: {
|
||||||
export function isFeatureDisabled(state: Object, feature: string) {
|
export function isFeatureDisabled(state: Object, feature: string) {
|
||||||
return state['features/jaas'].disabledFeatures.includes(feature);
|
return state['features/jaas'].disabledFeatures.includes(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a request for retrieving jaas JWT.
|
||||||
|
*
|
||||||
|
* @param {Object} reqData - The request info.
|
||||||
|
* @param {string} reqData.appId - The client appId.
|
||||||
|
* @param {string} reqData.baseUrl - The base url for the request.
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
export async function sendGetJWTRequest({ appId, baseUrl }: {
|
||||||
|
appId: string,
|
||||||
|
baseUrl: string
|
||||||
|
}) {
|
||||||
|
const fullUrl = `${baseUrl}/v1/public/token/${encodeURIComponent(appId)}`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(fullUrl, {
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error('Request not successful');
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(err);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a jaas JWT.
|
||||||
|
*
|
||||||
|
* @param {Object} state - Redux state.
|
||||||
|
* @returns {string} The JWT.
|
||||||
|
*/
|
||||||
|
export async function getJaasJWT(state: Object) {
|
||||||
|
const baseUrl = state['features/base/config'].jaasTokenUrl;
|
||||||
|
const appId = getVpaasTenant(state);
|
||||||
|
|
||||||
|
const shouldSendRequest = Boolean(baseUrl && appId);
|
||||||
|
|
||||||
|
if (shouldSendRequest) {
|
||||||
|
try {
|
||||||
|
const jwt = await sendGetJWTRequest({
|
||||||
|
appId,
|
||||||
|
baseUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
return jwt.token;
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Could not send request', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue