From a53a8d8ca7a1f783e22939d1e31ad043ced82b3f Mon Sep 17 00:00:00 2001 From: karanh37 Date: Tue, 24 Sep 2024 15:06:30 +0530 Subject: [PATCH 1/4] move routes to callback router --- .../components/AppRouter/CallbackRouter.tsx | 51 +++++++++++++++++++ .../AppRouter/UnAuthenticatedAppRouter.tsx | 3 ++ 2 files changed, 54 insertions(+) create mode 100644 openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx new file mode 100644 index 000000000000..1ff6ef8944c6 --- /dev/null +++ b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx @@ -0,0 +1,51 @@ +/* + * Copyright 2024 Collate. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { LoginCallback } from '@okta/okta-react'; +import React, { useMemo } from 'react'; +import { Route, Switch } from 'react-router-dom'; +import { ROUTES } from '../../constants/constants'; +import { AuthProvider } from '../../generated/configuration/authenticationConfiguration'; +import { useApplicationStore } from '../../hooks/useApplicationStore'; +import SamlCallback from '../../pages/SamlCallback'; +import Auth0Callback from '../Auth/AppCallbacks/Auth0Callback/Auth0Callback'; + +const CallbackRouter = () => { + const { authConfig } = useApplicationStore(); + const callbackComponent = useMemo(() => { + switch (authConfig?.provider) { + case AuthProvider.Okta: { + return LoginCallback; + } + case AuthProvider.Auth0: { + return Auth0Callback; + } + default: { + return null; + } + } + }, [authConfig?.provider]); + + return ( + + {callbackComponent && ( + + )} + + + ); +}; + +export default CallbackRouter; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx index f1d2f8dac8af..6f9820e851b7 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx @@ -22,6 +22,7 @@ import SamlCallback from '../../pages/SamlCallback'; import AccountActivationConfirmation from '../../pages/SignUp/account-activation-confirmation.component'; import { isProtectedRoute } from '../../utils/AuthProvider.util'; import Auth0Callback from '../Auth/AppCallbacks/Auth0Callback/Auth0Callback'; +import CallbackRouter from './CallbackRouter'; import withSuspenseFallback from './withSuspenseFallback'; const SigninPage = withSuspenseFallback( @@ -89,6 +90,8 @@ export const UnAuthenticatedAppRouter = () => { {/* keep this route before any conditional JSX.Element rendering */} + + {isBasicAuthProvider && ( <> From a2940dcc1f1478fcbb33ab2c038bd0ea4b36427f Mon Sep 17 00:00:00 2001 From: karanh37 Date: Tue, 24 Sep 2024 19:00:28 +0530 Subject: [PATCH 2/4] move callback routes to global router --- .../ui/src/components/AppRouter/AppRouter.tsx | 32 +++++++++++- .../components/AppRouter/CallbackRouter.tsx | 51 ------------------- .../AppRouter/UnAuthenticatedAppRouter.tsx | 29 +---------- 3 files changed, 31 insertions(+), 81 deletions(-) delete mode 100644 openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx index ab449c663aee..43f0425e4558 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx @@ -11,8 +11,9 @@ * limitations under the License. */ +import { LoginCallback } from '@okta/okta-react'; import { isEmpty, isNil } from 'lodash'; -import React, { useCallback, useEffect } from 'react'; +import React, { useCallback, useEffect, useMemo } from 'react'; import { Redirect, Route, Switch } from 'react-router-dom'; import { useAnalytics } from 'use-analytics'; import { ROUTES } from '../../constants/constants'; @@ -23,17 +24,35 @@ import AccessNotAllowedPage from '../../pages/AccessNotAllowedPage/AccessNotAllo import PageNotFound from '../../pages/PageNotFound/PageNotFound'; import SignUpPage from '../../pages/SignUp/SignUpPage'; import AppContainer from '../AppContainer/AppContainer'; +import Auth0Callback from '../Auth/AppCallbacks/Auth0Callback/Auth0Callback'; import Loader from '../common/Loader/Loader'; import { UnAuthenticatedAppRouter } from './UnAuthenticatedAppRouter'; +import { AuthProvider } from '../../generated/configuration/authenticationConfiguration'; +import SamlCallback from '../../pages/SamlCallback'; + const AppRouter = () => { const location = useCustomLocation(); // web analytics instance const analytics = useAnalytics(); - const { currentUser, isAuthenticated, isApplicationLoading } = + const { authConfig, currentUser, isAuthenticated, isApplicationLoading } = useApplicationStore(); + const callbackComponent = useMemo(() => { + switch (authConfig?.provider) { + case AuthProvider.Okta: { + return LoginCallback; + } + case AuthProvider.Auth0: { + return Auth0Callback; + } + default: { + return null; + } + } + }, [authConfig?.provider]); + useEffect(() => { const { pathname } = location; @@ -92,6 +111,15 @@ const AppRouter = () => { {!isEmpty(currentUser) && } + + {callbackComponent && ( + + )} + + {isAuthenticated ? : } ); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx deleted file mode 100644 index 1ff6ef8944c6..000000000000 --- a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/CallbackRouter.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2024 Collate. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { LoginCallback } from '@okta/okta-react'; -import React, { useMemo } from 'react'; -import { Route, Switch } from 'react-router-dom'; -import { ROUTES } from '../../constants/constants'; -import { AuthProvider } from '../../generated/configuration/authenticationConfiguration'; -import { useApplicationStore } from '../../hooks/useApplicationStore'; -import SamlCallback from '../../pages/SamlCallback'; -import Auth0Callback from '../Auth/AppCallbacks/Auth0Callback/Auth0Callback'; - -const CallbackRouter = () => { - const { authConfig } = useApplicationStore(); - const callbackComponent = useMemo(() => { - switch (authConfig?.provider) { - case AuthProvider.Okta: { - return LoginCallback; - } - case AuthProvider.Auth0: { - return Auth0Callback; - } - default: { - return null; - } - } - }, [authConfig?.provider]); - - return ( - - {callbackComponent && ( - - )} - - - ); -}; - -export default CallbackRouter; diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx index 6f9820e851b7..608439044584 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/UnAuthenticatedAppRouter.tsx @@ -10,19 +10,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { LoginCallback } from '@okta/okta-react'; -import React, { useMemo } from 'react'; +import React from 'react'; import { Redirect, Route, Switch } from 'react-router-dom'; import { ROUTES } from '../../constants/constants'; import { AuthProvider } from '../../generated/configuration/authenticationConfiguration'; import { useApplicationStore } from '../../hooks/useApplicationStore'; import useCustomLocation from '../../hooks/useCustomLocation/useCustomLocation'; import PageNotFound from '../../pages/PageNotFound/PageNotFound'; -import SamlCallback from '../../pages/SamlCallback'; import AccountActivationConfirmation from '../../pages/SignUp/account-activation-confirmation.component'; import { isProtectedRoute } from '../../utils/AuthProvider.util'; -import Auth0Callback from '../Auth/AppCallbacks/Auth0Callback/Auth0Callback'; -import CallbackRouter from './CallbackRouter'; import withSuspenseFallback from './withSuspenseFallback'; const SigninPage = withSuspenseFallback( @@ -52,20 +48,6 @@ export const UnAuthenticatedAppRouter = () => { (authConfig.provider === AuthProvider.Basic || authConfig.provider === AuthProvider.LDAP); - const callbackComponent = useMemo(() => { - switch (authConfig?.provider) { - case AuthProvider.Okta: { - return LoginCallback; - } - case AuthProvider.Auth0: { - return Auth0Callback; - } - default: { - return null; - } - } - }, [authConfig?.provider]); - if (isProtectedRoute(location.pathname)) { return ; } @@ -74,13 +56,6 @@ export const UnAuthenticatedAppRouter = () => { - {callbackComponent && ( - - )} - {!isSigningUp && ( @@ -90,8 +65,6 @@ export const UnAuthenticatedAppRouter = () => { {/* keep this route before any conditional JSX.Element rendering */} - - {isBasicAuthProvider && ( <> From 20098fe15edbde7a27d003aa534d2675dae4fdf9 Mon Sep 17 00:00:00 2001 From: karanh37 Date: Tue, 24 Sep 2024 19:09:53 +0530 Subject: [PATCH 3/4] added comments --- .../main/resources/ui/src/components/AppRouter/AppRouter.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx index 43f0425e4558..06fdcdc1325b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx @@ -112,6 +112,8 @@ const AppRouter = () => { {!isEmpty(currentUser) && } + {/* When authenticating from an SSO provider page (e.g., SAML Apps), if the user is already logged in, + the callbacks should be available. This ensures consistent behavior across different authentication scenarios. */} {callbackComponent && ( )} From 1144c0ddeca1de8e5b9d1f22addf10185a9a592f Mon Sep 17 00:00:00 2001 From: karanh37 Date: Fri, 27 Sep 2024 16:58:05 +0530 Subject: [PATCH 4/4] make saml and confidential callback route public --- .../ui/src/components/AppRouter/AppRouter.tsx | 24 ++----------------- .../AppRouter/UnAuthenticatedAppRouter.tsx | 22 ++++++++++++++++- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx index 06fdcdc1325b..f50f6579c3c5 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/AppRouter/AppRouter.tsx @@ -11,9 +11,8 @@ * limitations under the License. */ -import { LoginCallback } from '@okta/okta-react'; import { isEmpty, isNil } from 'lodash'; -import React, { useCallback, useEffect, useMemo } from 'react'; +import React, { useCallback, useEffect } from 'react'; import { Redirect, Route, Switch } from 'react-router-dom'; import { useAnalytics } from 'use-analytics'; import { ROUTES } from '../../constants/constants'; @@ -24,11 +23,9 @@ import AccessNotAllowedPage from '../../pages/AccessNotAllowedPage/AccessNotAllo import PageNotFound from '../../pages/PageNotFound/PageNotFound'; import SignUpPage from '../../pages/SignUp/SignUpPage'; import AppContainer from '../AppContainer/AppContainer'; -import Auth0Callback from '../Auth/AppCallbacks/Auth0Callback/Auth0Callback'; import Loader from '../common/Loader/Loader'; import { UnAuthenticatedAppRouter } from './UnAuthenticatedAppRouter'; -import { AuthProvider } from '../../generated/configuration/authenticationConfiguration'; import SamlCallback from '../../pages/SamlCallback'; const AppRouter = () => { @@ -36,23 +33,9 @@ const AppRouter = () => { // web analytics instance const analytics = useAnalytics(); - const { authConfig, currentUser, isAuthenticated, isApplicationLoading } = + const { currentUser, isAuthenticated, isApplicationLoading } = useApplicationStore(); - const callbackComponent = useMemo(() => { - switch (authConfig?.provider) { - case AuthProvider.Okta: { - return LoginCallback; - } - case AuthProvider.Auth0: { - return Auth0Callback; - } - default: { - return null; - } - } - }, [authConfig?.provider]); - useEffect(() => { const { pathname } = location; @@ -114,9 +97,6 @@ const AppRouter = () => { {/* When authenticating from an SSO provider page (e.g., SAML Apps), if the user is already logged in, the callbacks should be available. This ensures consistent behavior across different authentication scenarios. */} - {callbackComponent && ( - - )} { (authConfig.provider === AuthProvider.Basic || authConfig.provider === AuthProvider.LDAP); + const callbackComponent = useMemo(() => { + switch (authConfig?.provider) { + case AuthProvider.Okta: { + return LoginCallback; + } + case AuthProvider.Auth0: { + return Auth0Callback; + } + default: { + return null; + } + } + }, [authConfig?.provider]); + if (isProtectedRoute(location.pathname)) { return ; } @@ -56,6 +72,10 @@ export const UnAuthenticatedAppRouter = () => { + {callbackComponent && ( + + )} + {!isSigningUp && (