diff --git a/package.json b/package.json index b42fba8..7f61826 100755 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ "evt": "^2.4.15", "jwt-decode": "^3.1.2", "keycloak-js": "^21.0.1", - "keycloakify": "7.9.0-rc.0", - "powerhooks": "^0.26.7", + "keycloakify": "^7.9.2", + "powerhooks": "^0.26.8", "react": "18.1.0", "react-dom": "18.1.0", "tsafe": "^1.6.0" diff --git a/src/App/App.tsx b/src/App/App.tsx index 4f3cccb..fd1bc9a 100644 --- a/src/App/App.tsx +++ b/src/App/App.tsx @@ -4,16 +4,18 @@ import myimg from "./myimg.png"; import { createOidcClientProvider, useOidcClient } from "./oidc"; import { addFooToQueryParams, addBarToQueryParams } from "../keycloak-theme/login/valuesTransferredOverUrl"; import jwt_decode from "jwt-decode"; +import { addParamToUrl } from "powerhooks/tools/urlSearchParams"; //On older Keycloak version you need the /auth (e.g: http://localhost:8080/auth) //On newer version you must remove it (e.g: http://localhost:8080 ) const keycloakUrl = "https://auth.code.gouv.fr/auth"; const keycloakRealm = "keycloakify"; +const keycloakClient= "starter"; const { OidcClientProvider } = createOidcClientProvider({ url: keycloakUrl, realm: keycloakRealm, - clientId: "starter", + clientId: keycloakClient, //This function will be called just before redirecting, //it should return the current langue. //kcContext.locale.currentLanguageTag will be what this function returned just before redirecting. @@ -40,6 +42,29 @@ function ContextualizedApp() { const { oidcClient } = useOidcClient(); + let accountUrl = `${keycloakUrl}/realms/${keycloakRealm}/account`; + + // Set the language the user will get on the account page + accountUrl = addParamToUrl({ + "url": accountUrl, + "name": "kc_locale", + "value": "en" + }).newUrl; + + // Enable to redirect to the app from the account page we'll get the referrer_uri under kcContext.url.referrerUri + // see: https://technology.first8.nl/add-manage-account-link-keycloak-redhat-sso/ + accountUrl = addParamToUrl({ + "url": accountUrl, + "name": "referrer", + "value": keycloakClient + }).newUrl; + + accountUrl = addParamToUrl({ + "url": accountUrl, + "name": "referrer_uri", + "value": window.location.href + }).newUrl; + return (
{JSON.stringify(jwt_decode(oidcClient.getAccessToken()), null, 2)}>