Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp: Add configuration option to redirect to external site when TPA account is unlinked #540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lms/static/js/student_account/views/LoginView.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
saveError: function(error) {
var errorCode;
var msg;
var redirectURL;
if (error.status === 0) {
msg = gettext('An error has occurred. Check your Internet connection and try again.');
} else if (error.status === 500) {
Expand Down Expand Up @@ -242,6 +243,7 @@
} else if (error.responseJSON !== undefined) {
msg = error.responseJSON.value;
errorCode = error.responseJSON.error_code;
redirectURL = error.responseJSON.redirect_url;
} else {
msg = gettext('An unexpected error has occurred.');
}
Expand All @@ -263,6 +265,9 @@
this.clearFormErrors();
this.renderThirdPartyAuthWarning();
}
if (redirectURL){
window.location.href = redirectURL;
}
} else {
this.renderErrors(this.defaultFormErrorsTitle, this.errors);
}
Expand Down
15 changes: 13 additions & 2 deletions openedx/core/djangoapps/user_authn/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _do_third_party_auth(request):

try:
return pipeline.get_authenticated_user(requested_provider, username, third_party_uid)
except USER_MODEL.DoesNotExist:
except USER_MODEL.DoesNotExist as err:
AUDIT_LOG.info(
"Login failed - user with username {username} has no social auth "
"with backend_name {backend_name}".format(
Expand All @@ -99,7 +99,18 @@ def _do_third_party_auth(request):
)
)

raise AuthFailedError(message, error_code='third-party-auth-with-no-linked-account') # lint-amnesty, pylint: disable=raise-missing-from
# When a user logs in who is authenticated by the OAuth2 but doesn't
# have a linked account, redirect them to an external URL where they
# can set up their account.
# This is a temporary change that will be reverted when the authn MFE is
# in use.
redirect_url = configuration_helpers.get_value('OC_REDIRECT_ON_TPA_UNLINKED_ACCOUNT', None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave a comment here explaining the motivation for this change and that this is intended to be a temporary change. We should also indicate this in the PR commit message, for the benefit of the person preparing the next common branch.


raise AuthFailedError(
message,
error_code='third-party-auth-with-no-linked-account',
redirect_url=redirect_url
) from err


def _get_user_by_email(email):
Expand Down