Skip to content

Commit

Permalink
feat(standalone-viewer): Add authorization header (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasvandooren authored and swederik committed Dec 12, 2018
1 parent a4b8f2c commit 947a5f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions StandaloneViewer/StandaloneViewer/client/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ Meteor.startup(function() {

cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
cornerstoneWebImageLoader.external.cornerstone = cornerstone;

let configureAuthorization = {
beforeSend: function(xhr){
if (OHIF.viewer.authorizationToken) {
xhr.setRequestHeader('Authorization', OHIF.viewer.authorizationToken);
}
}
};

cornerstoneWADOImageLoader.configure(configureAuthorization);
cornerstoneWebImageLoader.configure(configureAuthorization);
});
8 changes: 8 additions & 0 deletions StandaloneViewer/StandaloneViewer/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ if (Meteor.isClient) {
oReq.open('GET', url);
oReq.setRequestHeader('Accept', 'application/json')

// Add token in the request authorization header
// if a token fragment parameter is present
const tokenParam = this.params.hash ? this.params.hash.match(/(?:token)=(.*?)(?:&|$)/) : null;
if (tokenParam) {
OHIF.viewer.authorizationToken = "Bearer " + tokenParam[1];
oReq.setRequestHeader('Authorization', OHIF.viewer.authorizationToken);
}

// Fire the request to the server
oReq.send();
},
Expand Down
10 changes: 10 additions & 0 deletions docs/standalone-viewer/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ It is possible to build this standalone viewer to run as a client-only bundle of

Open your web browser and navigate to http://localhost:3000/sampleJPEG.json or http://localhost:3000/sampleDICOM.json

## Authorization Header

A ```token``` fragment parameter can be specified. If present this value will be used for http bearer authorization when making requests for the above JSON, and when retrieving images using the Cornerstone Image Loaders.

Example :

```
http://localhost:3000/sampleDICOM.json#token=1a2b3c4d
```


### Testing the Sample client-only build
For the sake of simplicity we have also included a pre-built client-only version of the standalone viewer, which can be found in the SampleClientOnlyBuild folder.
Expand Down

0 comments on commit 947a5f4

Please sign in to comment.