OHIF can't connect to password-protected local orthanc (401 error)

Hi guys,

I’m working with OHIF since a couple of days and I would like to connect to a local Orthanc server that is “password protected” (there is at least one username in the “RegisteredUsers” section of my orthanc.json configuration files). I correctly setup the NGINX reverse proxy and OHIF can connect to it without any issue if the password has not been set and I can easily navigate all the studios.

However, as soon as I add RegisteredUsers in Orthanc I start getting 401 errors in OHIF just after loading (GET request to http://localhost:8041/dicom-web/studies?limit=25&offset=0&fuzzymatching=false&includefield=all). The same URL works when visited directly from the browser as I got display a form for inserting the Orthanc credentials.

The error makes sense, as I never got displayed the “form” inside OHIF to insert the Orthanc credentials. How can I make it work? This is the nginx.conf file I’m using right now:

worker_processes 1;

events { worker_connections 1024; }

http {

    upstream orthanc-server {
        server orthanc:8042;
    }

    server {
        listen [::]:80 default_server;
        listen 80;

        # CORS Magic
        add_header 'Access-Control-Allow-Origin' '$http_origin' always;
        add_header 'Access-Control-Allow_Credentials' 'true' always;
        add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
        add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;

        location / {

            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '$http_origin' always;
                add_header 'Access-Control-Allow_Credentials' 'true' always;
                add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
                add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }

            proxy_pass         http://orthanc:8042;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;

            # CORS Magic
            add_header 'Access-Control-Allow-Origin' '$http_origin' always;
            add_header 'Access-Control-Allow_Credentials' 'true' always;
            add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
            add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
        }
    }
}

and this is the config file used in OHIF for pointing it to my local Orthanc:

window.config = {
  routerBasename: '/',
  showStudyList: true,
  servers: {
    dicomWeb: [
      {
        name: 'Orthanc',
        wadoUriRoot: 'http://localhost:8041/wado',
        qidoRoot: 'http://localhost:8041/dicom-web',
        wadoRoot: 'http://localhost:8041/dicom-web',
        qidoSupportsIncludeField: false,
        imageRendering: 'wadors',
        thumbnailRendering: 'wadors',
      },
    ],
  },
};

I know that the ideal solution should be to use a setup similar to the one specified in the documentation with KeyCloak (or another tool) but this isn’t feasible in my use case for the following reasons:

  • The basic authentication I implemented in Orthanc is just to have a basic protection, as we do not have sensible information to protect in the development environment
  • I’m still at the development phase and I would like to just explore the available APIs with “realistic” data, without worrying about the setup of more components
  • The final software will have an access management system at a higher level

A workaround I just implemented is to use a whitelist in nginx.conf file in order to specify which IP addresses are allowed . In particular I added the following lines:

location / {
            allow   my.public.ip.address;
            deny    all;