From e41520dbae3a420596a07f89e0c7073efed6cd89 Mon Sep 17 00:00:00 2001 From: Robert Raposa Date: Mon, 4 Oct 2021 11:00:07 -0400 Subject: [PATCH] feat: return user id from login_refresh (#28905) To enhance monitoring of login_refresh issues that happen in the frontend, return user id as part of successful refreshes. --- openedx/core/djangoapps/user_authn/cookies.py | 1 + openedx/core/djangoapps/user_authn/tests/test_cookies.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/openedx/core/djangoapps/user_authn/cookies.py b/openedx/core/djangoapps/user_authn/cookies.py index acce270018..0567f5d3be 100644 --- a/openedx/core/djangoapps/user_authn/cookies.py +++ b/openedx/core/djangoapps/user_authn/cookies.py @@ -170,6 +170,7 @@ def get_response_with_refreshed_jwt_cookies(request, user): response.content = json.dumps( { 'success': True, + 'user_id': user.id, 'response_epoch_seconds': current_time, 'response_http_date': http_date(current_time), 'expires': expires_date if expires_date else 'not-found', diff --git a/openedx/core/djangoapps/user_authn/tests/test_cookies.py b/openedx/core/djangoapps/user_authn/tests/test_cookies.py index ad9808069f..37f26bf87e 100644 --- a/openedx/core/djangoapps/user_authn/tests/test_cookies.py +++ b/openedx/core/djangoapps/user_authn/tests/test_cookies.py @@ -153,6 +153,8 @@ class CookieTests(TestCase): self._set_use_jwt_cookie_header(self.request) response = cookies_api.get_response_with_refreshed_jwt_cookies(self.request, self.user) data = json.loads(response.content.decode('utf8').replace("'", '"')) + assert data['success'] is True + assert data['user_id'] == self.user.id assert data['expires_epoch_seconds'] > 0 assert data['expires'] != 'not-found' self._assert_cookies_present(response, cookies_api.JWT_COOKIE_NAMES)