Merge pull request #221 from edx/van-401/redirect_mfe_to_follow_tpa_hint
redirect MFE to tpa url if tpa_hint
This commit is contained in:
@@ -13,6 +13,7 @@ export default function processLink(link) {
|
||||
|
||||
export const getTpaProvider = (tpaHintProvider, primaryProviders, secondaryProviders) => {
|
||||
let tpaProvider = null;
|
||||
let isSecondaryProvider = false;
|
||||
primaryProviders.forEach((provider) => {
|
||||
if (provider.id === tpaHintProvider) {
|
||||
tpaProvider = provider;
|
||||
@@ -23,10 +24,11 @@ export const getTpaProvider = (tpaHintProvider, primaryProviders, secondaryProvi
|
||||
secondaryProviders.forEach((provider) => {
|
||||
if (provider.id === tpaHintProvider) {
|
||||
tpaProvider = provider;
|
||||
isSecondaryProvider = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return tpaProvider;
|
||||
return { provider: tpaProvider, isSecondaryProvider };
|
||||
};
|
||||
|
||||
export const getTpaHint = () => {
|
||||
|
||||
@@ -274,7 +274,11 @@ class LoginPage extends React.Component {
|
||||
if (thirdPartyAuthApiStatus === PENDING_STATE) {
|
||||
return <Skeleton height={36} />;
|
||||
}
|
||||
const provider = getTpaProvider(this.tpaHint, providers, secondaryProviders);
|
||||
const { provider, isSecondaryProvider } = getTpaProvider(this.tpaHint, providers, secondaryProviders);
|
||||
if (isSecondaryProvider) {
|
||||
window.location.href = getConfig().LMS_BASE_URL + provider.loginUrl;
|
||||
return null;
|
||||
}
|
||||
return provider ? (<EnterpriseSSO provider={provider} intl={intl} />) : this.renderForm(
|
||||
currentProvider,
|
||||
providers,
|
||||
|
||||
@@ -459,7 +459,6 @@ 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: {
|
||||
@@ -476,7 +475,7 @@ describe('LoginPage', () => {
|
||||
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);
|
||||
mount(reduxWrapper(<IntlLoginPage {...props} />));
|
||||
expect(window.location.href).toEqual(getConfig().LMS_BASE_URL + secondaryProviders.loginUrl);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -621,7 +621,11 @@ class RegistrationPage extends React.Component {
|
||||
if (thirdPartyAuthApiStatus === PENDING_STATE) {
|
||||
return <Skeleton height={36} />;
|
||||
}
|
||||
const provider = getTpaProvider(this.tpaHint, providers, secondaryProviders);
|
||||
const { provider, isSecondaryProvider } = getTpaProvider(this.tpaHint, providers, secondaryProviders);
|
||||
if (isSecondaryProvider) {
|
||||
window.location.href = getConfig().LMS_BASE_URL + provider.registerUrl;
|
||||
return null;
|
||||
}
|
||||
return provider ? (<EnterpriseSSO provider={provider} intl={intl} />)
|
||||
: this.renderForm(
|
||||
currentProvider,
|
||||
|
||||
@@ -697,7 +697,6 @@ 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: {
|
||||
@@ -714,7 +713,7 @@ describe('RegistrationPageTests', () => {
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), 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);
|
||||
mount(reduxWrapper(<IntlRegistrationPage {...props} />));
|
||||
expect(window.location.href).toEqual(getConfig().LMS_BASE_URL + secondaryProviders.registerUrl);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user