Skip to content

Commit

Permalink
Merge pull request #20 from open-craft/artur/redirect-on-tpa-unlinked…
Browse files Browse the repository at this point in the history
…-redwood

feat: redirect to custom URL when third-party auth account is unlinked
  • Loading branch information
ArturGaspar authored Aug 2, 2024
2 parents 8efb225 + 8bf29dd commit b8a808f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ORDER_HISTORY_URL=null
REFRESH_ACCESS_TOKEN_ENDPOINT=null
SEGMENT_KEY=''
SITE_NAME=null
TPA_UNLINKED_ACCOUNT_PROVISION_URL=''
INFO_EMAIL=''
# ***** Cookies *****
USER_RETENTION_COOKIE_NAME=null
Expand Down
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ The authentication micro-frontend also requires the following additional variabl
- Enables the image layout feature within the authn. When set to True, this feature allows the inclusion of images in the base container layout. For more details on configuring this feature, please refer to the `Modifying base container <docs/how_tos/modifying_base_container.rst>`_.
- ``true`` | ``''`` (empty strings are falsy)

* - ``TPA_UNLINKED_ACCOUNT_PROVISION_URL``
- URL to redirect to when the identity provided by third-party authentication is not yet linked to a platform account. This allows for redirecting to a custom sign-up flow handled by an external service to create the linked account. An empty string (the default) disables this feature.
- ``http://example.com/signup`` | ``''``


edX-specific Environment Variables
==================================
Expand Down Expand Up @@ -219,4 +223,4 @@ Please see `LICENSE <https://github.com/openedx/frontend-app-authn/blob/master/L
:target: https://github.com/openedx/edx-developer-docs/actions/workflows/ci.yml
:alt: Continuous Integration
.. |semantic-release| image:: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
:target: https://github.com/semantic-release/semantic-release
:target: https://github.com/semantic-release/semantic-release
1 change: 1 addition & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const configuration = {
SEARCH_CATALOG_URL: process.env.SEARCH_CATALOG_URL || null,
TOS_AND_HONOR_CODE: process.env.TOS_AND_HONOR_CODE || null,
TOS_LINK: process.env.TOS_LINK || null,
TPA_UNLINKED_ACCOUNT_PROVISION_URL: process.env.TPA_UNLINKED_ACCOUNT_PROVISION_URL || null,
// Base container images
BANNER_IMAGE_LARGE: process.env.BANNER_IMAGE_LARGE || '',
BANNER_IMAGE_MEDIUM: process.env.BANNER_IMAGE_MEDIUM || '',
Expand Down
12 changes: 12 additions & 0 deletions src/login/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ const LoginPage = (props) => {

const { provider, skipHintedLogin } = getTpaProvider(tpaHint, providers, secondaryProviders);

const unlinkedProvisionUrl = getConfig().TPA_UNLINKED_ACCOUNT_PROVISION_URL;

/**
* When currentProvider exists and we are in a login page, it is
* because the third-party authenticated account is not linked.
* See also ThirdPartyAuthAlert.jsx.
*/
if (currentProvider && unlinkedProvisionUrl) {
window.location.href = unlinkedProvisionUrl;
return null;
}

if (tpaHint) {
if (thirdPartyAuthApiStatus === PENDING_STATE) {
return <Skeleton height={36} />;
Expand Down
46 changes: 46 additions & 0 deletions src/login/tests/LoginPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,50 @@ describe('LoginPage', () => {
expect(container.querySelector('input#emailOrUsername').value).toEqual('john_doe');
expect(container.querySelector('input#password').value).toEqual('test-password');
});

it('should not redirect to provisioning URL when not configured', () => {
mergeConfig({
TPA_UNLINKED_ACCOUNT_PROVISION_URL: '',
});

store = mockStore({
...initialState,
commonComponents: {
...initialState.commonComponents,
thirdPartyAuthContext: {
...initialState.commonComponents.thirdPartyAuthContext,
currentProvider: ssoProvider.name,
},
},
});

delete window.location;
window.location = { href: getConfig().BASE_URL.concat(LOGIN_PAGE) };

render(reduxWrapper(<IntlLoginPage {...props} />));
expect(window.location.href).toEqual(getConfig().BASE_URL.concat(LOGIN_PAGE));
});

it('should redirect to provisioning URL on unlinked third-party auth account', () => {
mergeConfig({
TPA_UNLINKED_ACCOUNT_PROVISION_URL: 'http://example.com/signup',
});

store = mockStore({
...initialState,
commonComponents: {
...initialState.commonComponents,
thirdPartyAuthContext: {
...initialState.commonComponents.thirdPartyAuthContext,
currentProvider: ssoProvider.name,
},
},
});

delete window.location;
window.location = { href: getConfig().BASE_URL.concat(LOGIN_PAGE) };

render(reduxWrapper(<IntlLoginPage {...props} />));
expect(window.location.href).toEqual('http://example.com/signup');
});
});

0 comments on commit b8a808f

Please sign in to comment.