Skip to content
Snippets Groups Projects
Commit e5e97888 authored by Swen Vermeul's avatar Swen Vermeul
Browse files

fixed _xsrf bug for Safari (was a general get-cookie bug)

parent 014c04cb
No related branches found
No related tags found
No related merge requests found
...@@ -23,8 +23,25 @@ define([ ...@@ -23,8 +23,25 @@ define([
nb_container.prepend(feedbackBox) 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 { return {
createFeedback: createFeedback createFeedback: createFeedback,
getCookie: getCookie
} }
} }
) )
\ No newline at end of file
define([ define([
"base/js/utils" "base/js/utils",
"./common"
], ],
function (utils) { function (utils, common) {
function list(env) { function list(env) {
...@@ -16,6 +17,7 @@ define([ ...@@ -16,6 +17,7 @@ define([
return utils.ajax(settings) return utils.ajax(settings)
} }
function connect(env, connection, username, password) { function connect(env, connection, username, password) {
var url = env.notebook.base_url + 'openbis/conn/' + connection var url = env.notebook.base_url + 'openbis/conn/' + connection
body = { body = {
...@@ -23,14 +25,12 @@ define([ ...@@ -23,14 +25,12 @@ define([
"password": password "password": password
} }
var cookie = decodeURIComponent(document.cookie) var xsrf_token = common.getCookie('_xsrf')
var xsrf_token = cookie.split("_xsrf=")[1]
return fetch(url, { return fetch(url, {
method: "PUT", method: "PUT",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"X-XSRFToken": xsrf_token, "X-XSRFToken": xsrf_token
}, },
body: JSON.stringify(body) body: JSON.stringify(body)
}) })
...@@ -52,7 +52,7 @@ define([ ...@@ -52,7 +52,7 @@ define([
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
"X-XSRFToken": xsrf_token, //"X-XSRFToken": xsrf_token,
}, },
body: JSON.stringify(body) body: JSON.stringify(body)
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment