[arvados-workbench2] created: 2.5.0-1-gebbe5fdc
git repository hosting
git at public.arvados.org
Thu Jan 12 20:45:25 UTC 2023
at ebbe5fdc661b279c5166dae75381442c2e37f1f1 (commit)
commit ebbe5fdc661b279c5166dae75381442c2e37f1f1
Author: Stephen Smith <stephen at curii.com>
Date: Thu Jan 12 15:44:45 2023 -0500
19715: Add preserve url location flag to logout action - set to true for autologout
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen at curii.com>
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index 52bfa29e..b530e4cd 100644
--- a/src/services/auth-service/auth-service.ts
+++ b/src/services/auth-service/auth-service.ts
@@ -120,9 +120,13 @@ export class AuthService {
window.location.assign(`https://${homeClusterHost}/login?${(uuidPrefix !== homeCluster && homeCluster !== loginCluster) ? "remote=" + uuidPrefix + "&" : ""}return_to=${currentUrl}`);
}
- public logout(expireToken: string) {
- const currentUrl = `${window.location.protocol}//${window.location.host}`;
- window.location.assign(`${this.baseUrl || ""}/logout?api_token=${expireToken}&return_to=${currentUrl}`);
+ public logout(expireToken: string, preservePath: boolean) {
+ const fullUrl = new URL(window.location.href);
+ const wbBase = `${fullUrl.protocol}//${fullUrl.host}`;
+ const wbPath = fullUrl.pathname + fullUrl.search;
+ const returnTo = `${wbBase}${preservePath ? wbPath : ''}`
+
+ window.location.assign(`${this.baseUrl || ""}/logout?api_token=${expireToken}&return_to=${returnTo}`);
}
public getUserDetails = (showErrors?: boolean): Promise<User> => {
diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts
index 6eb8356f..145a461c 100644
--- a/src/store/auth/auth-action.ts
+++ b/src/store/auth/auth-action.ts
@@ -20,7 +20,7 @@ import { getTokenV2 } from 'models/api-client-authorization';
export const authActions = unionize({
LOGIN: {},
- LOGOUT: ofType<{ deleteLinkData: boolean }>(),
+ LOGOUT: ofType<{ deleteLinkData: boolean, preservePath: boolean }>(),
SET_CONFIG: ofType<{ config: Config }>(),
SET_EXTRA_TOKEN: ofType<{ extraApiToken: string, extraApiTokenExpiration?: Date }>(),
RESET_EXTRA_TOKEN: {},
@@ -113,7 +113,7 @@ export const saveApiToken = (token: string) => async (dispatch: Dispatch, getSta
const tokenLocation = await svc.authService.getStorageType();
dispatch(authActions.INIT_USER({ user, token, tokenExpiration, tokenLocation }));
} catch (e) {
- dispatch(authActions.LOGOUT({ deleteLinkData: false }));
+ dispatch(authActions.LOGOUT({ deleteLinkData: false, preservePath: false }));
}
};
@@ -163,8 +163,8 @@ export const login = (uuidPrefix: string, homeCluster: string, loginCluster: str
dispatch(authActions.LOGIN());
};
-export const logout = (deleteLinkData: boolean = false) =>
+export const logout = (deleteLinkData: boolean = false, preservePath: boolean = false) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) =>
- dispatch(authActions.LOGOUT({ deleteLinkData }));
+ dispatch(authActions.LOGOUT({ deleteLinkData, preservePath }))
export type AuthAction = UnionOf<typeof authActions>;
diff --git a/src/store/auth/auth-middleware.test.ts b/src/store/auth/auth-middleware.test.ts
index 9ded9e67..5a0364eb 100644
--- a/src/store/auth/auth-middleware.test.ts
+++ b/src/store/auth/auth-middleware.test.ts
@@ -36,10 +36,10 @@ describe("AuthMiddleware", () => {
window.location.assign = jest.fn();
const next = jest.fn();
const middleware = authMiddleware(services)(store)(next);
- middleware(authActions.LOGOUT({deleteLinkData: false}));
+ middleware(authActions.LOGOUT({deleteLinkData: false, preservePath: false}));
expect(window.location.assign).toBeCalledWith(
`/logout?api_token=someToken&return_to=${location.protocol}//${location.host}`
);
expect(localStorage.getItem(API_TOKEN_KEY)).toBeFalsy();
});
-});
\ No newline at end of file
+});
diff --git a/src/store/auth/auth-middleware.ts b/src/store/auth/auth-middleware.ts
index 87a1253b..eb1e42b5 100644
--- a/src/store/auth/auth-middleware.ts
+++ b/src/store/auth/auth-middleware.ts
@@ -59,7 +59,7 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store
document.title = `Arvados Workbench (${config.uuidPrefix})`;
next(action);
},
- LOGOUT: ({ deleteLinkData }) => {
+ LOGOUT: ({ deleteLinkData, preservePath }) => {
next(action);
if (deleteLinkData) {
services.linkAccountService.removeAccountToLink();
@@ -69,7 +69,7 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store
services.authService.removeSessions();
services.authService.removeUser();
removeAuthorizationHeader(services);
- services.authService.logout(token || '');
+ services.authService.logout(token || '', preservePath);
},
default: () => next(action)
});
diff --git a/src/views-components/auto-logout/auto-logout.tsx b/src/views-components/auto-logout/auto-logout.tsx
index a2d71d08..b4bef2b5 100644
--- a/src/views-components/auto-logout/auto-logout.tsx
+++ b/src/views-components/auto-logout/auto-logout.tsx
@@ -30,7 +30,7 @@ const mapStateToProps = (state: RootState, ownProps: any): AutoLogoutDataProps =
});
const mapDispatchToProps = (dispatch: Dispatch): AutoLogoutActionProps => ({
- doLogout: () => dispatch<any>(logout(true)),
+ doLogout: () => dispatch<any>(logout(true, true)),
doWarn: (message: string, duration: number) =>
dispatch(snackbarActions.OPEN_SNACKBAR({
message, hideDuration: duration, kind: SnackbarKind.WARNING })),
diff --git a/src/views-components/main-app-bar/account-menu.tsx b/src/views-components/main-app-bar/account-menu.tsx
index 7faf27c2..4b62cea2 100644
--- a/src/views-components/main-app-bar/account-menu.tsx
+++ b/src/views-components/main-app-bar/account-menu.tsx
@@ -95,7 +95,7 @@ export const AccountMenuComponent =
{user.isActive && accountMenuItems}
<Divider />
<MenuItem data-cy="logout-menuitem"
- onClick={() => dispatch(authActions.LOGOUT({ deleteLinkData: true }))}>
+ onClick={() => dispatch(authActions.LOGOUT({ deleteLinkData: true, preservePath: false }))}>
Logout
</MenuItem>
</DropdownMenu>
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list