Add ability to set SameSite policy for userLoggedIn cookie (#15100)

* Add ability to set SameSite policy for userLoggedIn cookie

* reformat line for linter
This commit is contained in:
Michael Tipton
2024-04-24 15:44:31 -04:00
committed by GitHub
parent 47a061eb39
commit f5f85666c8
3 changed files with 9 additions and 2 deletions

View File

@@ -38,7 +38,9 @@ class CompleteView(BaseRedirectView):
response = super(CompleteView, self).dispatch(request, *args, **kwargs)
if self.request.user and self.request.user.is_authenticated:
logger.info(smart_str(u"User {} logged in".format(self.request.user.username)))
response.set_cookie('userLoggedIn', 'true', secure=getattr(settings, 'SESSION_COOKIE_SECURE', False))
response.set_cookie(
'userLoggedIn', 'true', secure=getattr(settings, 'SESSION_COOKIE_SECURE', False), samesite=getattr(settings, 'USER_COOKIE_SAMESITE', 'Lax')
)
response.setdefault('X-API-Session-Cookie-Name', getattr(settings, 'SESSION_COOKIE_NAME', 'awx_sessionid'))
return response