From 0da5b926cb7aa461e8d45d86d5fc423d90e768a1 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 8 Feb 2019 17:06:38 -0500 Subject: [PATCH] 14720: Federated login chooser wip Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- src/index.tsx | 2 + src/services/auth-service/auth-service.ts | 7 +- src/store/auth/auth-action.ts | 4 +- .../main-app-bar/account-menu.tsx | 2 +- .../main-app-bar/anonymous-menu.tsx | 2 +- .../main-app-bar/main-app-bar.tsx | 5 +- src/views/login-panel/login-panel.tsx | 86 +++++++++++++------ src/views/main-panel/main-panel-root.tsx | 10 ++- src/views/main-panel/main-panel.tsx | 5 +- 9 files changed, 80 insertions(+), 43 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 1561c3ff..f5eedc73 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -60,6 +60,7 @@ import { groupActionSet } from '~/views-components/context-menu/action-sets/grou import { groupMemberActionSet } from '~/views-components/context-menu/action-sets/group-member-action-set'; import { linkActionSet } from '~/views-components/context-menu/action-sets/link-action-set'; import { loadFileViewersConfig } from '~/store/file-viewers/file-viewers-actions'; +import { setRemoteHosts } from '~/views/login-panel/login-panel'; console.log(`Starting arvados [${getBuildInfo()}]`); @@ -106,6 +107,7 @@ fetchConfig() store.dispatch(setBuildInfo()); store.dispatch(setCurrentTokenDialogApiHost(apiHost)); store.dispatch(setUuidPrefix(config.uuidPrefix)); + store.dispatch(setRemoteHosts(config.remoteHosts)); store.dispatch(loadVocabulary); store.dispatch(loadFileViewersConfig); diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts index 6fe27c8d..fff7d577 100644 --- a/src/services/auth-service/auth-service.ts +++ b/src/services/auth-service/auth-service.ts @@ -99,9 +99,10 @@ export class AuthService { localStorage.removeItem(USER_PREFS); } - public login() { + public login(uuidPrefix: string, homeCluster: string) { const currentUrl = `${window.location.protocol}//${window.location.host}/token`; - window.location.assign(`${this.baseUrl || ""}/login?return_to=${currentUrl}`); + // window.location.assign(`${this.baseUrl || ""}/login?return_to=${currentUrl}`); + window.location.assign(`https://${homeCluster}/login?remote=${uuidPrefix}&return_to=${currentUrl}`); } public logout() { @@ -116,7 +117,7 @@ export class AuthService { .get('/users/current') .then(resp => { this.actions.progressFn(reqId, false); - const prefs = resp.data.prefs.profile ? resp.data.prefs : { profile: {}}; + const prefs = resp.data.prefs.profile ? resp.data.prefs : { profile: {} }; return { email: resp.data.email, firstName: resp.data.first_name, diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts index 6c54a5c9..43d1be82 100644 --- a/src/store/auth/auth-action.ts +++ b/src/store/auth/auth-action.ts @@ -60,8 +60,8 @@ export const saveApiToken = (token: string) => (dispatch: Dispatch, getState: () dispatch(authActions.SAVE_API_TOKEN(token)); }; -export const login = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - services.authService.login(); +export const login = (uuidPrefix: string, homeCluster: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + services.authService.login(uuidPrefix, homeCluster); dispatch(authActions.LOGIN()); }; diff --git a/src/views-components/main-app-bar/account-menu.tsx b/src/views-components/main-app-bar/account-menu.tsx index 6c1e46c5..b50ee336 100644 --- a/src/views-components/main-app-bar/account-menu.tsx +++ b/src/views-components/main-app-bar/account-menu.tsx @@ -38,7 +38,7 @@ export const AccountMenu = connect(mapStateToProps)( title="Account Management" key={currentRoute}> - {getUserFullname(user)} + {getUserFullname(user)} ({user.uuid.substr(0, 5)}) dispatch(openUserVirtualMachines())}>Virtual Machines {!user.isAdmin && dispatch(openRepositoriesPanel())}>Repositories} diff --git a/src/views-components/main-app-bar/anonymous-menu.tsx b/src/views-components/main-app-bar/anonymous-menu.tsx index 6f77a524..5ffc4215 100644 --- a/src/views-components/main-app-bar/anonymous-menu.tsx +++ b/src/views-components/main-app-bar/anonymous-menu.tsx @@ -11,6 +11,6 @@ export const AnonymousMenu = connect()( ({ dispatch }: DispatchProp) => ); diff --git a/src/views-components/main-app-bar/main-app-bar.tsx b/src/views-components/main-app-bar/main-app-bar.tsx index ff3bee61..d2a05837 100644 --- a/src/views-components/main-app-bar/main-app-bar.tsx +++ b/src/views-components/main-app-bar/main-app-bar.tsx @@ -31,6 +31,7 @@ interface MainAppBarDataProps { user?: User; buildInfo?: string; children?: ReactNode; + uuidPrefix: string; } export type MainAppBarProps = MainAppBarDataProps & WithStyles; @@ -43,7 +44,7 @@ export const MainAppBar = withStyles(styles)( - arvados workbench + arvados workbench ({props.uuidPrefix}) {props.buildInfo} @@ -53,7 +54,7 @@ export const MainAppBar = withStyles(styles)( xs={6} container alignItems="center"> - {props.user && } + {props.user && } = (theme: ArvadosTheme) => ({ } }); -type LoginPanelProps = DispatchProp & WithStyles; +type LoginPanelProps = DispatchProp & WithStyles & { + remoteHosts: any, + homeCluster: string, + uuidPrefix: string +}; -export const LoginPanel = withStyles(styles)(connect()( - ({ classes, dispatch }: LoginPanelProps) => - - - - Welcome to the Arvados Workbench - - - The "Log in" button below will show you a Google sign-in page. - After you assure Google that you want to log in here with your Google account, you will be redirected back here to Arvados Workbench. - - - If you have never used Arvados Workbench before, logging in for the first time will automatically create a new account. - - - IMPORTANT: Please keep in mind to store exploratory data only but not any information used for clinical decision making. - - - Arvados Workbench uses your name and email address only for identification, and does not retrieve any other personal information from Google. - - - - +export const REMOTE_HOSTS_NAME = 'remoteHosts'; +export const HOME_CLUSTER_NAME = 'homeCluster'; +export const setRemoteHosts = (remoteHosts: any) => + propertiesActions.SET_PROPERTY({ key: REMOTE_HOSTS_NAME, value: remoteHosts }); + +export const setHomeCluster = (homeCluster: string) => + propertiesActions.SET_PROPERTY({ key: HOME_CLUSTER_NAME, value: homeCluster }); + +export const LoginPanel = withStyles(styles)( + connect((state: RootState) => ({ + remoteHosts: state.properties.remoteHosts, + homeCluster: state.properties.homeCluster, + uuidPrefix: state.properties.uuidPrefix + }))(({ classes, dispatch, remoteHosts, homeCluster, uuidPrefix }: LoginPanelProps) => + + + + Welcome to the Arvados Workbench + + + The "Log in" button below will show you a Google sign-in page. + After you assure Google that you want to log in here with your Google account, you will be redirected back here to Arvados Workbench. + + + If you have never used Arvados Workbench before, logging in for the first time will automatically create a new account. + + + IMPORTANT: Please keep in mind to store exploratory data only but not any information used for clinical decision making. + + + Arvados Workbench uses your name and email address only for identification, and does not retrieve any other personal information from Google. + + + +
+ +
+
+ + + +
-
-)); + )); diff --git a/src/views/main-panel/main-panel-root.tsx b/src/views/main-panel/main-panel-root.tsx index 15149dce..b96e3cc8 100644 --- a/src/views/main-panel/main-panel-root.tsx +++ b/src/views/main-panel/main-panel-root.tsx @@ -26,22 +26,24 @@ export interface MainPanelRootDataProps { working: boolean; loading: boolean; buildInfo: string; + uuidPrefix: string; } type MainPanelRootProps = MainPanelRootDataProps & WithStyles; export const MainPanelRoot = withStyles(styles)( - ({ classes, loading, working, user, buildInfo }: MainPanelRootProps) => - loading + ({ classes, loading, working, user, buildInfo, uuidPrefix }: MainPanelRootProps) => + loading ? : <> + buildInfo={buildInfo} + uuidPrefix={uuidPrefix}> {working ? : null} {user ? : } -); \ No newline at end of file +); diff --git a/src/views/main-panel/main-panel.tsx b/src/views/main-panel/main-panel.tsx index 7592afb3..087163dc 100644 --- a/src/views/main-panel/main-panel.tsx +++ b/src/views/main-panel/main-panel.tsx @@ -13,10 +13,11 @@ const mapStateToProps = (state: RootState): MainPanelRootDataProps => { user: state.auth.user, working: isSystemWorking(state.progressIndicator), loading: isWorkbenchLoading(state), - buildInfo: state.appInfo.buildInfo + buildInfo: state.appInfo.buildInfo, + uuidPrefix: state.properties.uuidPrefix }; }; const mapDispatchToProps = null; -export const MainPanel = connect(mapStateToProps, mapDispatchToProps)(MainPanelRoot); \ No newline at end of file +export const MainPanel = connect(mapStateToProps, mapDispatchToProps)(MainPanelRoot); -- 2.30.2