Skip to content

fix: redirect TPA account_settings errors to Account MFE with duplica…#38673

Draft
Gi-ron wants to merge 1 commit into
openedx:masterfrom
eduNEXT:sgb/render-tpa-account-mfe-error
Draft

fix: redirect TPA account_settings errors to Account MFE with duplica…#38673
Gi-ron wants to merge 1 commit into
openedx:masterfrom
eduNEXT:sgb/render-tpa-account-mfe-error

Conversation

@Gi-ron
Copy link
Copy Markdown

@Gi-ron Gi-ron commented May 28, 2026

PR Description

When a SAML (or any third-party auth) error occurs during the Linked Accounts flow in the Account MFE, for example, AuthAlreadyAssociated when a user tries to link an IdP identity that is already linked to a different platform account the error context was silently lost before reaching the user.

Root cause: ExceptionMiddleware.get_redirect_uri() returned /account/settings, which is registered as a stateless RedirectView that redirects directly to ACCOUNT_MICROFRONTEND_URL without forwarding Django messages or query parameters. As a result, the user was redirected to the Account MFE with no indication of what went wrong.


Changes

common/djangoapps/third_party_auth/pipeline.py

  • Changed AUTH_DISPATCH_URLS[AUTH_ENTRY_ACCOUNT_SETTINGS] from /account/settings to /auth/account_settings_error.
  • This routes error redirects through the new intermediate view instead of the stateless RedirectView.

common/djangoapps/third_party_auth/views.py

  • Added account_settings_error_view: an intermediate Django view that reads the Django message left by SocialAuthExceptionMiddleware, resolves the human-readable provider name via provider.Registry.get_enabled_by_backend_name(), and redirects to the Account MFE with ?duplicate_provider=<provider_name>.
  • This approach works for all backend types: SAML, OAuth2, and LTI.

common/djangoapps/third_party_auth/urls.py

  • Registered the new view at auth/account_settings_error.

openedx/core/djangoapps/user_api/legacy_urls.py

  • Added query_string=True to the existing /account/settings RedirectView as a defensive improvement, so any future redirects to that URL preserve query parameters.

How it works

Before:

AuthAlreadyAssociated
→ ExceptionMiddleware → /account/settings
→ RedirectView (stateless) → Account MFE (no error context)

After:

AuthAlreadyAssociated
→ ExceptionMiddleware → /auth/account_settings_error
→ account_settings_error_view reads Django messages
→ Account MFE /?duplicate_provider=SimpleSAML+Local


Screenshots

The user sees a clear error message in the Linked Accounts section.

image

Testing

Setup

  1. Configure a SAML IdP (e.g. SimpleSAMLphp) as a Third Party Auth provider in Django Admin.
  2. Create two platform accounts: user_a@example.com and user_b@example.com.
  3. Log in as user_a and complete the SAML login flow to link the IdP identity to user_a.
  4. Log out.

Reproduce the error

  1. Log in as user_b.
  2. Navigate to Account MFE → Linked Accounts.
  3. Click Sign in with [provider name] for the same SAML IdP.
  4. Complete authentication on the IdP side using the same identity used in step 3.

Expected result (after fix)

  • The user is redirected to the Account MFE at: https://<LMS_HOST>/account/?duplicate_provider=<Provider+Name>

  • The Account MFE displays the error message: The [Provider Name] account you selected is already linked to another [Site Name] account.

Expected result (before fix)

  • The user is silently redirected to the Account MFE homepage with no error message.

Additional notes

After the AuthAlreadyAssociated error occurs, user_b will not be able to link the provider
until one of the following conditions is met:

  • Sign out from the IdP session: Since the IdP session remains active after the error,
    user_b must sign out from the IdP (e.g. SimpleSAMLphp) before attempting to link again.
    Otherwise the IdP will silently reuse the same identity that is already linked to user_a,
    causing the error to repeat.

  • user_a unlinks their account: If user_a disconnects the provider from their Open edX
    account via Account MFE → Linked AccountsUnlink, the IdP identity becomes available
    again and user_b will be able to link it successfully on the next attempt.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label May 28, 2026
@openedx-webhooks
Copy link
Copy Markdown

Thanks for the pull request, @Gi-ron!

This repository is currently maintained by @openedx/wg-maintenance-openedx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Submit a signed contributor agreement (CLA)

⚠️ We ask all contributors to the Open edX project to submit a signed contributor agreement or indicate their institutional affiliation.
Please see the CONTRIBUTING file for more information.

If you've signed an agreement in the past, you may need to re-sign.
See The New Home of the Open edX Codebase for details.

Once you've signed the CLA, please allow 1 business day for it to be processed.
After this time, you can re-run the CLA check by adding a comment below that you have signed it.
If the CLA check continues to fail, you can tag the @openedx/cla-problems team in a comment for further assistance.

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Update the status of your PR

Your PR is currently marked as a draft. After completing the steps above, update its status by clicking "Ready for Review", or removing "WIP" from the title, as appropriate.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions May 28, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Jun 1, 2026
@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Jun 1, 2026
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Needs Tests Run or CLA Signed in Contributions Jun 1, 2026
@mphilbrick211
Copy link
Copy Markdown

Hi @Gi-ron! It looks like you're contributing on behalf of eduNEXT. In order to have your CLA check turn green, please have your manager reach out to oscm@axim.org to have you added to our existing entity agreement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs test run Author's first PR to this repository, awaiting test authorization from Axim open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Tests Run or CLA Signed

Development

Successfully merging this pull request may close these issues.

3 participants