Skip to content

Commit

Permalink
Amend the JupyterHub csrf_token forward to check whether the _xsrf to…
Browse files Browse the repository at this point in the history
…ken is present, to make the code compatible with both pre and post JupyterHub version 4.0

git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@5784 b75ad72c-e7d7-11dd-a971-7dbc132099af
  • Loading branch information
rasmunk authored and jonasbardino committed Aug 15, 2023
1 parent 33b5ab5 commit 589ee61
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mig/shared/functionality/reqjupyterservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,14 @@ def main(client_id, user_arguments_dict):
with requests.session() as session:
# Refresh cookies
session.get(url_auth)
csrf_token = {"_xsrf": session.cookies['_xsrf']}
auth_params = {}
if "_xsrf" in session.cookies:
auth_patams = {"_xsrf": session.cookies['_xsrf']}
# Authenticate and submit data
response = session.post(url_auth, headers=auth_header, params=csrf_token)
response = session.post(url_auth, headers=auth_header, params=auth_patams)
if response.status_code == 200:
for user_data_type, user_data in user_post_data.items():
response = session.post(url_data, json={user_data_type: user_data}, params=csrf_token)
response = session.post(url_data, json={user_data_type: user_data}, params=auth_patams)
if response.status_code != 200:
logger.error(
"Jupyter: User %s failed to submit data %s to %s"
Expand Down Expand Up @@ -614,12 +616,14 @@ def main(client_id, user_arguments_dict):
with requests.session() as session:
# Refresh cookies
session.get(url_auth)
csrf_token = {"_xsrf": session.cookies['_xsrf']}
auth_params = {}
if "_xsrf" in session.cookies:
auth_patams = {"_xsrf": session.cookies['_xsrf']}
# Authenticate
response = session.post(url_auth, headers=auth_header, params=csrf_token)
response = session.post(url_auth, headers=auth_header, params=auth_params)
if response.status_code == 200:
for user_data_type, user_data in user_post_data.items():
response = session.post(url_data, json={user_data_type: user_data}, params=csrf_token)
response = session.post(url_data, json={user_data_type: user_data}, params=auth_params)
if response.status_code != 200:
logger.error("Jupyter: User %s failed to submit data %s to %s"
% (client_id, user_data, url_data))
Expand Down

0 comments on commit 589ee61

Please sign in to comment.