Files
ohif-viewer/src/utils/getUserManagerForOpenIdConnectClient.js
T

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-04-29 15:39:09 -04:00
// https://github.com/maxmantz/redux-oidc/blob/master/docs/API.md
2019-05-29 08:39:54 -04:00
import { loadUser, createUserManager } from 'redux-oidc';
import { WebStorageStateStore, InMemoryWebStorage } from 'oidc-client';
2019-04-29 15:39:09 -04:00
/**
* Creates a userManager from oidcSettings;
* loads the user into the provided redux store
2019-05-07 15:42:11 -04:00
* LINK: https://github.com/IdentityModel/oidc-client-js/wiki#configuration
2019-04-29 15:39:09 -04:00
*
* @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) {
2019-05-29 08:39:54 -04:00
return;
2019-04-29 15:39:09 -04:00
}
// Do not store tokens in localStorage or sessionStorage
// https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/HTML5_Security_Cheat_Sheet.md#local-storage
const userStore = new WebStorageStateStore({ store: new InMemoryWebStorage() });
2019-04-29 15:39:09 -04:00
const settings = {
2019-05-07 15:42:11 -04:00
...oidcSettings,
2019-04-29 15:39:09 -04:00
automaticSilentRenew: true,
revokeAccessTokenOnSignout: true,
filterProtocolClaims: true,
loadUserInfo: true,
userStore,
2019-05-29 08:39:54 -04:00
};
2019-04-29 15:39:09 -04:00
2019-05-29 08:39:54 -04:00
const userManager = createUserManager(settings);
2019-04-29 15:39:09 -04:00
2019-05-29 08:39:54 -04:00
loadUser(store, userManager);
2019-04-29 15:39:09 -04:00
2019-05-29 08:39:54 -04:00
return userManager;
2019-04-29 15:39:09 -04:00
}