Skip to content

Commit

Permalink
Merge pull request #248 from InseeFr/v2-develop
Browse files Browse the repository at this point in the history
release 2.3.1
  • Loading branch information
ORogel authored Mar 24, 2023
2 parents 97d9a9e + 0e5cb10 commit 3ee7481
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 91 deletions.
6 changes: 0 additions & 6 deletions configuration/build-configuration.json

This file was deleted.

3 changes: 2 additions & 1 deletion configuration/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"authenticationType": "${AUTHENTICATION_TYPE}",
"_authenticationType_comment_": "Authentication type : OIDC or NONE",
"apiUrl": "${API_URL}",
"portail": "${PORTAIL_URL}"
"portail": "${PORTAIL_URL}",
"identityProvider": "${IDENTITY_PROVIDER}"
}
15 changes: 0 additions & 15 deletions configuration/oidc.json

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stromae",
"version": "2.2.14",
"version": "2.3.1",
"description": "Web application for the management of questionnaires powered by Lunatic",
"repository": {
"type": "git",
Expand Down
6 changes: 0 additions & 6 deletions public/build-configuration.json

This file was deleted.

5 changes: 3 additions & 2 deletions public/configuration.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"authenticationType": "${AUTHENTICATION_TYPE}",
"authenticationType": "NONE",
"_authenticationType_comment_": "Authentication type : OIDC or NONE",
"apiUrl": "${API_URL}",
"portail": "${PORTAIL_URL}"
"portail": "${PORTAIL_URL}",
"identityProvider": "${IDENTITY_PROVIDER}"
}
4 changes: 3 additions & 1 deletion scripts/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AUTHENTICATION_TYPE=NONE
API_URL=https://stromae-bo.dev.insee.io
PORTAIL_URL=
REALM=
AUTHORITY=
CLIENT_ID=
CLIENT_ID=
IDENTITY_PROVIDER=
8 changes: 2 additions & 6 deletions scripts/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ do

done < .env
envsubst < "./configuration.json" > "configuration.temp"
envsubst < "./build-configuration.json" > "build-configuration.temp"
envsubst < "./build-oidc.json" > "build-oidc.temp"
envsubst < "./oidc.json" > "oidc.temp"
envsubst < "./keycloak.json" > "keycloak.temp"
mv configuration.temp configuration.json
mv build-configuration.temp build-configuration.json
mv build-oidc.temp build-oidc.json
mv oidc.temp oidc.json
mv keycloak.temp keycloak.json
13 changes: 5 additions & 8 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useEffect, useState } from 'react';
import { BrowserRouter } from 'react-router-dom';
import { ErrorBoundary } from 'react-error-boundary';
import { AuthProvider } from 'components/auth';
import { Router } from 'components/router';
import { StyleProvider } from 'components/style';
import { ErrorFallback } from 'components/shared/error';
import { StyleProvider } from 'components/style';
import React, { useEffect, useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { BrowserRouter } from 'react-router-dom';
import { getConfiguration } from 'utils/configuration';
import './App.css';

Expand All @@ -30,10 +30,7 @@ const App = () => {
>
{configuration && (
<AppContext.Provider value={configuration}>
<AuthProvider
authType={configuration.authenticationType}
urlPortail={configuration.portail}
>
<AuthProvider>
<BrowserRouter>
<Router />
</BrowserRouter>
Expand Down
20 changes: 14 additions & 6 deletions src/components/auth/provider/component.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import React, { useEffect, useState } from 'react';
import { OIDC, NONE } from 'utils/constants';
import { AppContext } from 'App';
import { LoaderSimple } from 'components/shared/loader';
import { getOidc } from 'utils/configuration';
import { errorDictionary } from 'i18n';
import { createKeycloakOidcClient } from 'utils/keycloak';
import React, { useContext, useEffect, useState } from 'react';
import { getOidc } from 'utils/configuration';
import { NONE, OIDC } from 'utils/constants';
import { listenActivity } from 'utils/events';
import { createKeycloakOidcClient } from 'utils/keycloak';

export const AuthContext = React.createContext();

const AuthProvider = ({ authType, urlPortail, children }) => {
const AuthProvider = ({ children }) => {
const {
authenticationType: authType,
portail: urlPortail,
identityProvider,
} = useContext(AppContext);

const [oidcClient, setOidcClient] = useState(() => {
switch (authType) {
case OIDC:
Expand All @@ -32,13 +39,14 @@ const AuthProvider = ({ authType, urlPortail, children }) => {
url: oidcConf['auth-server-url'],
realm: oidcConf['realm'],
clientId: oidcConf['resource'],
identityProvider: identityProvider,
urlPortail,
evtUserActivity: listenActivity,
});

setOidcClient(oidcClient);
})();
}, [authType, urlPortail]);
}, [authType, identityProvider, urlPortail]);

if (oidcClient === null) return <LoaderSimple />;

Expand Down
3 changes: 1 addition & 2 deletions src/utils/configuration/get-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { getEnvVar } from './env';

const basePath = `${window.location.origin}`;

const nameConfigFile =
getEnvVar('NAME_CONFIG_FILE') ?? 'build-configuration.json';
const nameConfigFile = getEnvVar('NAME_CONFIG_FILE') ?? 'configuration.json';

const nameOidcFile = getEnvVar('NAME_OIDC_FILE') ?? 'keycloak.json';

Expand Down
10 changes: 9 additions & 1 deletion src/utils/keycloak/keycloakOidcClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Keycloak from 'keycloak-js';
import { READ_ONLY } from 'utils/constants';

const getCurrentSurvey = (path) => {
const temp = path.split('/questionnaire/');
Expand All @@ -13,6 +14,7 @@ export const createKeycloakOidcClient = async ({
url,
realm,
clientId,
identityProvider,
urlPortail,
evtUserActivity,
}) => {
Expand All @@ -27,7 +29,13 @@ export const createKeycloakOidcClient = async ({
.catch((error) => error);

const login = async () => {
await keycloakInstance.login({ redirectUri: window.location.href });
await keycloakInstance.login({
redirectUri: window.location.href,
// Readonly mode : Internal user login
idpHint: window.location.pathname.startsWith(`/${READ_ONLY}`)
? identityProvider
: null,
});
return new Promise(() => {});
};

Expand Down
36 changes: 0 additions & 36 deletions src/utils/oidc/build-configuration.js

This file was deleted.

0 comments on commit 3ee7481

Please sign in to comment.