Skip to content

Commit

Permalink
Variabilize ident provider (#6)
Browse files Browse the repository at this point in the history
* variabilize identity provider

* remove useless log
  • Loading branch information
EricThuaud authored Feb 14, 2023
1 parent 54786e1 commit 8804b32
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coleman-management",
"version": "0.2.4",
"version": "0.2.5",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
Expand Down
5 changes: 3 additions & 2 deletions public/configuration.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"authType": "NONE",
"authType": "OIDC",
"apiUrl": "https://datacollection-management-api.dev.insee.io",
"moogUrl": "https://suivi-gestion-collecte-enquetes.dev.insee.io"
"moogUrl": "https://suivi-gestion-collecte-enquetes.dev.insee.io",
"identityProvider": "insee-ssp"
}
4 changes: 2 additions & 2 deletions public/keycloak.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"realm": "my-realm",
"auth-server-url": "https://my.nice.server/auth",
"auth-server-url": "https://my-nice-server.test/auth",
"ssl-required": "none",
"resource": "localhost-frontend",
"resource": "my-client",
"public-client": true,
"confidential-port": 0
}
5 changes: 4 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const App = () => {
<>
{configuration && (
<AppContext.Provider value={context}>
<AuthProvider authType={configuration.authType}>
<AuthProvider
authType={configuration.authType}
identityProvider={configuration.identityProvider}
>
<React.StrictMode>
<UserAccountProvider>
<Router />
Expand Down
10 changes: 8 additions & 2 deletions src/core/keycloak/keycloakOidcClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Keycloak from "keycloak-js";

export const createKeycloakOidcClient = async ({ url, realm, clientId, evtUserActivity }) => {
export const createKeycloakOidcClient = async ({
url,
realm,
clientId,
evtUserActivity,
identityProvider,
}) => {
const keycloakInstance = new Keycloak({ url, realm, clientId });

const isAuthenticated = await keycloakInstance
Expand All @@ -12,7 +18,7 @@ export const createKeycloakOidcClient = async ({ url, realm, clientId, evtUserAc
.catch(error => error);

const login = async () => {
await keycloakInstance.login({ idpHint: "sso-insee", redirectUri: window.location.href });
await keycloakInstance.login({ idpHint: identityProvider, redirectUri: window.location.href });
return new Promise(() => {});
};

Expand Down
4 changes: 2 additions & 2 deletions src/ui/context/auth/provider/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ const dummyOidcClient = {
isUserLoggedIn: false,
};

const AuthProvider = ({ authType, children }) => {
const AuthProvider = ({ authType, identityProvider, children }) => {
const [oidcClient, setOidcClient] = useState(null);

useEffect(() => {
const loadOidcConf = async () => {
const oidcConf = await getOidc();

const oidcClientKC = await createKeycloakOidcClient({
url: oidcConf["auth-server-url"],
realm: oidcConf["realm"],
clientId: oidcConf["resource"],
evtUserActivity: listenActivity,
identityProvider,
});
return oidcClientKC;
};
Expand Down

0 comments on commit 8804b32

Please sign in to comment.