From c64fec0d9862798eb3050ce0520f521ba7805ba3 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Mon, 19 Apr 2021 09:48:30 -0400 Subject: [PATCH] Fixes SSO Redirect --- awx/ui_next/src/screens/Login/Login.jsx | 18 ++++++++++++++---- awx/ui_next/src/screens/Login/Login.test.jsx | 10 ++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/awx/ui_next/src/screens/Login/Login.jsx b/awx/ui_next/src/screens/Login/Login.jsx index a551c94c51..d23c0f4f82 100644 --- a/awx/ui_next/src/screens/Login/Login.jsx +++ b/awx/ui_next/src/screens/Login/Login.jsx @@ -42,12 +42,18 @@ function AWXLogin({ alt, i18n, isAuthenticated }) { isLoading: isCustomLoginInfoLoading, error: customLoginInfoError, request: fetchCustomLoginInfo, - result: { brandName, logo, loginInfo, socialAuthOptions }, + result: { + brandName, + logo, + loginInfo, + socialAuthOptions, + loginRedirectOverride, + }, } = useRequest( useCallback(async () => { const [ { - data: { custom_logo, custom_login_info }, + data: { custom_logo, custom_login_info, login_redirect_override }, }, { data: { BRAND_NAME }, @@ -61,11 +67,13 @@ function AWXLogin({ alt, i18n, isAuthenticated }) { const logoSrc = custom_logo ? `data:image/jpeg;${custom_logo}` : loginLogoSrc; + return { brandName: BRAND_NAME, logo: logoSrc, loginInfo: custom_login_info, socialAuthOptions: authData, + loginRedirectOverride: login_redirect_override, }; }, []), { @@ -84,7 +92,6 @@ function AWXLogin({ alt, i18n, isAuthenticated }) { useEffect(() => { fetchCustomLoginInfo(); }, [fetchCustomLoginInfo]); - const { isLoading: isAuthenticating, error: authenticationError, @@ -108,7 +115,10 @@ function AWXLogin({ alt, i18n, isAuthenticated }) { if (isCustomLoginInfoLoading) { return null; } - + if (!isAuthenticated(document.cookie) && loginRedirectOverride) { + window.location.replace(loginRedirectOverride); + return null; + } if (isAuthenticated(document.cookie)) { return ; } diff --git a/awx/ui_next/src/screens/Login/Login.test.jsx b/awx/ui_next/src/screens/Login/Login.test.jsx index 5866685779..d025c89f5c 100644 --- a/awx/ui_next/src/screens/Login/Login.test.jsx +++ b/awx/ui_next/src/screens/Login/Login.test.jsx @@ -10,6 +10,16 @@ import AWXLogin from './Login'; jest.mock('../../api'); +RootAPI.readAssetVariables.mockResolvedValue({ + data: { + BRAND_NAME: 'AWX', + }, +}); + +AuthAPI.read.mockResolvedValue({ + data: {}, +}); + describe('', () => { async function findChildren(wrapper) { const [