Skip to content

Commit

Permalink
Add support to update cookie value (#513)
Browse files Browse the repository at this point in the history
Co-authored-by: Anas-hameed <[email protected]>
  • Loading branch information
Anas-hameed and Anas-hmeed authored Feb 28, 2024
1 parent 64a8f3f commit 1165e79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion openedx/core/djangoapps/user_authn/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from django.conf.urls import url

from openedx.core.djangoapps.user_authn.api.views import TPAContextView
from openedx.core.djangoapps.user_authn.api.views import TPAContextView, CookieRefreshView

urlpatterns = [
url(
r'^third_party_auth_context$', TPAContextView.as_view(), name='third_party_auth_context'
),
url(r'^cookie/refresh/', CookieRefreshView.as_view(), name='cookie_refresh_view'),
]
25 changes: 25 additions & 0 deletions openedx/core/djangoapps/user_authn/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from rest_framework.response import Response
from rest_framework.throttling import AnonRateThrottle
from rest_framework.views import APIView
from rest_framework.authentication import SessionAuthentication

from common.djangoapps.util.json_request import JsonResponse
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from openedx.core.djangoapps.user_authn.cookies import set_logged_in_cookies
from openedx.core.djangoapps.user_authn.utils import third_party_auth_context

REDIRECT_KEY = 'redirect_to'
Expand Down Expand Up @@ -54,3 +58,24 @@ def get(self, request, **kwargs):
status=status.HTTP_200_OK,
data=context
)


class CookieRefreshView(APIView):
"""
API to regenerate the cookie for a user, when creating a new site
"""
authentication_classes = (JwtAuthentication, SessionAuthentication,)

def get(self, request, *args, **kwargs):
"""
GET /api/cookie/refresh/
This API endpoint is used to update the cookie value, authenticated
user send a get request and user cookie is regenerated and set with list
of update sites.
"""
response = JsonResponse({
'success': True,
})
response = set_logged_in_cookies(request, response, request.user)
return response

0 comments on commit 1165e79

Please sign in to comment.