Skip to content

Commit 8e90bec

Browse files
committed
fix: redirect TPA account_settings errors to Account MFE with duplicate_provider param
1 parent 272718e commit 8e90bec

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

common/djangoapps/third_party_auth/views.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"""
44

55
import logging
6+
from urllib.parse import quote
67

78
from django.conf import settings
89
from django.contrib.auth.decorators import login_required
10+
from django.contrib.messages import get_messages
911
from django.core.exceptions import PermissionDenied, ValidationError
1012
from django.db import DatabaseError
1113
from django.http import (
@@ -32,6 +34,7 @@
3234
from common.djangoapps.student.models import UserProfile
3335
from common.djangoapps.student.views import compose_and_send_activation_email
3436
from common.djangoapps.third_party_auth import pipeline, provider
37+
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
3538

3639
from .models import SAMLConfiguration, SAMLProviderConfig
3740

@@ -273,3 +276,21 @@ def disconnect_json_view(request, backend, association_id=None):
273276
'backend': backend,
274277
'association_id': association_id
275278
}, status=500)
279+
280+
def account_settings_redirect_view(request):
281+
"""
282+
Redirect to Account MFE, preserving auth error messages (e.g., AuthAlreadyAssociated).
283+
"""
284+
account_mfe_url = configuration_helpers.get_value(
285+
'ACCOUNT_MICROFRONTEND_URL',
286+
settings.ACCOUNT_MICROFRONTEND_URL,
287+
).rstrip('/')
288+
289+
duplicate_backend = pipeline.get_duplicate_provider(get_messages(request))
290+
if not duplicate_backend:
291+
return redirect(account_mfe_url)
292+
293+
enabled_providers = list(provider.Registry.get_enabled_by_backend_name(duplicate_backend))
294+
provider_name = enabled_providers[0].name if enabled_providers else duplicate_backend
295+
296+
return redirect(f'{account_mfe_url}/?duplicate_provider={quote(provider_name)}')

openedx/core/djangoapps/user_api/legacy_urls.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"""
22
Defines the URL routes for this app.
33
"""
4-
from django.conf import settings
54
from django.urls import include, path, re_path
6-
from django.views.generic import RedirectView
75
from rest_framework import routers
86

9-
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
7+
from common.djangoapps.third_party_auth.views import account_settings_redirect_view
108

119
from . import views as user_api_views
1210
from .models import UserPreference
@@ -19,12 +17,7 @@
1917
# This redirect is needed for backward compatibility with the old URL structure for the authentication
2018
# workflows using third-party authentication providers until the authentication workflows fully support
2119
# the URL structure with MFEs.
22-
re_path(r'^account(?:/settings)?/?$', RedirectView.as_view(
23-
url=configuration_helpers.get_value(
24-
'ACCOUNT_MICROFRONTEND_URL',
25-
settings.ACCOUNT_MICROFRONTEND_URL,
26-
)),
27-
),
20+
re_path(r'^account(?:/settings)?/?$', account_settings_redirect_view),
2821
path('user_api/v1/', include(USER_API_ROUTER.urls)),
2922
re_path(
3023
fr'^user_api/v1/preferences/(?P<pref_key>{UserPreference.KEY_REGEX})/users/$',

0 commit comments

Comments
 (0)