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-869 do not store /logout as a "return-to" URL #1511

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions src/components/Root/FFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { okapi as okapiConfig } from 'stripes-config';
import {
setRtrTimeout,
setRtrFlsTimeout,
setRtrFlsWarningTimeout,
} from '../../okapiActions';

import { getTokenExpiry } from '../../loginServices';
Expand Down Expand Up @@ -131,15 +132,17 @@ export class FFetch {

// schedule FLS end-of-session warning
this.logger.log('rtr-fls', `end-of-session warning at ${new Date(rotationInterval.refreshTokenExpiration - ms(this.rtrConfig.fixedLengthSessionWarningTTL))}`);
this.store.dispatch(setRtrFlsTimeout(setTimeout(() => {
this.store.dispatch(setRtrFlsWarningTimeout(setTimeout(() => {
this.logger.log('rtr-fls', 'emitting RTR_FLS_WARNING_EVENT');
window.dispatchEvent(new Event(RTR_FLS_WARNING_EVENT));
}, rtWarningInterval)));

// schedule FLS end-of-session logout
this.logger.log('rtr-fls', `session will end at ${new Date(rotationInterval.refreshTokenExpiration)}`);
setTimeout(() => {
this.store.dispatch(setRtrFlsTimeout(setTimeout(() => {
this.logger.log('rtr-fls', 'emitting RTR_FLS_TIMEOUT_EVENT');
window.dispatchEvent(new Event(RTR_FLS_TIMEOUT_EVENT));
}, rtTimeoutInterval);
}, rtTimeoutInterval)));
});
};

Expand Down
5 changes: 4 additions & 1 deletion src/loginServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export const setTokenExpiry = async (te) => {
const UNAUTHORIZED_PATH = 'unauthorized_path';
export const removeUnauthorizedPathFromSession = () => sessionStorage.removeItem(UNAUTHORIZED_PATH);
export const setUnauthorizedPathToSession = (pathname) => {
sessionStorage.setItem(UNAUTHORIZED_PATH, pathname ?? `${window.location.pathname}${window.location.search}`);
const path = pathname ?? `${window.location.pathname}${window.location.search}`;
if (!path.startsWith('/logout')) {
sessionStorage.setItem(UNAUTHORIZED_PATH, pathname ?? `${window.location.pathname}${window.location.search}`);
}
};
export const getUnauthorizedPathFromSession = () => sessionStorage.getItem(UNAUTHORIZED_PATH);

Expand Down
14 changes: 14 additions & 0 deletions src/okapiActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ function clearRtrTimeout() {
};
}

function setRtrFlsWarningTimeout(rtrFlsTimeout) {
return {
type: OKAPI_REDUCER_ACTIONS.SET_RTR_FLS_WARNING_TIMEOUT,
rtrFlsTimeout,
};
}

function clearRtrFlsWarningTimeout() {
return {
type: OKAPI_REDUCER_ACTIONS.CLEAR_RTR_FLS_WARNING_TIMEOUT,
};
}
function setRtrFlsTimeout(rtrFlsTimeout) {
return {
type: OKAPI_REDUCER_ACTIONS.SET_RTR_FLS_TIMEOUT,
Expand All @@ -190,6 +202,7 @@ export {
clearCurrentUser,
clearOkapiToken,
clearRtrFlsTimeout,
clearRtrFlsWarningTimeout,
clearRtrTimeout,
setAuthError,
setBindings,
Expand All @@ -203,6 +216,7 @@ export {
setOkapiToken,
setPlugins,
setRtrFlsTimeout,
setRtrFlsWarningTimeout,
setRtrTimeout,
setServerDown,
setSessionData,
Expand Down
17 changes: 17 additions & 0 deletions src/okapiReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const OKAPI_REDUCER_ACTIONS = {
CLEAR_CURRENT_USER: 'CLEAR_CURRENT_USER',
CLEAR_OKAPI_TOKEN: 'CLEAR_OKAPI_TOKEN',
CLEAR_RTR_FLS_TIMEOUT: 'CLEAR_RTR_FLS_TIMEOUT',
CLEAR_RTR_FLS_WARNING_TIMEOUT: 'CLEAR_RTR_FLS_WARNING_TIMEOUT',
CLEAR_RTR_TIMEOUT: 'CLEAR_RTR_TIMEOUT',
OKAPI_READY: 'OKAPI_READY',
SERVER_DOWN: 'SERVER_DOWN',
Expand All @@ -18,6 +19,7 @@ export const OKAPI_REDUCER_ACTIONS = {
SET_OKAPI_TOKEN: 'SET_OKAPI_TOKEN',
SET_PLUGINS: 'SET_PLUGINS',
SET_RTR_FLS_TIMEOUT: 'SET_RTR_FLS_TIMEOUT',
SET_RTR_FLS_WARNING_TIMEOUT: 'SET_RTR_FLS_WARNING_TIMEOUT',
SET_RTR_TIMEOUT: 'SET_RTR_TIMEOUT',
SET_SESSION_DATA: 'SET_SESSION_DATA',
SET_SINGLE_PLUGIN: 'SET_SINGLE_PLUGIN',
Expand Down Expand Up @@ -47,9 +49,11 @@ export default function okapiReducer(state = {}, action) {
// if we're logging out, clear the RTR timeouts and related values
if (!action.isAuthenticated) {
clearTimeout(state.rtrTimeout);
clearTimeout(state.rtrFlsWarningTimeout);
clearTimeout(state.rtrFlsTimeout);
newState.rtrModalIsVisible = false;
newState.rtrTimeout = undefined;
newState.rtrFlsWarningTimeout = undefined;
newState.rtrFlsTimeout = undefined;
}

Expand Down Expand Up @@ -99,10 +103,23 @@ export default function okapiReducer(state = {}, action) {
clearTimeout(state.rtrTimeout);
return { ...state, rtrTimeout: action.rtrTimeout };
}

case OKAPI_REDUCER_ACTIONS.CLEAR_RTR_TIMEOUT: {
clearTimeout(state.rtrTimeout);
return { ...state, rtrTimeout: undefined };
}

// clear existing FLS warning timeout and set a new one
case OKAPI_REDUCER_ACTIONS.SET_RTR_FLS_WARNING_TIMEOUT: {
clearTimeout(state.rtrFlsWarningTimeout);
return { ...state, rtrFlsWarningTimeout: action.rtrFlsWarningTimeout };
}

case OKAPI_REDUCER_ACTIONS.CLEAR_RTR_FLS_WARNING_TIMEOUT: {
clearTimeout(state.rtrFlsWarningTimeout);
return { ...state, rtrFlsWarningTimeout: undefined };
}

// clear existing FLS timeout and set a new one
case OKAPI_REDUCER_ACTIONS.SET_RTR_FLS_TIMEOUT: {
clearTimeout(state.rtrFlsTimeout);
Expand Down
Loading