Merge pull request #9943 from AlexSCorey/9115-SSOFix

Fixes SSO Redirect

SUMMARY
This fixes #9115 by simply checking if there is a redirect url in and then replacing it with the existing url in history, navigating the user to the correct login url.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

UI

AWX VERSION
ADDITIONAL INFORMATION

Reviewed-by: Jake McDermott <yo@jakemcdermott.me>
Reviewed-by: Alex Corey <Alex.swansboro@gmail.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-04-22 20:47:52 +00:00 committed by GitHub
commit 8d20add2d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -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 <Redirect to="/" />;
}

View File

@ -10,6 +10,16 @@ import AWXLogin from './Login';
jest.mock('../../api');
RootAPI.readAssetVariables.mockResolvedValue({
data: {
BRAND_NAME: 'AWX',
},
});
AuthAPI.read.mockResolvedValue({
data: {},
});
describe('<Login />', () => {
async function findChildren(wrapper) {
const [