From e5e97888518ddd825f10bd6e3e083dde81a0903c Mon Sep 17 00:00:00 2001 From: vermeul <swen@ethz.ch> Date: Fri, 15 Mar 2019 18:03:59 +0100 Subject: [PATCH] fixed _xsrf bug for Safari (was a general get-cookie bug) --- jupyter-openbis-extension/static/common.js | 19 ++++++++++++++++++- .../static/connections.js | 14 +++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/jupyter-openbis-extension/static/common.js b/jupyter-openbis-extension/static/common.js index 41f42fd..15280a1 100644 --- a/jupyter-openbis-extension/static/common.js +++ b/jupyter-openbis-extension/static/common.js @@ -23,8 +23,25 @@ define([ nb_container.prepend(feedbackBox) } + function getCookie(cname) { + var name = cname + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for(var i = 0; i <ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) === ' ') { + c = c.substring(1); + } + if (c.indexOf(name) === 0) { + return c.substring(name.length, c.length); + } + } + return ""; + } + return { - createFeedback: createFeedback + createFeedback: createFeedback, + getCookie: getCookie } } ) \ No newline at end of file diff --git a/jupyter-openbis-extension/static/connections.js b/jupyter-openbis-extension/static/connections.js index 1f5972c..6f856fb 100644 --- a/jupyter-openbis-extension/static/connections.js +++ b/jupyter-openbis-extension/static/connections.js @@ -1,7 +1,8 @@ define([ - "base/js/utils" + "base/js/utils", + "./common" ], - function (utils) { + function (utils, common) { function list(env) { @@ -16,6 +17,7 @@ define([ return utils.ajax(settings) } + function connect(env, connection, username, password) { var url = env.notebook.base_url + 'openbis/conn/' + connection body = { @@ -23,14 +25,12 @@ define([ "password": password } - var cookie = decodeURIComponent(document.cookie) - var xsrf_token = cookie.split("_xsrf=")[1] - + var xsrf_token = common.getCookie('_xsrf') return fetch(url, { method: "PUT", headers: { "Content-Type": "application/json", - "X-XSRFToken": xsrf_token, + "X-XSRFToken": xsrf_token }, body: JSON.stringify(body) }) @@ -52,7 +52,7 @@ define([ method: "POST", headers: { "Content-Type": "application/json", - "X-XSRFToken": xsrf_token, + //"X-XSRFToken": xsrf_token, }, body: JSON.stringify(body) }) -- GitLab