changeset 3509:5405d51e040d

Orthanc Explorer: include the url search params into HTTP headers to the Rest API to ease usage of the Authorization plugin
author Alain Mazy <alain@mazy.be>
date Tue, 03 Sep 2019 09:49:10 +0200
parents 70524b4acc72
children 1a65beb5e52f
files NEWS OrthancExplorer/explorer.js
diffstat 2 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Aug 29 11:41:26 2019 +0200
+++ b/NEWS	Tue Sep 03 09:49:10 2019 +0200
@@ -9,6 +9,7 @@
 * Name of temporary files now include the process ID to ease design of scripts cleaning /tmp
 * Fix compatibility of LSB binaries with Ubuntu >= 18.04
 * Fix generation of "SOP Instance UID" on split and merge
+* Orthanc Explorer: include the url search params into HTTP headers to the Rest API to ease usage of the Authorization plugin
 
 
 Version 1.5.7 (2019-06-25)
--- a/OrthancExplorer/explorer.js	Thu Aug 29 11:41:26 2019 +0200
+++ b/OrthancExplorer/explorer.js	Tue Sep 03 09:49:10 2019 +0200
@@ -91,6 +91,31 @@
   }
 });
 
+var GetUrlParametersAsDict = function getUrlParametersAsDict(sParam) {
+  var urlVariables = window.location.search.substring(1).split('&');
+  var dict = {};
+
+  for (var i = 0; i < urlVariables.length; i++) {
+      var split = urlVariables[i].split('=');
+
+      if (split.length == 2) {
+        dict[split[0]] = split[1];
+      }
+  }
+  return dict;
+};
+
+var initSearchParams = GetUrlParametersAsDict();
+
+/* Copy all url search parameters into HTTP headers in every request to the Rest API.  
+Thanks to this behaviour, you may specify a ?token=xxx in your url and this will be passed 
+as the "token" header in every request to the API allowing you to use the authorization plugin */
+$.ajaxSetup(
+  {
+    headers : initSearchParams
+  }
+);
+
 
 function SplitLongUid(s)
 {