diff Applications/StoneWebViewer/WebApplication/app.js @ 1959:889892e51545

Fix handling of "token": The authorization header was not set in QIDO-RS requests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Oct 2022 17:09:28 +0200
parents 142c7ee8fe1f
children 2034ae383cfd b180233143ae
line wrap: on
line diff
--- a/Applications/StoneWebViewer/WebApplication/app.js	Thu Oct 27 14:53:09 2022 +0200
+++ b/Applications/StoneWebViewer/WebApplication/app.js	Thu Oct 27 17:09:28 2022 +0200
@@ -1147,6 +1147,11 @@
 
 
 window.addEventListener('StoneInitialized', function() {
+  /**
+   * Do NOT modify the order of the calls to "stone.XXX()" in this
+   * section, otherwise the HTTP headers might not be properly set.
+   **/
+
   stone.Setup(Module);
   stone.SetDicomWebRoot(app.globalConfiguration.DicomWebRoot,
                         true /* assume "/rendered" is available in DICOMweb (could be a configuration option) */);
@@ -1156,6 +1161,23 @@
     stone.SetDicomCacheSize(app.globalConfiguration.DicomCacheSize);
   }
 
+  // Calls to "stone.AddHttpHeader()" must be after "stone.SetDicomWebRoot()",
+  // and before "stone.SetSkipSeriesFromModalities()"
+  for (var header in app.globalConfiguration.DicomWebHttpHeaders) {
+    stone.AddHttpHeader(header, app.globalConfiguration.DicomWebHttpHeaders[header]);
+  }
+  
+  // Bearer token is new in Stone Web viewer 2.0
+  var token = getParameterFromUrl('token');
+  if (token !== undefined) {
+    stone.AddHttpHeader('Authorization', 'Bearer ' + token);
+  }
+
+
+  /**
+   * Calls to "stone.XXX()" can be reordered after this point.
+   **/
+  
   if ('SkipSeriesFromModalities' in app.globalConfiguration) {
     stone.SetSkipSeriesFromModalities(JSON.stringify(app.globalConfiguration.SkipSeriesFromModalities));
   }
@@ -1170,12 +1192,6 @@
     alert('Bad value for option "ShowInfoPanelAtStartup": ' + app.globalConfiguration.ShowInfoPanelAtStartup);
   }
 
-  // Bearer token is new in Stone Web viewer 2.0
-  var token = getParameterFromUrl('token');
-  if (token !== undefined) {
-    stone.AddHttpHeader('Authorization', 'Bearer ' + token);
-  }
-  
   console.warn('Stone properly initialized');
 
   app.stoneWebViewerVersion = stone.GetStoneWebViewerVersion();