diff OrthancExplorer/explorer.js @ 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 e54ca78059bd
children 1a65beb5e52f
line wrap: on
line diff
--- 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)
 {