changeset 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 40f8009ceb4e
files Applications/StoneWebViewer/NEWS Applications/StoneWebViewer/WebApplication/app.js Applications/StoneWebViewer/WebApplication/configuration.json
diffstat 3 files changed, 34 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/StoneWebViewer/NEWS	Thu Oct 27 14:53:09 2022 +0200
+++ b/Applications/StoneWebViewer/NEWS	Thu Oct 27 17:09:28 2022 +0200
@@ -5,8 +5,10 @@
   - "ShowInfoPanelAtStartup" to control the info panel at startup
   - "ShowUserPreferencesButton" to show the button for setting preferences
   - "ShowNotForDiagnosticUsageDisclaimer" to show disclaimer about diagnostic usage
+  - "DicomWebHttpHeaders" to set HTTP headers in DICOMweb requests
 * More tolerance wrt. bad values of the Pixel Spacing (0028,0030) tag
 * Support of DICOM images without the Study Date (0008,0020) tag
+* Fix handling of "token": The authorization header was not set in QIDO-RS requests
 
 
 Version 2.3 (2022-03-24)
--- 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();
--- a/Applications/StoneWebViewer/WebApplication/configuration.json	Thu Oct 27 14:53:09 2022 +0200
+++ b/Applications/StoneWebViewer/WebApplication/configuration.json	Thu Oct 27 17:09:28 2022 +0200
@@ -139,6 +139,15 @@
      * Display a "not for diagnostic usage" disclaimer above the list
      * of studies/series. (New in Stone Web viewer 2.4)
      **/
-    "ShowNotForDiagnosticUsageDisclaimer": true
+    "ShowNotForDiagnosticUsageDisclaimer": true,
+
+    /**
+     * HTTP headers to be set in each request to the DICOMweb server.
+     * Note that the value of the headers can be taken from the
+     * environment variables.
+     **/
+    "DicomWebHttpHeaders" : {
+      /* "Authorization" : "Bearer ${USER}" */
+    }
   }
 }