Skip to content

Commit

Permalink
[STCOR-885] Clear saved entry path so that subsequent logins will use…
Browse files Browse the repository at this point in the history
… default base URL. (#1531)

* Clear saved entry path so that subsequent logins will use default base URL

* Moving removeUnauthorizedPathFromSession() to OIDCRedirect so the value is cleared right after being used rather than on logout

* Add comment
  • Loading branch information
ryandberger authored Sep 9, 2024
1 parent d3f2c20 commit f694821
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/AuthnLogin/AuthnLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const AuthnLogin = ({ stripes }) => {
* @see OIDCRedirect
*/
if (okapi.authnUrl && window.location.pathname !== '/') {
setUnauthorizedPathToSession(window.location.pathname + window.location.search);
setUnauthorizedPathToSession();
}

// If only 1 tenant is defined in config (in either okapi or config.tenantOptions) set to okapi to be accessed there
Expand Down
12 changes: 9 additions & 3 deletions src/components/OIDCRedirect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { withRouter, Redirect, useLocation } from 'react-router';
import queryString from 'query-string';
import { useStripes } from '../StripesContext';
import { getUnauthorizedPathFromSession } from '../loginServices';
import { getUnauthorizedPathFromSession, removeUnauthorizedPathFromSession } from '../loginServices';

// Setting at top of component since value should be retained during re-renders
// but will be correctly re-fetched when redirected from Keycloak login page.
const unauthorizedPath = getUnauthorizedPathFromSession();

/**
* OIDCRedirect authenticated route handler for /oidc-landing.
Expand Down Expand Up @@ -29,8 +33,10 @@ const OIDCRedirect = () => {

const getUrl = () => {
if (stripes.okapi.authnUrl) {
const unauthorizedPath = getUnauthorizedPathFromSession();
if (unauthorizedPath) return unauthorizedPath;
if (unauthorizedPath) {
removeUnauthorizedPathFromSession();
return unauthorizedPath;
}
}

const params = getParams();
Expand Down
2 changes: 1 addition & 1 deletion src/loginServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const removeUnauthorizedPathFromSession = () => sessionStorage.removeItem
export const setUnauthorizedPathToSession = (pathname) => {
const path = pathname ?? `${window.location.pathname}${window.location.search}`;
if (!path.startsWith('/logout')) {
sessionStorage.setItem(UNAUTHORIZED_PATH, pathname ?? `${window.location.pathname}${window.location.search}`);
sessionStorage.setItem(UNAUTHORIZED_PATH, path);
}
};
export const getUnauthorizedPathFromSession = () => sessionStorage.getItem(UNAUTHORIZED_PATH);
Expand Down

0 comments on commit f694821

Please sign in to comment.