Skip to content

Commit f4d1db5

Browse files
committed
feat: redirect to custom URL when third-party auth account is unlinked
1 parent 38c186d commit f4d1db5

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ORDER_HISTORY_URL=null
1313
REFRESH_ACCESS_TOKEN_ENDPOINT=null
1414
SEGMENT_KEY=''
1515
SITE_NAME=null
16+
TPA_UNLINKED_ACCOUNT_PROVISION_URL=null
1617
INFO_EMAIL=''
1718
# ***** Cookies *****
1819
USER_RETENTION_COOKIE_NAME=null

src/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const configuration = {
1919
SEARCH_CATALOG_URL: process.env.SEARCH_CATALOG_URL || null,
2020
TOS_AND_HONOR_CODE: process.env.TOS_AND_HONOR_CODE || null,
2121
TOS_LINK: process.env.TOS_LINK || null,
22+
TPA_UNLINKED_ACCOUNT_PROVISION_URL: process.env.TPA_UNLINKED_ACCOUNT_PROVISION_URL || null,
2223
// Base container images
2324
BANNER_IMAGE_LARGE: process.env.BANNER_IMAGE_LARGE || '',
2425
BANNER_IMAGE_MEDIUM: process.env.BANNER_IMAGE_MEDIUM || '',

src/login/LoginPage.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,18 @@ class LoginPage extends React.Component {
310310
} = this.props;
311311
const { currentProvider, providers, secondaryProviders } = this.props.thirdPartyAuthContext;
312312

313+
const unlinkedProvisionUrl = getConfig().TPA_UNLINKED_ACCOUNT_PROVISION_URL;
314+
315+
/**
316+
* When currentProvider exists and we are in a login page, it is
317+
* because the third-party authenticated account is not linked.
318+
* See also ThirdPartyAuthAlert.jsx.
319+
*/
320+
if (currentProvider && unlinkedProvisionUrl) {
321+
window.location.href = unlinkedProvisionUrl;
322+
return null;
323+
}
324+
313325
if (this.tpaHint) {
314326
if (thirdPartyAuthApiStatus === PENDING_STATE) {
315327
return <Skeleton height={36} />;

src/login/tests/LoginPage.test.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,4 +766,24 @@ describe('LoginPage', () => {
766766

767767
expect(store.dispatch).toHaveBeenCalledWith(loginRemovePasswordResetBanner());
768768
});
769+
770+
it('should redirect to provisioning URL on unlinked third-party auth account', () => {
771+
mergeConfig({
772+
TPA_UNLINKED_ACCOUNT_PROVISION_URL: 'http://example.com',
773+
});
774+
775+
store = mockStore({
776+
...initialState,
777+
commonComponents: {
778+
...initialState.commonComponents,
779+
thirdPartyAuthContext: {
780+
...initialState.commonComponents.thirdPartyAuthContext,
781+
currentProvider: ssoProvider.name,
782+
},
783+
},
784+
});
785+
786+
const loginPage = mount(reduxWrapper(<IntlLoginPage {...props} />));
787+
expect(window.location.href).toEqual('http://example.com');
788+
});
769789
});

0 commit comments

Comments
 (0)