Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,20 @@
# Maximum of 6 retries before giving up.
SOFTWARE_SECURE_RETRY_MAX_ATTEMPTS = 6


# .. toggle_name: TPA_AUTOMATIC_LOGOUT_ENABLED
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
# .. toggle_description: Redirect the user to the TPA logout URL if this flag is enabled, the
# TPA logout URL is configured, and the user logs in through TPA
# .. toggle_use_cases: open_edx
# .. toggle_warning: Enabling this toggle skips rendering logout.html, which is used to log the user out
# from the different IDAs. To ensure the user is logged out of all the IDAs be sure to redirect
# back to <LMS>/logout after logging out of the TPA.
# .. toggle_creation_date: 2023-05-07
# .. toggle_tickets: https://github.com/openedx/edx-platform/pull/32193
TPA_AUTOMATIC_LOGOUT_ENABLED = False

@timmc-edx timmc-edx May 23, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should only have this defined on the LMS side -- the CMS side just redirects to LMS for logout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@timmc-edx You are right, I added this in the CMS side only because some CMS test cases were failing. In hindsight, that was the incorrect way to go about it, I have now handled it differently and removed it from the CMS side.

############## DJANGO-USER-TASKS ##############

# How long until database records about the outcome of a task and its artifacts get deleted?
Expand Down
13 changes: 13 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,19 @@
TPA_PROVIDER_BURST_THROTTLE = '10/min'
TPA_PROVIDER_SUSTAINED_THROTTLE = '50/hr'

# .. toggle_name: TPA_AUTOMATIC_LOGOUT_ENABLED
# .. toggle_implementation: DjangoSetting
# .. toggle_default: False
# .. toggle_description: Redirect the user to the TPA logout URL if this flag is enabled, the
# TPA logout URL is configured, and the user logs in through TPA.
# .. toggle_use_cases: open_edx

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[nit] I believe this would generally be considered an opt_in toggle, although I don't have very strong feelings on this. Docs: https://edx.readthedocs.io/projects/edx-toggles/en/latest/how_to/documenting_new_feature_toggles.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for linking the docs.

# .. toggle_warning: Enabling this toggle skips rendering logout.html, which is used to log the user out
# from the different IDAs. To ensure the user is logged out of all the IDAs be sure to redirect
# back to <LMS>/logout after logging out of the TPA.
# .. toggle_creation_date: 2023-05-07
# .. toggle_tickets: https://github.com/openedx/edx-platform/pull/32193

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think toggle_tickets is primarily used for temporary toggles, whereas this one would be intended as permanent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed this.

TPA_AUTOMATIC_LOGOUT_ENABLED = False

################################## TEMPLATE CONFIGURATION #####################################
# Mako templating
import tempfile # pylint: disable=wrong-import-position,wrong-import-order
Expand Down
12 changes: 12 additions & 0 deletions openedx/core/djangoapps/user_authn/views/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import bleach
from django.conf import settings
from django.contrib.auth import logout
from django.shortcuts import redirect
from django.utils.http import urlencode
from django.views.generic import TemplateView
from oauth2_provider.models import Application
Expand Down Expand Up @@ -83,6 +84,17 @@ def dispatch(self, request, *args, **kwargs):
delete_logged_in_cookies(response)

mark_user_change_as_expected(None)

# Redirect to tpa_logout_url if TPA_AUTOMATIC_LOGOUT_ENABLED is set to True and if
# tpa_logout_url is configured.
#
# NOTE: This step skips rendering logout.html, which is used to log the user out from the
# different IDAs. To ensure the user is logged out of all the IDAs be sure to redirect
# back to <LMS>/logout after logging out of the TPA.
Comment thread
kaustavb12 marked this conversation as resolved.
Outdated
if settings.TPA_AUTOMATIC_LOGOUT_ENABLED:
if self.tpa_logout_url:
return redirect(self.tpa_logout_url)

Comment thread
mubbsharanwar marked this conversation as resolved.
return response

def _build_logout_url(self, url):
Expand Down
27 changes: 27 additions & 0 deletions openedx/core/djangoapps/user_authn/views/tests/test_logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,33 @@ def test_learner_portal_logout_having_idp_logout_url(self):
}
self.assertDictContainsSubset(expected, response.context_data)

@mock.patch('django.conf.settings.TPA_AUTOMATIC_LOGOUT_ENABLED', True)
def test_automatic_tpa_logout_url_redirect(self):
"""
Test user automatically redirected to tpa logout_url
when TPA_AUTOMATIC_LOGOUT is set to True.
"""
idp_logout_url = 'http://mock-idp.com/logout'
client = self._create_oauth_client()

with mock.patch(
'openedx.core.djangoapps.user_authn.views.logout.tpa_pipeline.get_idp_logout_url_from_running_pipeline'
) as mock_idp_logout_url:
mock_idp_logout_url.return_value = idp_logout_url
self._authenticate_with_oauth(client)
response = self.client.get(reverse('logout'))
assert response.status_code == 302
assert response.url == idp_logout_url

@mock.patch('django.conf.settings.TPA_AUTOMATIC_LOGOUT_ENABLED', True)
def test_no_automatic_tpa_logout_without_logout_url(self):
"""
Test user is NOT automatically redirected when tpa logout_url is not set
even if TPA_AUTOMATIC_LOGOUT is set to True.
"""
client = self._create_oauth_client()
self._assert_session_logged_out(client)

@ddt.data(
('%22%3E%3Cscript%3Ealert(%27xss%27)%3C/script%3E', 'edx.org'),
)
Expand Down