Shift oidc and initWebworkers to own files
This commit is contained in:
parent
70f83f131a
commit
69fb4d7947
76
src/App.js
76
src/App.js
@ -13,19 +13,16 @@ import OHIFVTKExtension from 'ohif-vtk-extension'
|
|||||||
import OHIFDicomPDFExtension from 'ohif-dicom-pdf-extension'
|
import OHIFDicomPDFExtension from 'ohif-dicom-pdf-extension'
|
||||||
import OHIFDicomHtmlExtension from 'ohif-dicom-html-extension'
|
import OHIFDicomHtmlExtension from 'ohif-dicom-html-extension'
|
||||||
import OHIFDicomMicroscopyExtension from 'ohif-dicom-microscopy-extension'
|
import OHIFDicomMicroscopyExtension from 'ohif-dicom-microscopy-extension'
|
||||||
|
import { OidcProvider, reducer as oidcReducer } from 'redux-oidc'
|
||||||
import {
|
import {
|
||||||
loadUser,
|
getUserManagerForOpenIdConnectClient,
|
||||||
OidcProvider,
|
initWebWorkers,
|
||||||
createUserManager,
|
} from './utils/index.js'
|
||||||
reducer as oidcReducer,
|
|
||||||
} from 'redux-oidc'
|
|
||||||
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader'
|
|
||||||
|
|
||||||
const { ExtensionManager } = OHIF.extensions
|
|
||||||
|
|
||||||
const Icons = 'icons.svg'
|
const Icons = 'icons.svg'
|
||||||
|
const { ExtensionManager } = OHIF.extensions
|
||||||
const { reducers, localStorage } = OHIF.redux
|
const { reducers, localStorage } = OHIF.redux
|
||||||
|
|
||||||
reducers.ui = ui
|
reducers.ui = ui
|
||||||
reducers.oidc = oidcReducer
|
reducers.oidc = oidcReducer
|
||||||
|
|
||||||
@ -163,60 +160,6 @@ function handleServers(servers) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleOIDC(oidc) {
|
|
||||||
if (!oidc) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const oidcClient = oidc[0]
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
loadUser(store, userManager)
|
|
||||||
|
|
||||||
return userManager
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {String} baseDirectory
|
|
||||||
* @param {String} webWorkScriptsPath
|
|
||||||
*/
|
|
||||||
function handleWebWorkerInit(baseDirectory, webWorkScriptsPath) {
|
|
||||||
const scriptsPath = `${baseDirectory}/${webWorkScriptsPath}`
|
|
||||||
const config = {
|
|
||||||
maxWebWorkers: Math.max(navigator.hardwareConcurrency - 1, 1),
|
|
||||||
startWebWorkersOnDemand: true,
|
|
||||||
webWorkerPath: `${scriptsPath}/cornerstoneWADOImageLoaderWebWorker.min.js`,
|
|
||||||
taskConfiguration: {
|
|
||||||
decodeTask: {
|
|
||||||
loadCodecsOnStartup: true,
|
|
||||||
initializeCodecsOnStartup: false,
|
|
||||||
codecsPath: `${scriptsPath}/cornerstoneWADOImageLoaderCodecs.min.js`,
|
|
||||||
usePDFJS: false,
|
|
||||||
strict: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
cornerstoneWADOImageLoader.webWorkerManager.initialize(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
routerBasename: PropTypes.string,
|
routerBasename: PropTypes.string,
|
||||||
@ -238,9 +181,12 @@ class App extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.userManager = handleOIDC(this.props.oidc)
|
this.userManager = getUserManagerForOpenIdConnectClient(
|
||||||
|
store,
|
||||||
|
this.props.oidc
|
||||||
|
)
|
||||||
handleServers(this.props.servers)
|
handleServers(this.props.servers)
|
||||||
handleWebWorkerInit(
|
initWebWorkers(
|
||||||
this.props.routerBasename,
|
this.props.routerBasename,
|
||||||
this.props.relativeWebWorkerScriptsPath
|
this.props.relativeWebWorkerScriptsPath
|
||||||
)
|
)
|
||||||
|
|||||||
5
src/__mocks__/cornerstone-wado-image-loader.js
Normal file
5
src/__mocks__/cornerstone-wado-image-loader.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
webWorkerManager: {
|
||||||
|
initialize: jest.fn(),
|
||||||
|
},
|
||||||
|
}
|
||||||
52
src/utils/getUserManagerForOpenIdConnectClient.js
Normal file
52
src/utils/getUserManagerForOpenIdConnectClient.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// https://github.com/maxmantz/redux-oidc/blob/master/docs/API.md
|
||||||
|
import { loadUser, createUserManager } from 'redux-oidc'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a userManager from oidcSettings;
|
||||||
|
* loads the user into the provided redux store
|
||||||
|
*
|
||||||
|
* @param {*} store
|
||||||
|
* @param {Object} oidcSettings
|
||||||
|
* @param {string} oidcSettings.authServerUrl,
|
||||||
|
* @param {string} oidcSettings.clientId,
|
||||||
|
* @param {string} oidcSettings.authRedirectUri,
|
||||||
|
* @param {string} oidcSettings.postLogoutRedirectUri,
|
||||||
|
* @param {string} oidcSettings.responseType,
|
||||||
|
* @param {string} oidcSettings.extraQueryParams,
|
||||||
|
*/
|
||||||
|
export default function(store, oidcSettings) {
|
||||||
|
if (!store || !oidcSettings) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
authServerUrl,
|
||||||
|
clientId,
|
||||||
|
authRedirectUri,
|
||||||
|
postLogoutRedirectUri,
|
||||||
|
responseType,
|
||||||
|
extraQueryParams,
|
||||||
|
} = oidcSettings
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
authority: authServerUrl,
|
||||||
|
client_id: clientId,
|
||||||
|
redirect_uri: authRedirectUri,
|
||||||
|
silent_redirect_uri: '/silent-refresh.html',
|
||||||
|
post_logout_redirect_uri: postLogoutRedirectUri,
|
||||||
|
response_type: responseType,
|
||||||
|
// Note: Request must have scope 'openid' to be considered an OpenID Connect request
|
||||||
|
scope: 'email profile openid',
|
||||||
|
automaticSilentRenew: true,
|
||||||
|
revokeAccessTokenOnSignout: true,
|
||||||
|
filterProtocolClaims: true,
|
||||||
|
loadUserInfo: true,
|
||||||
|
extraQueryParams: extraQueryParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
const userManager = createUserManager(settings)
|
||||||
|
|
||||||
|
loadUser(store, userManager)
|
||||||
|
|
||||||
|
return userManager
|
||||||
|
}
|
||||||
4
src/utils/index.js
Normal file
4
src/utils/index.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import getUserManagerForOpenIdConnectClient from './getUserManagerForOpenIdConnectClient.js'
|
||||||
|
import initWebWorkers from './initWebWorkers.js'
|
||||||
|
|
||||||
|
export { getUserManagerForOpenIdConnectClient, initWebWorkers }
|
||||||
26
src/utils/initWebWorkers.js
Normal file
26
src/utils/initWebWorkers.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader'
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {String} baseDirectory
|
||||||
|
* @param {String} webWorkScriptsPath
|
||||||
|
*/
|
||||||
|
export default function(baseDirectory, webWorkScriptsPath) {
|
||||||
|
const scriptsPath = `${baseDirectory}/${webWorkScriptsPath}`
|
||||||
|
const config = {
|
||||||
|
maxWebWorkers: Math.max(navigator.hardwareConcurrency - 1, 1),
|
||||||
|
startWebWorkersOnDemand: true,
|
||||||
|
webWorkerPath: `${scriptsPath}/cornerstoneWADOImageLoaderWebWorker.min.js`,
|
||||||
|
taskConfiguration: {
|
||||||
|
decodeTask: {
|
||||||
|
loadCodecsOnStartup: true,
|
||||||
|
initializeCodecsOnStartup: false,
|
||||||
|
codecsPath: `${scriptsPath}/cornerstoneWADOImageLoaderCodecs.min.js`,
|
||||||
|
usePDFJS: false,
|
||||||
|
strict: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cornerstoneWADOImageLoader.webWorkerManager.initialize(config)
|
||||||
|
}
|
||||||
15
src/utils/initWebWorkers.test.js
Normal file
15
src/utils/initWebWorkers.test.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import initWebWorkers from './initWebWorkers.js'
|
||||||
|
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader'
|
||||||
|
|
||||||
|
describe('initWebWorkers', () => {
|
||||||
|
it("initializes cornerstoneWADOImageLoader's web workers", () => {
|
||||||
|
const basePath = '/'
|
||||||
|
const relativeWebWorkerScriptsPath = ''
|
||||||
|
|
||||||
|
initWebWorkers(basePath, relativeWebWorkerScriptsPath)
|
||||||
|
|
||||||
|
expect(
|
||||||
|
cornerstoneWADOImageLoader.webWorkerManager.initialize
|
||||||
|
).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue
Block a user