Skip to content

Commit

Permalink
[SwanContents] Make download feature set xsrf auth header
Browse files Browse the repository at this point in the history
This is required after the update to hub v4.1.6
  • Loading branch information
etejedor authored and diocas committed Sep 13, 2024
1 parent d87e82d commit 5a854dd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions SwanContents/swancontents/serverextension/templates/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,28 @@

<script type = "text/javascript" >

function get_headers() {
var headers = {
'Content-Type': 'application/json'
}

var cookie = document.cookie.match("\\b_xsrf=([^;]*)\\b");
var xsrf = cookie ? cookie[1] : undefined;
if (xsrf) {
headers['X-XSRFToken'] = xsrf // hub auth header
}

return headers
};

document.addEventListener("DOMContentLoaded", function() {
var base_url = document.body.getAttribute("data-baseUrl") || "";
var urlParams = new URLSearchParams(window.location.search);
var proj_url = urlParams.get('projurl');

var settings = {
method: "GET",
headers: {
'Content-Type': 'application/json'
}
headers: get_headers()
};

fetch(base_url + 'api/contents/fetch?url=' + encodeURIComponent(proj_url), settings)
Expand Down

0 comments on commit 5a854dd

Please sign in to comment.