Skip to content

Commit

Permalink
Remove old authentication flag and update fn call
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jun 14, 2024
1 parent 664aee0 commit aa5b889
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@gridsuite/commons-ui": "0.53.0",
"@gridsuite/commons-ui": "0.60.0",
"@hookform/resolvers": "^3.3.4",
"@mui/icons-material": "^5.15.14",
"@mui/lab": "5.0.0-alpha.169",
Expand Down
35 changes: 17 additions & 18 deletions src/routes/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ import {
useMatch,
useNavigate,
} from 'react-router-dom';
import { UserManager } from 'oidc-client';
import { useDispatch, useSelector } from 'react-redux';
import { AppState } from '../redux/reducer';
import { AppsMetadataSrv, UserAdminSrv } from '../services';
import { App } from '../components/App';
import { Users, Profiles } from '../pages';
import { Profiles, Users } from '../pages';
import ErrorPage from './ErrorPage';
import { updateUserManagerDestructured } from '../redux/actions';
import HomePage from './HomePage';
Expand Down Expand Up @@ -138,27 +137,27 @@ const AppAuthStateWithRouterLayer: FunctionComponent<
);

useEffect(() => {
AppsMetadataSrv.fetchAuthorizationCodeFlowFeatureFlag()
.then((authorizationCodeFlowEnabled) =>
initializeAuthenticationProd(
dispatch,
initialMatchSilentRenewCallbackUrl != null,
fetch('idpSettings.json'),
UserAdminSrv.fetchValidateUser,
authorizationCodeFlowEnabled,
initialMatchSignInCallbackUrl != null
)
)
.then((userManager: UserManager | undefined) => {
// need subfunction when async as suggested by rule react-hooks/exhaustive-deps
(async function initializeAuthentication() {
try {
dispatch(
updateUserManagerDestructured(userManager ?? null, null)
updateUserManagerDestructured(
(await initializeAuthenticationProd(
dispatch,
initialMatchSilentRenewCallbackUrl != null,
AppsMetadataSrv.fetchIdpSettings,
UserAdminSrv.fetchValidateUser,
initialMatchSignInCallbackUrl != null
)) ?? null,
null
)
);
})
.catch((error: any) => {
} catch (error: unknown) {
dispatch(
updateUserManagerDestructured(null, getErrorMessage(error))
);
});
}
})();
// Note: initialize and initialMatchSilentRenewCallbackUrl & initialMatchSignInCallbackUrl won't change
}, [
dispatch,
Expand Down
33 changes: 5 additions & 28 deletions src/services/apps-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import { getErrorMessage } from '../utils/error';
import { Url } from '../utils/api-rest';

//import { IdpSettings } from '@gridsuite/commons-ui';
export type IdpSettingsJson = typeof import('../../public/idpSettings.json');

export type EnvJson = typeof import('../../public/env.json') & {
// https://github.com/gridsuite/deployment/blob/main/docker-compose/env.json
// https://github.com/gridsuite/deployment/blob/main/k8s/live/azure-dev/env.json
Expand All @@ -22,34 +25,8 @@ function fetchEnv(): Promise<EnvJson> {
return fetch('env.json').then((res: Response) => res.json());
}

export function fetchAuthorizationCodeFlowFeatureFlag(): Promise<boolean> {
console.debug('Fetching authorization code flow feature flag...');
return fetchEnv()
.then((env: EnvJson) =>
fetch(`${env.appsMetadataServerUrl}/authentication.json`)
)
.then((res: Response) => res.json())
.then((res: { authorizationCodeFlowFeatureFlag: boolean }) => {
console.info(
`Authorization code flow is ${
res.authorizationCodeFlowFeatureFlag
? 'enabled'
: 'disabled'
}`
);
return res.authorizationCodeFlowFeatureFlag || false;
})
.catch((error) => {
console.error(
`Error while fetching the authentication code flow: ${getErrorMessage(
error
)}`
);
console.warn(
'Something wrong happened when retrieving authentication.json: authorization code flow will be disabled'
);
return false;
});
export function fetchIdpSettings(): Promise<IdpSettingsJson> {
return fetch('idpSettings.json').then((res) => res.json());
}

export type VersionJson = {
Expand Down

0 comments on commit aa5b889

Please sign in to comment.