Add OAuth support
This commit is contained in:
1 parent
0cbf15c46e
commit
9e7314e4a5
16 files changed
+273
-10531
No files matched your search
+28
-20
@@ -1,12 +1,14 @@
|
||||
import React, { Component } from 'react';
|
||||
import { withRouter } from 'react-router';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import { connect } from 'react-redux';
|
||||
import { ViewerbaseDragDropContext } from 'react-viewerbase';
|
||||
import ViewerRouting from "./ViewerRouting.js";
|
||||
import StudyListRouting from './StudyListRouting.js';
|
||||
import StandaloneRouting from './StandaloneRouting.js';
|
||||
import IHEInvokeImageDisplay from './IHEInvokeImageDisplay.js';
|
||||
import { ViewerbaseDragDropContext } from 'react-viewerbase';
|
||||
|
||||
import CallbackPage from './CallbackPage.js';
|
||||
import userManager from "./userManager.js";
|
||||
import './App.css';
|
||||
import './variables.css';
|
||||
import './theme-tide.css';
|
||||
@@ -24,11 +26,6 @@ function setContext(context) {
|
||||
|
||||
class App extends Component {
|
||||
componentDidMount() {
|
||||
// Temporary until the rest of the UI is in React
|
||||
window.router = {
|
||||
history: this.props.history
|
||||
};
|
||||
|
||||
this.unlisten = this.props.history.listen((location, action) => {
|
||||
setContext(window.location.pathname);
|
||||
});
|
||||
@@ -39,50 +36,50 @@ class App extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const user = this.props.user;
|
||||
|
||||
if (!user || user.expired) {
|
||||
// TODO: redirect to OAuth page if necessary
|
||||
//return ('Loading user...');
|
||||
}
|
||||
|
||||
return (
|
||||
<Switch>
|
||||
<Route
|
||||
exact
|
||||
path="/studylist"
|
||||
component={StudyListRouting}
|
||||
/*auth={this.props.auth}*/
|
||||
store={this.props.store}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path="/"
|
||||
component={StudyListRouting}
|
||||
/*auth={this.props.auth}*/
|
||||
store={this.props.store}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path="/viewer"
|
||||
component={StandaloneRouting}
|
||||
/*auth={this.props.auth}*/
|
||||
store={this.props.store}
|
||||
/>
|
||||
<Route
|
||||
path="/viewer/:studyInstanceUids"
|
||||
component={ViewerRouting}
|
||||
/*auth={this.props.auth}*/
|
||||
store={this.props.store}
|
||||
/>
|
||||
<Route
|
||||
path="/study/:studyInstanceUid/series/:seriesInstanceUids"
|
||||
component={ViewerRouting}
|
||||
/*auth={this.props.auth}*/
|
||||
store={this.props.store}
|
||||
/>
|
||||
<Route
|
||||
path="/IHEInvokeImageDisplay"
|
||||
component={IHEInvokeImageDisplay}
|
||||
/*auth={this.props.auth}*/
|
||||
store={this.props.store}
|
||||
/>
|
||||
|
||||
<Route path="/silent-refresh.html" onEnter={reload} />
|
||||
<Route path="/logout-redirect.html" onEnter={reload} />
|
||||
<Route exact path='/login' component={() => {
|
||||
userManager.signinRedirect();
|
||||
}}
|
||||
/>
|
||||
<Route path="/callback" component={CallbackPage} />
|
||||
<Route render={() =>
|
||||
<div> Sorry, this page does not exist. </div>}
|
||||
/>
|
||||
@@ -91,4 +88,15 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
export default ViewerbaseDragDropContext(withRouter(App));
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
user: state.oidc.user,
|
||||
};
|
||||
};
|
||||
|
||||
const ConnectedApp = connect(
|
||||
mapStateToProps,
|
||||
null
|
||||
)(App);
|
||||
|
||||
export default ViewerbaseDragDropContext(withRouter(ConnectedApp));
|
||||
@@ -0,0 +1,24 @@
|
||||
import React from "react";
|
||||
import { CallbackComponent } from "redux-oidc";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import userManager from "./userManager";
|
||||
|
||||
class CallbackPage extends React.Component {
|
||||
render() {
|
||||
// just redirect to '/' in both cases
|
||||
return (
|
||||
<CallbackComponent
|
||||
userManager={userManager}
|
||||
successCallback={() => this.props.history.push("/")}
|
||||
errorCallback={error => {
|
||||
this.props.history.push("/");
|
||||
console.error(error);
|
||||
}}
|
||||
>
|
||||
<div>Redirecting...</div>
|
||||
</CallbackComponent>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withRouter(CallbackPage);
|
||||
@@ -4,12 +4,12 @@ import StudyListWithData from './StudyListWithData.js';
|
||||
|
||||
const isActive = (a) => a.active === true;
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const mapStateToProps = state => {
|
||||
const activeServer = state.servers.servers.find(isActive);
|
||||
|
||||
return {
|
||||
server: activeServer,
|
||||
...ownProps
|
||||
user: state.oidc.user,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class StudyListWithData extends Component {
|
||||
error: null
|
||||
};
|
||||
|
||||
this.pageSize = 5;
|
||||
this.rowsPerPage = 20;
|
||||
this.defaultSort = { field: 'patientName', order: 'desc' };
|
||||
}
|
||||
|
||||
@@ -28,18 +28,17 @@ class StudyListWithData extends Component {
|
||||
|
||||
searchForStudies = (searchData = {
|
||||
currentPage: 0,
|
||||
pageSize: 5
|
||||
rowsPerPage: this.rowsPerPage
|
||||
}) => {
|
||||
const { server } = this.props;
|
||||
console.log(searchData);
|
||||
const filter = {
|
||||
patientId: searchData.patientId,
|
||||
patientName: searchData.patientName,
|
||||
accessionNumber: searchData.accessionNumber,
|
||||
studyDescription: searchData.studyDescription,
|
||||
modalitiesInStudy: searchData.modalitiesInStudy,
|
||||
limit: searchData.currentPage * searchData.pageSize + searchData.pageSize,
|
||||
offset: searchData.currentPage * searchData.pageSize
|
||||
limit: searchData.currentPage * searchData.rowsPerPage + searchData.rowsPerPage,
|
||||
offset: searchData.currentPage * searchData.rowsPerPage
|
||||
};
|
||||
|
||||
// TODO: add sorting
|
||||
@@ -98,13 +97,13 @@ class StudyListWithData extends Component {
|
||||
const studyCount = this.state.studies ? this.state.studies.length : 0;
|
||||
|
||||
return (<>
|
||||
<Header home />
|
||||
<Header home user={this.props.user}/>
|
||||
<StudyList studies={this.state.studies}
|
||||
studyCount={studyCount}
|
||||
studyListFunctionsEnabled={false}
|
||||
onImport={this.onImport}
|
||||
onSelectItem={this.onSelectItem}
|
||||
pageSize={this.pageSize}
|
||||
pageSize={this.rowsPerPage}
|
||||
defaultSort={this.defaultSort}
|
||||
onSearch={this.onSearch} />
|
||||
</>
|
||||
@@ -114,7 +113,8 @@ class StudyListWithData extends Component {
|
||||
|
||||
StudyListWithData.propTypes = {
|
||||
patientId: PropTypes.string,
|
||||
server: PropTypes.object
|
||||
server: PropTypes.object,
|
||||
user: PropTypes.object
|
||||
};
|
||||
|
||||
export default withRouter(StudyListWithData);
|
||||
@@ -54,6 +54,17 @@ const config = {
|
||||
|
||||
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
|
||||
|
||||
|
||||
OHIF.user.getAccessToken = () => {
|
||||
// TODO: Get the Redux store from somewhere else
|
||||
const state = window.store.getState();
|
||||
if (!state.oidc || !state.oidc.user) {
|
||||
return;
|
||||
}
|
||||
|
||||
return state.oidc.user.access_token;
|
||||
}
|
||||
|
||||
cornerstoneWADOImageLoader.configure({
|
||||
beforeSend: function(xhr) {
|
||||
const headers = OHIF.DICOMWeb.getAuthorizationHeader();
|
||||
@@ -67,7 +78,7 @@ cornerstoneWADOImageLoader.configure({
|
||||
// Set the tool font and font size
|
||||
// context.font = "[style] [variant] [weight] [size]/[line height] [font family]";
|
||||
const fontFamily =
|
||||
'Work Sans, Roboto, OpenSans, HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif';
|
||||
'Roboto, OpenSans, HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif';
|
||||
cornerstoneTools.textStyle.setFont(`16px ${fontFamily}`);
|
||||
|
||||
// Set the tool width
|
||||
|
||||
@@ -3,17 +3,23 @@ import ReactDOM from 'react-dom';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
import { createStore, combineReducers } from 'redux';
|
||||
import App from './App.js';
|
||||
import { loadUser, reducer as oidcReducer, OidcProvider} from 'redux-oidc';
|
||||
import OHIF from 'ohif-core';
|
||||
|
||||
import './config';
|
||||
import App from './App.js';
|
||||
import ui from './redux/ui.js'
|
||||
import userManager from './userManager.js';
|
||||
import Icons from "./images/icons.svg"
|
||||
|
||||
const reducers = OHIF.redux.reducers;
|
||||
reducers.ui = ui;
|
||||
reducers.oidc = oidcReducer;
|
||||
|
||||
const combined = combineReducers(reducers)
|
||||
|
||||
const store = createStore(combined);
|
||||
loadUser(store, userManager);
|
||||
|
||||
const defaultButtons = [
|
||||
{
|
||||
@@ -96,6 +102,9 @@ const servers = {
|
||||
"wadoUriRoot": "https://dcm4che.ohif.club/dcm4chee-arc/aets/DCM4CHEE/wado",
|
||||
"qidoRoot": "https://dcm4che.ohif.club/dcm4chee-arc/aets/DCM4CHEE/rs",
|
||||
"wadoRoot": "https://dcm4che.ohif.club/dcm4chee-arc/aets/DCM4CHEE/rs",
|
||||
//"wadoUriRoot": "https://cancer.crowds-cure.org/dcm4chee-arc/aets/DCM4CHEE/wado",
|
||||
//"qidoRoot": "https://cancer.crowds-cure.org/dcm4chee-arc/aets/DCM4CHEE/rs",
|
||||
//"wadoRoot": "https://cancer.crowds-cure.org/dcm4chee-arc/aets/DCM4CHEE/rs",
|
||||
"qidoSupportsIncludeField": true,
|
||||
"imageRendering": "wadors",
|
||||
"thumbnailRendering": "wadors",
|
||||
@@ -118,9 +127,11 @@ window.store = store;
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<BrowserRouter>
|
||||
<App store={store}/>
|
||||
</BrowserRouter>
|
||||
<OidcProvider store={store} userManager={userManager}>
|
||||
<BrowserRouter>
|
||||
<App/>
|
||||
</BrowserRouter>
|
||||
</OidcProvider>
|
||||
</Provider>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
@@ -0,0 +1,34 @@
|
||||
import { createUserManager } from 'redux-oidc';
|
||||
|
||||
const oidcClient = {
|
||||
authServerUrl: 'https://cancer.crowds-cure.org/auth/realms/dcm4che',
|
||||
clientId: 'crowds-cure-cancer',
|
||||
authRedirectUri: '/callback',
|
||||
postLogoutRedirectUri: '/logout-redirect.html',
|
||||
responseType: 'id_token token',
|
||||
scope: 'email profile openid',
|
||||
revokeAccessTokenOnSignout: true,
|
||||
extraQueryParams: {
|
||||
kc_idp_hint: 'crowds-cure-cancer-auth0-oidc',
|
||||
client_id: 'crowds-cure-cancer'
|
||||
}
|
||||
};
|
||||
|
||||
const settings = {
|
||||
authority: oidcClient.authServerUrl,
|
||||
client_id: oidcClient.clientId,
|
||||
redirect_uri: oidcClient.authRedirectUri,
|
||||
silent_redirect_uri: '/silent-refresh.html',
|
||||
post_logout_redirect_uri: oidcClient.postLogoutRedirectUri,
|
||||
response_type: oidcClient.responseType,
|
||||
scope: 'email profile openid', // Note: Request must have scope 'openid' to be considered an OpenID Connect request
|
||||
automaticSilentRenew: true,
|
||||
revokeAccessTokenOnSignout: true,
|
||||
filterProtocolClaims: true,
|
||||
loadUserInfo: true,
|
||||
extraQueryParams: oidcClient.extraQueryParams
|
||||
};
|
||||
|
||||
const userManager = createUserManager(settings);
|
||||
|
||||
export default userManager;
|
||||
Reference in new issue
Block a user