Skip to content

Commit

Permalink
Merge pull request #440 from InseeFr/hot-fix/v2-auth
Browse files Browse the repository at this point in the history
Hot fix: v2 auth
  • Loading branch information
laurentC35 authored Oct 5, 2023
2 parents 2780b42 + f89408d commit c2f247c
Show file tree
Hide file tree
Showing 69 changed files with 4,733 additions and 5,819 deletions.
13 changes: 13 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
SKIP_PREFLIGHT_CHECK=true
REACT_APP_SURVEY_API_BASE_URL=
REACT_APP_LUNATIC_LOADER_WORKER_PATH=/workers/lunatic-append-worker-0.3.0-experimental.js
REACT_APP_LUNATIC_SEARCH_WORKER_PATH=/workers/lunatic-searching-worker-0.3.0-experimental.js
REACT_APP_LUNATIC_LABEL_WORKER_PATH=/workers/lunatic-label-worker-0.3.0-experimental.js
# REACT_APP_SAVING_TIME When data is put : 'sequence' or 'page', default: sequence
REACT_APP_SAVING_TIME=
# REACT_APP_SAVING_STRATEGY: If data has to be send each time complete or just changed data : 'complete' or 'partial', , default: complete
REACT_APP_SAVING_STRATEGY=
# default: recensement
REACT_APP_DEFAULT_SURVEY=
# REACT_APP_AUTH_TYPE: oidc / none, default: none
REACT_APP_AUTH_TYPE=oidc
REACT_APP_CLIENT_ID=localhost-frontend
REACT_APP_AUTHORITY=https://auth.insee.net/auth/realms/questionnaire-particuliers
REACT_APP_PORTAIL_URL=https://enquetes.beta.stat-publique.fr
REACT_APP_IDENTITY_PROVIDER=insee-ssp
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- run: yarn
- run: yarn build
- name: Upload build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/develop-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- run: yarn
- run: yarn build
- name: Upload build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- run: yarn
- run: yarn build
- name: Upload build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ jobs:
install:
runs-on: ubuntu-latest
steps:
- name: Use Node.js 14C
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- run: yarn --frozen-lockfile
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
- name: Use Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- run: yarn
- run: yarn build
- name: Upload build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ configuration-local.json
oidc-local.json
keycloak-local.json

/public/OidcServiceWorker.js
/public/OidcTrustedDomains.js

npm-debug.log*
yarn-debug.log*
Expand Down
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
FROM nginx
RUN rm -rf /usr/share/nginx/html/*

ADD build /usr/share/nginx/html

RUN rm etc/nginx/conf.d/default.conf
COPY nginx.conf etc/nginx/conf.d/
COPY ./nginx.conf /etc/nginx/conf.d/

# Copy .env file and shell script to container
WORKDIR /usr/share/nginx/html
COPY ./scripts/env.sh .
COPY ./scripts/.env .

# Make shell script executable and prevent windows encoding
RUN sed -i -e 's/\r$//' env.sh && sed -i -e 's/\r$//' .env && chmod +x env.sh
COPY entrypoint.sh /entrypoint.sh
RUN chmod 755 /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]

# Start Nginx server
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]
CMD ["nginx", "-g", "daemon off;"]
7 changes: 0 additions & 7 deletions configuration/configuration.json

This file was deleted.

56 changes: 13 additions & 43 deletions craco.config.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,18 @@
module.exports = {
babel: {
loaderOptions: (babelLoaderOptions) => {
const origBabelPresetCRAIndex = babelLoaderOptions.presets.findIndex(
(preset) => {
return preset[0].includes('babel-preset-react-app');
}
);

const origBabelPresetCRA =
babelLoaderOptions.presets[origBabelPresetCRAIndex];

babelLoaderOptions.presets[origBabelPresetCRAIndex] =
function overridenPresetCRA(api, opts, env) {
const babelPresetCRAResult = require(origBabelPresetCRA[0])(
api,
origBabelPresetCRA[1],
env
);

babelPresetCRAResult.presets.forEach((preset) => {
// detect @babel/preset-react with {development: true, runtime: 'automatic'}
const isReactPreset =
preset &&
preset[1] &&
preset[1].runtime === 'automatic' &&
preset[1].development === true;
if (isReactPreset) {
preset[1].importSource = '@welldone-software/why-did-you-render';
}
});

return babelPresetCRAResult;
};
const OVERLOAD = { fs: false, stream: false, os: false };

return babelLoaderOptions;
},
},
// if you want to track react-redux selectors
module.exports = {
webpack: {
alias: {
'react-redux':
process.env.NODE_ENV === 'development'
? 'react-redux/lib'
: 'react-redux',
configure: (config, { env, paths }) => {
const { resolve } = config;
const { fallback } = resolve;

return {
...config,
resolve: {
...resolve,
fallback: { ...fallback, ...OVERLOAD },
},
};
},
},
};
15 changes: 15 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
echo "self._env_['SKIP_PREFLIGHT_CHECK'] = '$SKIP_PREFLIGHT_CHECK';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_SURVEY_API_BASE_URL'] = '$REACT_APP_SURVEY_API_BASE_URL';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_LUNATIC_LOADER_WORKER_PATH'] = '$REACT_APP_LUNATIC_LOADER_WORKER_PATH';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_LUNATIC_SEARCH_WORKER_PATH'] = '$REACT_APP_LUNATIC_SEARCH_WORKER_PATH';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_LUNATIC_LABEL_WORKER_PATH'] = '$REACT_APP_LUNATIC_LABEL_WORKER_PATH';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_SAVING_TIME'] = '$REACT_APP_SAVING_TIME';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_SAVING_STRATEGY'] = '$REACT_APP_SAVING_STRATEGY';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_DEFAULT_SURVEY'] = '$REACT_APP_DEFAULT_SURVEY';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_AUTH_TYPE'] = '$REACT_APP_AUTH_TYPE';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_CLIENT_ID'] = '$REACT_APP_CLIENT_ID';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_AUTHORITY'] = '$REACT_APP_AUTHORITY';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_PORTAIL_URL'] = '$REACT_APP_PORTAIL_URL';" >> /usr/share/nginx/html/env-config.js
echo "self._env_['REACT_APP_IDENTITY_PROVIDER'] = '$REACT_APP_IDENTITY_PROVIDER';" >> /usr/share/nginx/html/env-config.js
exec "$@"
18 changes: 16 additions & 2 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
{
"compilerOptions": {
"baseUrl": "./src"
}
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"include": ["src"]
}
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stromae",
"version": "2.4.9",
"version": "2.4.10",
"description": "Web application for the management of questionnaires powered by Lunatic",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
"author": "INSEE (http://www.insee.fr)",
"license": "MIT",
"dependencies": {
"@craco/craco": "^6.4.0",
"@axa-fr/react-oidc": "^7.6.0",
"@inseefr/lunatic": "2.4.9",
"@material-ui/core": "^4.11.2",
"@material-ui/icons": "^4.11.2",
Expand All @@ -19,32 +19,33 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"date-fns": "^2.29.3",
"keycloak-js": "^22.0.0",
"oidc-client": "^1.10.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^3.1.3",
"react-markdown": "^5.0.3",
"react-modal": "^3.12.1",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.1",
"react-scripts": "5.0.0",
"react-swipeable-views": "^0.13.9",
"react-swipeable-views-utils": "^0.14.0-alpha.0",
"sass": "^1.32.6",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "react-scripts start",
"start-dev": "craco start",
"build": "react-scripts build && copy-and-watch configuration/* build",
"test": "react-scripts test",
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"prepare": "husky install",
"lint:check": "eslint . --ext .js,.jsx",
"lint": "npm run lint:check -- --fix",
"_format": "prettier '**/*.{js,jsx,json,md}'",
"format": "npm run _format -- --write",
"format:check": "npm run _format -- --list-different"
"format:check": "npm run _format -- --list-different",
"postinstall": "node ./node_modules/@axa-fr/react-oidc/bin/copy-service-worker-files.mjs public",
"prestart": "node -r dotenv/config ./scripts/generate-oidc-trusted-domains.js",
"postbuild": "node -r dotenv/config ./scripts/generate-oidc-trusted-domains.js"
},
"lint-staged": {
"*.{js,jsx}": [
Expand Down Expand Up @@ -72,10 +73,12 @@
]
},
"devDependencies": {
"@craco/craco": "^7.1.0",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@welldone-software/why-did-you-render": "^6.2.3",
"copy-and-watch": "^0.1.5",
"dotenv": "^16.3.1",
"eslint": "^8.12.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
Expand Down
7 changes: 0 additions & 7 deletions public/configuration.json

This file was deleted.

2 changes: 2 additions & 0 deletions public/env-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* eslint-disable no-restricted-globals */
if (!self._env_) self._env_ = {};
36 changes: 28 additions & 8 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,36 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="apple-touch-icon" sizes="180x180" href="/static/images/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/static/images/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/static/images/icons/favicon-16x16.png">
<link rel="mask-icon" href="/static/images/icons/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#2d89ef">
<meta name="theme-color" content="#ffffff">

<link
rel="apple-touch-icon"
sizes="180x180"
href="/static/images/icons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/static/images/icons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/static/images/icons/favicon-16x16.png"
/>
<link
rel="mask-icon"
href="/static/images/icons/safari-pinned-tab.svg"
color="#5bbad5"
/>
<meta name="msapplication-TileColor" content="#2d89ef" />
<meta name="theme-color" content="#ffffff" />
<link rel="manifest" href="/manifest.json" />
<meta name="description" content="Questionnaire auprès des particuliers" />


<script type="module" src="/env-config.js"></script>

<title>Questionnaire auprès des particuliers</title>
</head>
<body>
Expand Down
5 changes: 0 additions & 5 deletions public/keycloak.json

This file was deleted.

7 changes: 0 additions & 7 deletions scripts/.env

This file was deleted.

24 changes: 0 additions & 24 deletions scripts/env.sh

This file was deleted.

Loading

0 comments on commit c2f247c

Please sign in to comment.