From c860176fbbabe5e669b793779156763bfc97e97c Mon Sep 17 00:00:00 2001 From: alfredorubin96 Date: Fri, 29 Nov 2024 14:08:50 +0100 Subject: [PATCH 1/3] fixing strange param behaviour with sso --- src/application/ApplicationThunks.ts | 29 +++++++++++++++++++--------- src/component/sso/SSOLoginButton.tsx | 13 ++++++++++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/application/ApplicationThunks.ts b/src/application/ApplicationThunks.ts index 6af4b6339..6fcf88155 100644 --- a/src/application/ApplicationThunks.ts +++ b/src/application/ApplicationThunks.ts @@ -291,7 +291,6 @@ export const handleSharedDashboardsThunk = () => (dispatch: any) => { if (skipConfirmation === true) { dispatch(onConfirmLoadSharedDashboardThunk()); } - window.history.pushState({}, document.title, window.location.pathname); } else { dispatch(setConnectionModalOpen(false)); @@ -358,7 +357,6 @@ export const onConfirmLoadSharedDashboardThunk = () => (dispatch: any, getState: } if (shareDetails.standalone == true) { dispatch(setStandaloneMode(true)); - localStorage.setItem('standaloneShared', 'true'); // EDGE CASE: redirect SSO removes the shareDetails when redirecting } dispatch(resetShareDetails()); } catch (e) { @@ -410,29 +408,35 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: try { // Parse the URL parameters to see if there's any deep linking of parameters. + const state = getState(); const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); + if (state.application.waitForSSO) { + const paramsBeforeSSO = JSON.parse(sessionStorage.getItem('SSO_PARAMS_BEFORE_REDIRECT') || '{}'); + Object.entries(paramsBeforeSSO).forEach(([key, value]) => { + urlParams.set(key, value); + }); + } const paramsToSetAfterConnecting = {}; Array.from(urlParams.entries()).forEach(([key, value]) => { if (key.startsWith('neodash_')) { paramsToSetAfterConnecting[key] = value; } }); - + sessionStorage.getItem('SSO_PARAMS_BEFORE_REDIRECT'); const page = urlParams.get('page'); if (page !== '' && page !== null) { if (!isNaN(page)) { dispatch(setPageNumberThunk(parseInt(page))); } } - const state = getState(); dispatch(setSSOEnabled(config.ssoEnabled, state.application.cachedSSODiscoveryUrl)); dispatch(setSSOProviders(config.ssoProviders)); // Check if we are in standalone mode - // const standaloneShared = localStorage.getItem('standaloneShared') == 'true'; // EDGE case: from url param it could happen that we lose the value due to SSO redirect - const { standalone } = config; - // || standaloneShared; + const standalone = config.standalone || urlParams.get('standalone') == 'Yes'; + console.log(urlParams.get('standalone')); + console.log(standalone); // if a dashboard database was previously set, remember to use it. const dashboardDatabase = state.application.standaloneDashboardDatabase; @@ -455,7 +459,6 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: config.standaloneDatabaseList ) ); - localStorage.removeItem('standaloneShared'); dispatch(setLoggingMode(config.loggingMode)); dispatch(setLoggingDatabase(config.loggingDatabase)); @@ -491,6 +494,7 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: dispatch(setAboutModalOpen(false)); dispatch(setConnected(false)); dispatch(setWelcomeScreenOpen(false)); + console.log('EDDAJE'); const success = await initializeSSO(state.application.cachedSSODiscoveryUrl, (credentials) => { if (standalone) { // Redirected from SSO and running in viewer mode, merge retrieved config with hardcoded credentials. @@ -537,6 +541,7 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: } dispatch(setParametersToLoadAfterConnecting(paramsToSetAfterConnecting)); } + sessionStorage.removeItem('SSO_PARAMS_BEFORE_REDIRECT'); }); dispatch(setWaitForSSO(false)); if (!success) { @@ -550,7 +555,13 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: } else { return; } - } + } else if (state.application.ssoEnabled && !state.application.waitForSSO && urlParams) { + let paramsToStore = {}; + urlParams.forEach((value, key) => { + paramsToStore[key] = value; + }); + sessionStorage.setItem('SSO_PARAMS_BEFORE_REDIRECT', JSON.stringify(paramsToStore)); + } if (standalone) { dispatch(initializeApplicationAsStandaloneThunk(config, paramsToSetAfterConnecting)); diff --git a/src/component/sso/SSOLoginButton.tsx b/src/component/sso/SSOLoginButton.tsx index b22b47163..fab194260 100644 --- a/src/component/sso/SSOLoginButton.tsx +++ b/src/component/sso/SSOLoginButton.tsx @@ -6,7 +6,7 @@ import { Button, IconButton } from '@neo4j-ndl/react'; export const SSOLoginButton = ({ discoveryAPIUrl, hostname, port, onSSOAttempt, onClick, providers }) => { const [savedSSOProviders, setSSOProviders] = useState([]); - const [discoveryUrlValidated, setDiscoveryUrlValidated] = useState(undefined); + const [discoveryUrlValidated, setDiscoveryUrlValidated] = useState(undefined); const filterByProvidersList = (discoveredProviders, validProviders) => { return validProviders == null || validProviders.length == 0 @@ -15,19 +15,26 @@ export const SSOLoginButton = ({ discoveryAPIUrl, hostname, port, onSSOAttempt, }; const attemptManualSSOProviderRetrieval = () => { // Do an extra check to see if the hostname provides some SSO provider configuration. - getDiscoveryDataInfo(`https://${hostname}:${port}`) + const protocol = isLocalhost(hostname) ? 'http' : 'https'; + const discoveryUrl = `${protocol}://${hostname}:${port}`; + getDiscoveryDataInfo(discoveryUrl) .then((mergedSSOProviders) => { setSSOProviders(filterByProvidersList(mergedSSOProviders, providers)); if (mergedSSOProviders.length == 0) { setDiscoveryUrlValidated(undefined); } else { - setDiscoveryUrlValidated(`https://${hostname}:${port}`); + setDiscoveryUrlValidated(discoveryUrl); } }) // eslint-disable-next-line no-console .catch((err) => console.error('Error in getDiscoveryDataInfo of Login component', err)); }; + function isLocalhost(hostname) { + const localhostNames = ['localhost', '127.0.0.1', '::1']; + return localhostNames.includes(hostname); + } + useEffect(() => { // First, try to get the SSO discovery URL from the config.json configuration file and see if it contains anything. getDiscoveryDataInfo(discoveryAPIUrl) From 1642bb972745d8725b8cbd1aaf398d11179dc03d Mon Sep 17 00:00:00 2001 From: alfredorubin96 Date: Mon, 2 Dec 2024 12:07:08 +0100 Subject: [PATCH 2/3] fixing params for SSo --- src/application/ApplicationThunks.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/application/ApplicationThunks.ts b/src/application/ApplicationThunks.ts index 6fcf88155..07c5a8826 100644 --- a/src/application/ApplicationThunks.ts +++ b/src/application/ApplicationThunks.ts @@ -534,7 +534,9 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: } if (standalone) { - if (config.standaloneDashboardURL !== undefined && config.standaloneDashboardURL.length > 0) { + if (urlParams.get('id')) { + dispatch(setDashboardToLoadAfterConnecting(urlParams.get('id'))); + } else if (config.standaloneDashboardURL !== undefined && config.standaloneDashboardURL.length > 0) { dispatch(setDashboardToLoadAfterConnecting(config.standaloneDashboardURL)); } else { dispatch(setDashboardToLoadAfterConnecting(`name:${config.standaloneDashboardName}`)); @@ -543,6 +545,7 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: } sessionStorage.removeItem('SSO_PARAMS_BEFORE_REDIRECT'); }); + dispatch(setWaitForSSO(false)); if (!success) { alert('Unable to connect using SSO. See the browser console for more details.'); @@ -556,12 +559,12 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: return; } } else if (state.application.ssoEnabled && !state.application.waitForSSO && urlParams) { - let paramsToStore = {}; - urlParams.forEach((value, key) => { - paramsToStore[key] = value; - }); - sessionStorage.setItem('SSO_PARAMS_BEFORE_REDIRECT', JSON.stringify(paramsToStore)); - } + let paramsToStore = {}; + urlParams.forEach((value, key) => { + paramsToStore[key] = value; + }); + sessionStorage.setItem('SSO_PARAMS_BEFORE_REDIRECT', JSON.stringify(paramsToStore)); + } if (standalone) { dispatch(initializeApplicationAsStandaloneThunk(config, paramsToSetAfterConnecting)); From 563a1d697ba2e0cf2c65a8527bde11aa44cdb3e7 Mon Sep 17 00:00:00 2001 From: alfredorubin96 Date: Mon, 2 Dec 2024 13:02:37 +0100 Subject: [PATCH 3/3] removing useless logging --- src/application/ApplicationThunks.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/application/ApplicationThunks.ts b/src/application/ApplicationThunks.ts index 07c5a8826..67f48b726 100644 --- a/src/application/ApplicationThunks.ts +++ b/src/application/ApplicationThunks.ts @@ -435,8 +435,6 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: // Check if we are in standalone mode const standalone = config.standalone || urlParams.get('standalone') == 'Yes'; - console.log(urlParams.get('standalone')); - console.log(standalone); // if a dashboard database was previously set, remember to use it. const dashboardDatabase = state.application.standaloneDashboardDatabase; @@ -494,7 +492,6 @@ export const loadApplicationConfigThunk = () => async (dispatch: any, getState: dispatch(setAboutModalOpen(false)); dispatch(setConnected(false)); dispatch(setWelcomeScreenOpen(false)); - console.log('EDDAJE'); const success = await initializeSSO(state.application.cachedSSODiscoveryUrl, (credentials) => { if (standalone) { // Redirected from SSO and running in viewer mode, merge retrieved config with hardcoded credentials.