skip hinted login check added for enterprise SSO

This commit is contained in:
adeelehsan
2021-03-30 11:22:07 +05:00
parent 3147ad13d8
commit 41a0deea5b
5 changed files with 59 additions and 19 deletions

View File

@@ -13,22 +13,16 @@ export default function processLink(link) {
export const getTpaProvider = (tpaHintProvider, primaryProviders, secondaryProviders) => {
let tpaProvider = null;
let isSecondaryProvider = false;
primaryProviders.forEach((provider) => {
let skipHintedLogin = false;
[...primaryProviders, ...secondaryProviders].forEach((provider) => {
if (provider.id === tpaHintProvider) {
tpaProvider = provider;
if (provider.skipHintedLogin) {
skipHintedLogin = true;
}
}
});
if (!tpaProvider) {
secondaryProviders.forEach((provider) => {
if (provider.id === tpaHintProvider) {
tpaProvider = provider;
isSecondaryProvider = true;
}
});
}
return { provider: tpaProvider, isSecondaryProvider };
return { provider: tpaProvider, skipHintedLogin };
};
export const getTpaHint = () => {

View File

@@ -276,8 +276,8 @@ class LoginPage extends React.Component {
if (thirdPartyAuthApiStatus === PENDING_STATE) {
return <Skeleton height={36} />;
}
const { provider, isSecondaryProvider } = getTpaProvider(this.tpaHint, providers, secondaryProviders);
if (isSecondaryProvider) {
const { provider, skipHintedLogin } = getTpaProvider(this.tpaHint, providers, secondaryProviders);
if (skipHintedLogin) {
window.location.href = getConfig().LMS_BASE_URL + provider.loginUrl;
return null;
}

View File

@@ -49,6 +49,7 @@ describe('LoginPage', () => {
name: 'Test University',
loginUrl: '/dummy-auth',
registerUrl: '/dummy_auth',
skipHintedLogin: false,
};
const appleProvider = {
@@ -459,6 +460,28 @@ describe('LoginPage', () => {
});
it('should render tpa button for tpa_hint id in secondary provider', () => {
const expectedMessage = `Sign in using ${secondaryProviders.name}`;
store = mockStore({
...initialState,
commonComponents: {
...initialState.commonComponents,
thirdPartyAuthContext: {
...initialState.commonComponents.thirdPartyAuthContext,
secondaryProviders: [secondaryProviders],
},
thirdPartyAuthApiStatus: COMPLETE_STATE,
},
});
delete window.location;
window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
secondaryProviders.iconImage = null;
const loginPage = mount(reduxWrapper(<IntlLoginPage {...props} />));
expect(loginPage.find(`button#${secondaryProviders.id}`).find('span').text()).toEqual(expectedMessage);
});
it('should redirect to idp page if skipHinetedLogin is true', () => {
secondaryProviders.skipHintedLogin = true;
store = mockStore({
...initialState,
commonComponents: {

View File

@@ -626,8 +626,8 @@ class RegistrationPage extends React.Component {
if (thirdPartyAuthApiStatus === PENDING_STATE) {
return <Skeleton height={36} />;
}
const { provider, isSecondaryProvider } = getTpaProvider(this.tpaHint, providers, secondaryProviders);
if (isSecondaryProvider) {
const { provider, skipHintedLogin } = getTpaProvider(this.tpaHint, providers, secondaryProviders);
if (skipHintedLogin) {
window.location.href = getConfig().LMS_BASE_URL + provider.registerUrl;
return null;
}

View File

@@ -65,6 +65,7 @@ describe('RegistrationPageTests', () => {
name: 'Test University',
loginUrl: '/dummy-auth',
registerUrl: '/dummy_auth',
skipHintedLogin: false,
};
const emptyFieldValidation = {
@@ -667,7 +668,7 @@ describe('RegistrationPageTests', () => {
});
delete window.location;
window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${appleProvider.id}` };
window.location = { href: getConfig().BASE_URL.concat('/register'), search: `?next=/dashboard&tpa_hint=${appleProvider.id}` };
appleProvider.iconImage = null;
const registerPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
@@ -689,7 +690,7 @@ describe('RegistrationPageTests', () => {
});
delete window.location;
window.location = { href: getConfig().BASE_URL.concat('/login'), search: '?next=/dashboard&tpa_hint=invalid' };
window.location = { href: getConfig().BASE_URL.concat('/register'), search: '?next=/dashboard&tpa_hint=invalid' };
appleProvider.iconImage = null;
const registerPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
@@ -697,6 +698,28 @@ describe('RegistrationPageTests', () => {
});
it('should render tpa button for tpa_hint id in secondary provider', () => {
const expectedMessage = `Sign in using ${secondaryProviders.name}`;
store = mockStore({
...initialState,
commonComponents: {
...initialState.commonComponents,
thirdPartyAuthContext: {
...initialState.commonComponents.thirdPartyAuthContext,
secondaryProviders: [secondaryProviders],
},
thirdPartyAuthApiStatus: COMPLETE_STATE,
},
});
delete window.location;
window.location = { href: getConfig().BASE_URL.concat('/register'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
secondaryProviders.iconImage = null;
const registerPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
expect(registerPage.find(`button#${secondaryProviders.id}`).find('span').text()).toEqual(expectedMessage);
});
it('should redirect to idp page if skipHinetedLogin is true', () => {
secondaryProviders.skipHintedLogin = true;
store = mockStore({
...initialState,
commonComponents: {
@@ -710,7 +733,7 @@ describe('RegistrationPageTests', () => {
});
delete window.location;
window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
window.location = { href: getConfig().BASE_URL.concat('/register'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
secondaryProviders.iconImage = null;
mount(reduxWrapper(<IntlRegistrationPage {...props} />));