Skip to content

Commit

Permalink
feat(authorization): enable code flow by config (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <[email protected]>
  • Loading branch information
TheMaskedTurtle authored Dec 1, 2023
1 parent 4eebcbb commit f6d4a14
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"@emotion/react": "^11.8.2",
"@emotion/styled": "^11.8.1",
"@gridsuite/commons-ui": "^0.35.6",
"@gridsuite/commons-ui": "0.41.0",
"@hookform/resolvers": "^3.3.1",
"@mui/icons-material": "^5.5.1",
"@mui/lab": "^5.0.0-alpha.75",
Expand Down
16 changes: 11 additions & 5 deletions src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Box, Typography } from '@mui/material';

import {
connectNotificationsWsUpdateConfig,
fetchAuthorizationCodeFlowFeatureFlag,
fetchConfigParameter,
fetchConfigParameters,
fetchValidateUser,
Expand Down Expand Up @@ -130,11 +131,16 @@ const App = () => {

const initialize = useCallback(() => {
if (process.env.REACT_APP_USE_AUTHENTICATION === 'true') {
return initializeAuthenticationProd(
dispatch,
initialMatchSilentRenewCallbackUrl != null,
fetch('idpSettings.json'),
fetchValidateUser
return fetchAuthorizationCodeFlowFeatureFlag().then(
(authorizationCodeFlowEnabled) => {
return initializeAuthenticationProd(
dispatch,
initialMatchSilentRenewCallbackUrl != null,
fetch('idpSettings.json'),
fetchValidateUser,
authorizationCodeFlowEnabled
);
}
);
} else {
return initializeAuthenticationDev(
Expand Down
27 changes: 27 additions & 0 deletions src/utils/rest-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ export function fetchValidateUser(user) {
});
}

export function fetchAuthorizationCodeFlowFeatureFlag() {
console.info(`Fetching authorization code flow feature flag...`);
return fetch('env.json')
.then((res) => res.json())
.then((res) => {
return fetch(res.appsMetadataServerUrl + '/authentication.json')
.then((res) => res.json())
.then((res) => {
console.log(
`Authorization code flow is ${
res.authorizationCodeFlowFeatureFlag
? 'enabled'
: 'disabled'
}`
);
return res.authorizationCodeFlowFeatureFlag;
})
.catch((error) => {
console.error(error);
console.warn(
`Something wrong happened when retrieving authentication.json: authorization code flow will be disabled`
);
return false;
});
});
}

export function fetchAppsAndUrls() {
console.info(`Fetching apps and urls...`);
return fetch('env.json')
Expand Down

0 comments on commit f6d4a14

Please sign in to comment.