Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STCOR-787 Fix tenant and clientId references #1492

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/AuthnLogin/AuthnLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const AuthnLogin = ({ stripes }) => {
if (okapi.authnUrl) {
// If only 1 tenant is defined in config, skip the tenant selection screen.
if (tenants.length === 1) {
const loginTenant = tenants[0];
const redirectUri = `${window.location.protocol}//${window.location.host}/oidc-landing`;
const authnUri = `${okapi.authnUrl}/realms/${okapi.tenant}/protocol/openid-connect/auth?client_id=${okapi.clientId}&response_type=code&redirect_uri=${redirectUri}&scope=openid`;
const authnUri = `${okapi.authnUrl}/realms/${loginTenant.name}/protocol/openid-connect/auth?client_id=${loginTenant.clientId}&response_type=code&redirect_uri=${redirectUri}&scope=openid`;
return <Redirect to={authnUri} />;
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/Root/FFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export class FFetch {
rotationP.then((rotationInterval) => {
this.logger.log('rtr', `rotation fired from rotateCallback; next callback in ${ms(rotationInterval)}`);
this.store.dispatch(setRtrTimeout(setTimeout(() => {
rtr(this.nativeFetch, this.logger, this.rotateCallback);
const okapiStore = this.store.getState().okapi;
rtr(this.nativeFetch, this.logger, this.rotateCallback, okapiStore);
ryandberger marked this conversation as resolved.
Show resolved Hide resolved
}, rotationInterval)));
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/Root/token-util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isEmpty } from 'lodash';
import { okapi } from 'stripes-config';

import { getTokenExpiry, setTokenExpiry } from '../../loginServices';
import { RTRError, UnexpectedResourceError } from './Errors';
Expand Down Expand Up @@ -192,9 +191,10 @@ export const isRotating = () => {
* @param {function} fetchfx native fetch function
* @param {@folio/stripes/logger} logger
* @param {function} callback
* @param {object} store
ryandberger marked this conversation as resolved.
Show resolved Hide resolved
* @returns void
*/
export const rtr = (fetchfx, logger, callback) => {
export const rtr = (fetchfx, logger, callback, okapi) => {
logger.log('rtr', '** RTR ...');

// rotation is already in progress, maybe in this window,
Expand Down
15 changes: 10 additions & 5 deletions src/components/Root/token-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import {
} from './token-util';
import { RTR_SUCCESS_EVENT } from './constants';

const okapi = {
tenant: 'diku',
url: 'http://test'
};

describe('isFolioApiRequest', () => {
it('accepts requests whose origin matches okapi\'s', () => {
const oUrl = 'https://millicent-sounds-kinda-like-malificent.edu';
Expand Down Expand Up @@ -126,7 +131,7 @@ describe('rtr', () => {
let ex = null;
// const callback = () => { console.log('HOLA!!!')}; // jest.fn();
try {
await rtr(fetchfx, logger, callback);
await rtr(fetchfx, logger, callback, okapi);
expect(callback).toHaveBeenCalled();
} catch (e) {
ex = e;
Expand Down Expand Up @@ -168,7 +173,7 @@ describe('rtr', () => {

let ex = null;
try {
await rtr(nativeFetch, logger, jest.fn());
await rtr(nativeFetch, logger, jest.fn(), okapi);
} catch (e) {
ex = e;
}
Expand Down Expand Up @@ -202,7 +207,7 @@ describe('rtr', () => {

let ex = null;
try {
await rtr(nativeFetch, logger, jest.fn());
await rtr(nativeFetch, logger, jest.fn(), okapi);
} catch (e) {
ex = e;
}
Expand Down Expand Up @@ -232,7 +237,7 @@ describe('rtr', () => {

let ex = null;
try {
await rtr(nativeFetch, logger, jest.fn());
await rtr(nativeFetch, logger, jest.fn(), okapi);
} catch (e) {
ex = e;
}
Expand Down Expand Up @@ -262,7 +267,7 @@ describe('rtr', () => {

let ex = null;
try {
await rtr(nativeFetch, logger, jest.fn());
await rtr(nativeFetch, logger, jest.fn(), okapi);
} catch (e) {
ex = e;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/SSOLanding/useSSOSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const getToken = (cookies, params) => {
return cookies?.ssoToken || params?.ssoToken;
};

const getTenant = (params, token) => {
const getTenant = (params, token, store) => {
const tenant = config.useSecureTokens
? params?.tenantId
: parseJWT(token)?.tenant;

return tenant || okapi.tenant;
return tenant || store.getState()?.okapi?.tenant;
};

const useSSOSession = () => {
Expand All @@ -42,7 +42,7 @@ const useSSOSession = () => {
const params = getParams(location);

const token = getToken(cookies, params);
const tenant = getTenant(params, token);
const tenant = getTenant(params, token, store);

useEffect(() => {
requestUserWithPerms(okapi.url, store, tenant, token)
Expand Down
9 changes: 8 additions & 1 deletion src/components/SSOLanding/useSSOSession.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ describe('SSOLanding', () => {
useLocation.mockReturnValue({ search: '' });
useCookies.mockReturnValue([]);

useStore.mockReturnValue({ getState: jest.fn() });
useStore.mockReturnValue({
getState: jest.fn().mockReturnValue({
okapi: {
url: 'okapiUrl',
tenant: 'okapiTenant'
}
})
});

requestUserWithPerms.mockReturnValue(Promise.resolve());
});
Expand Down
8 changes: 4 additions & 4 deletions src/discoverServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function parseApplicationDescriptor(store, descriptor) {
const APP_MAX_COUNT = 500;

function fetchApplicationDetails(store) {
const okapi = store.getState().okapi;
const { okapi } = store.getState();

return fetch(`${okapi.url}/entitlements/${okapi.tenant}/applications?limit=${APP_MAX_COUNT}`, {
credentials: 'include',
Expand Down Expand Up @@ -146,7 +146,7 @@ function fetchApplicationDetails(store) {
*/

function fetchGatewayVersion(store) {
const okapi = store.getState().okapi;
const { okapi } = store.getState();

return fetch(`${okapi.url}/version`, {
credentials: 'include',
Expand All @@ -167,7 +167,7 @@ function fetchGatewayVersion(store) {
}

function fetchOkapiVersion(store) {
const okapi = store.getState().okapi;
const { okapi } = store.getState();

return fetch(`${okapi.url}/_/version`, {
credentials: 'include',
Expand All @@ -188,7 +188,7 @@ function fetchOkapiVersion(store) {
}

function fetchModules(store) {
const okapi = store.getState().okapi;
const { okapi } = store.getState();

return fetch(`${okapi.url}/_/proxy/tenants/${okapi.tenant}/modules?full=true`, {
credentials: 'include',
Expand Down
Loading