Skip to content

Commit

Permalink
Merge pull request #5 from InseeFr/fix_keycloak_sso
Browse files Browse the repository at this point in the history
Fix keycloak sso
  • Loading branch information
EricThuaud authored Jan 3, 2023
2 parents 4235f75 + 4241cea commit 54786e1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .k8s/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ spec:
spec:
containers:
- name: dc-management-ui
image: inseefr/coleman-management:0.2.3-rc
image: inseefr/coleman-management:0.2.4-rc
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.3",
"version": "0.2.4",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
Expand Down
4 changes: 2 additions & 2 deletions src/core/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const deleteRequest = (url) => (token) => (body) =>
*/
const getRequest = url => params => token => fetcher(url, token, "GET", params, null);
const getAllContacts = apiUrl => token => getRequest(`${apiUrl}/api/contacts`)(null)(token);
const getAllCampaigns = apiUrl => token => getRequest(`${apiUrl}/campaigns`)(null)(token);
const getAllCampaigns = apiUrl => token => getRequest(`${apiUrl}/api/campaigns`)(null)(token);
const getAllSurveyUnits = apiUrl => token => getRequest(`${apiUrl}/api/survey-units`)(null)(token);

const getContacts = apiUrl => searchParams => token =>
Expand All @@ -19,7 +19,7 @@ const getContactAccreditations = apiUrl => id => token =>
getRequest(`${apiUrl}/api/contacts/${id}/accreditations`)(null)(token);
const updateContact = apiUrl => (id, contactInfos) => token =>
putRequest(`${apiUrl}/api/contacts/${id}`)(contactInfos)(token);
const getSources = apiUrl => token => getRequest(`${apiUrl}/sources`)(null)(token);
const getSources = apiUrl => token => getRequest(`${apiUrl}/api/sources`)(null)(token);

// eslint-disable-next-line no-unused-vars
const getUsers = apiUrl => token => ({
Expand Down
6 changes: 5 additions & 1 deletion src/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export const FAKE_USERS_LIST = [
"Tarek Tifié",
"Vishnou Lapaix",
"Yvon Tremblay",
].map(funnyName => ({ given_name: funnyName.split(" ")[0], family_name: funnyName.split(" ")[1] }));
].map(funnyName => ({
given_name: funnyName.split(" ")[0],
family_name: funnyName.split(" ")[1],
preferred_username: funnyName,
}));
2 changes: 1 addition & 1 deletion src/core/keycloak/keycloakOidcClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const createKeycloakOidcClient = async ({ url, realm, clientId, evtUserAc
.catch(error => error);

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

Expand Down
6 changes: 3 additions & 3 deletions src/ui/context/UserAccount/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export const UserAccountProvider = ({ children }) => {
} else {
const userLoaded = {
id: id,
name: `${oidcUser?.given_name} ${oidcUser?.family_name}`,
name: `${oidcUser?.preferred_username}`,
sourceAccreditations: dataSourceAcc?.content,
roles: [...(oidcUser["groupe-ag"] || []), dataRole?.role],
canAccess: canAccessToApp(oidcUser["groupe-ag"] || []),
roles: [...(oidcUser["inseegroupedefaut"] || []), dataRole?.role],
canAccess: canAccessToApp(oidcUser["inseegroupedefaut"] || []),
};
setUser(userLoaded);
if (userLoaded.canAccess)
Expand Down
3 changes: 2 additions & 1 deletion src/ui/context/auth/provider/noAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const NoAuthLogin = ({ setOidcClient }) => {
id: id,
given_name: fakeUserName.given_name,
family_name: fakeUserName.family_name,
["groupe-ag"]: [ACCESS_APP_ROLE_ADMIN], // Admin role for noAuth
preferred_username: fakeUserName.preferred_username,
["inseegroupedefaut"]: [ACCESS_APP_ROLE_ADMIN], // Admin role for noAuth
},
logout: () => (window.location.href = "/"),
};
Expand Down

0 comments on commit 54786e1

Please sign in to comment.