feat: set the authorization header for DICOMWeb requests if provided in query string (#1646)

This commit is contained in:
Danny Brown authored and GitHub committed 2020-04-17 10:14:13 -04:00
1 parent d3eefb50f5
commit 450c80b9d5
5 files changed
+257 -75

No files matched your search

@@ -1,6 +1,3 @@
// Commenting this out for now since it looks like Rollup is pulling in the
// Node.js version instead of the Browser version of this package
//import { btoa } from 'isomorphic-base64';
import user from '../user';
/**
@@ -18,6 +15,7 @@ export default function getAuthorizationHeader({ requestOptions } = {}) {
// Check for OHIF.user since this can also be run on the server
const accessToken = user && user.getAccessToken && user.getAccessToken();
// Auth for a specific server
if (requestOptions && requestOptions.auth) {
if (typeof requestOptions.auth === 'function') {
// Custom Auth Header
@@ -26,7 +24,9 @@ export default function getAuthorizationHeader({ requestOptions } = {}) {
// HTTP Basic Auth (user:password)
headers.Authorization = `Basic ${btoa(requestOptions.auth)}`;
}
} else if (accessToken) {
}
// Auth for the user's default
else if (accessToken) {
headers.Authorization = `Bearer ${accessToken}`;
}
@@ -0,0 +1,11 @@
import { useLocation } from 'react-router-dom';
/**
* hook that builds on useLocation to parse
* the query string for you.
*
* @name useQuery
*/
export default function() {
return new URLSearchParams(useLocation().search);
}
+17 -3
View File
@@ -1,9 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import { utils, user } from '@ohif/core';
//
import ConnectedViewerRetrieveStudyData from '../connectedComponents/ConnectedViewerRetrieveStudyData';
import useServer from '../customHooks/useServer';
import OHIF from '@ohif/core';
const { urlUtil: UrlUtil } = OHIF.utils;
import useQuery from '../customHooks/useQuery';
const { urlUtil: UrlUtil } = utils;
/**
* Get array of seriesUIDs from param or from queryString
@@ -27,8 +29,19 @@ function ViewerRouting({ match: routeMatch, location: routeLocation }) {
studyInstanceUIDs,
seriesInstanceUIDs,
} = routeMatch.params;
const server = useServer({ project, location, dataset, dicomStore });
// Set the user's default authToken for outbound DICOMWeb requests.
// Is only applied if target server does not set `requestOptions` property.
//
// See: `getAuthorizationHeaders.js`
let query = useQuery();
const authToken = query.get('token');
if (authToken) {
user.getAccessToken = () => authToken;
}
const server = useServer({ project, location, dataset, dicomStore });
const studyUIDs = UrlUtil.paramString.parseParam(studyInstanceUIDs);
const seriesUIDs = getSeriesInstanceUIDs(seriesInstanceUIDs, routeLocation);
@@ -55,6 +68,7 @@ ViewerRouting.propTypes = {
project: PropTypes.string,
}),
}),
location: PropTypes.any,
};
export default ViewerRouting;
+3 -1
View File
@@ -19,7 +19,9 @@ const StudyListRouting = asyncComponent(() =>
)
);
const StandaloneRouting = asyncComponent(() =>
import(/* webpackChunkName: "ConnectedStandaloneRouting" */ '../connectedComponents/ConnectedStandaloneRouting.js')
import(
/* webpackChunkName: "ConnectedStandaloneRouting" */ '../connectedComponents/ConnectedStandaloneRouting.js'
)
);
const ViewerLocalFileData = asyncComponent(() =>
import(