changeset 219:0f042939410d

support for auth token passed as url search params
author amazy
date Tue, 03 Sep 2019 10:56:08 +0200
parents 6318db66448e
children 5d15a86bad26
files NEWS Resources/OrthancExplorer.js WebApplication/viewer.js
diffstat 3 files changed, 37 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed May 29 16:51:35 2019 +0200
+++ b/NEWS	Tue Sep 03 10:56:08 2019 +0200
@@ -2,7 +2,8 @@
 ===============================
 
 * Performance: Replaced "OrthancPluginRegisterRestCallback" by "OrthancPluginRegisterRestCallbackNoLock"
-
+* Authorization tokens passed as url search params in Orthanc Explorer are now transmitted to the viewer
+  and included as headers in every HTTP request to the Rest API easing the usage of the Authorization plugin
 
 Version 2.5 (2019-02-27)
 ========================
--- a/Resources/OrthancExplorer.js	Wed May 29 16:51:35 2019 +0200
+++ b/Resources/OrthancExplorer.js	Tue Sep 03 10:56:08 2019 +0200
@@ -11,8 +11,16 @@
   b.insertBefore($('#series-delete').parent().parent());
   b.click(function() {
     if ($.mobile.pageData) {
-      var series = $.mobile.pageData.uuid;
-      window.open('../web-viewer/app/viewer.html?series=' + series);
+      var urlSearchParams = {
+        "series" : $.mobile.pageData.uuid
+      };
+      if (authorizationTokens !== undefined) {
+        for (var token in authorizationTokens) {
+          urlSearchParams[token] = authorizationTokens[token];
+        }
+      }
+
+      window.open('../web-viewer/app/viewer.html?' + $.param(urlSearchParams));
     }
   });
 });
--- a/WebApplication/viewer.js	Wed May 29 16:51:35 2019 +0200
+++ b/WebApplication/viewer.js	Tue Sep 03 10:56:08 2019 +0200
@@ -32,6 +32,31 @@
 }
 
 
+function GetAuthorizationTokensFromUrl() {
+  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 && (split[0] == "token" || split[0] == "auth-token" || split[0] == "authorization")) {
+        dict[split[0]] = split[1];
+      }
+  }
+  return dict;
+};
+
+var authorizationTokens = GetAuthorizationTokensFromUrl();
+
+/* Copy the authoziation toekn from the 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 : authorizationTokens
+  }
+);
+
 function ResizeCornerstone()
 {
   $('#dicomImage').height($(window).height() - $('#slider').parent().height());