diff --git a/openedx/core/djangoapps/user_authn/views/login.py b/openedx/core/djangoapps/user_authn/views/login.py index ac818a23bc23a5e191f4d781ff3e7a39eb9585e5..451d88cdbbb589e998f90a1281a1cf34bb766f92 100644 --- a/openedx/core/djangoapps/user_authn/views/login.py +++ b/openedx/core/djangoapps/user_authn/views/login.py @@ -365,7 +365,11 @@ def login_user(request): except AuthFailedError as e: set_custom_metric('login_user_tpa_success', False) set_custom_metric('login_user_tpa_failure_msg', e.value) - return HttpResponse(e.value, content_type="text/plain", status=403) + + # user successfully authenticated with a third party provider, but has no linked Open edX account + response_content = e.get_response() + response_content['error_code'] = 'third-party-auth-with-no-linked-account' + return JsonResponse(response_content, status=403) else: user = _get_user_by_email(request) diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_login.py b/openedx/core/djangoapps/user_authn/views/tests/test_login.py index 3a6c1b3bf04f6b7c336a155ac55a34cf9ff2430a..961fcc3ec5535afc64340f4e2e3671c4f270ae43 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_login.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_login.py @@ -40,6 +40,7 @@ from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_un from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.lib.api.test_utils import ApiTestCase from student.tests.factories import RegistrationFactory, UserFactory, UserProfileFactory +from util.json_request import JsonResponse from util.password_policy_validators import DEFAULT_MAX_PASSWORD_LENGTH @@ -818,8 +819,13 @@ class StudentViewShimTest(TestCase): self.captured_request = None def test_third_party_auth_login_failure(self): + mocked_response_content = { + "success": False, + "error_code": "third-party-auth-with-no-linked-account", + "value": "Test message." + } view = self._shimmed_view( - HttpResponse(status=403), + JsonResponse(mocked_response_content, status=403), check_logged_in=True ) response = view(HttpRequest())