fix: redirect TPA account_settings errors to Account MFE with duplica…#38673
fix: redirect TPA account_settings errors to Account MFE with duplica…#38673Gi-ron wants to merge 1 commit into
Conversation
…te_provider param
|
Thanks for the pull request, @Gi-ron! This repository is currently maintained by 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 approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo 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:
🔘 Submit a signed contributor agreement (CLA)
If you've signed an agreement in the past, you may need to re-sign. Once you've signed the CLA, please allow 1 business day for it to be processed. 🔘 Get a green buildIf 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 PRYour 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:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
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. |
PR Description
When a SAML (or any third-party auth) error occurs during the Linked Accounts flow in the Account MFE, for example,
AuthAlreadyAssociatedwhen 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 statelessRedirectViewthat redirects directly toACCOUNT_MICROFRONTEND_URLwithout 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.pyAUTH_DISPATCH_URLS[AUTH_ENTRY_ACCOUNT_SETTINGS]from/account/settingsto/auth/account_settings_error.RedirectView.common/djangoapps/third_party_auth/views.pyaccount_settings_error_view: an intermediate Django view that reads the Django message left bySocialAuthExceptionMiddleware, resolves the human-readable provider name viaprovider.Registry.get_enabled_by_backend_name(), and redirects to the Account MFE with?duplicate_provider=<provider_name>.common/djangoapps/third_party_auth/urls.pyauth/account_settings_error.openedx/core/djangoapps/user_api/legacy_urls.pyquery_string=Trueto the existing/account/settingsRedirectViewas 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
Testing
Setup
user_a@example.comanduser_b@example.com.user_aand complete the SAML login flow to link the IdP identity touser_a.Reproduce the error
user_b.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)
Additional notes
After the
AuthAlreadyAssociatederror occurs,user_bwill not be able to link the provideruntil one of the following conditions is met:
Sign out from the IdP session: Since the IdP session remains active after the error,
user_bmust 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_aunlinks their account: Ifuser_adisconnects the provider from their Open edXaccount via Account MFE → Linked Accounts → Unlink, the IdP identity becomes available
again and
user_bwill be able to link it successfully on the next attempt.