diff options
| author | 2023-04-20 04:41:29 +0200 | |
|---|---|---|
| committer | 2023-04-20 04:41:29 +0200 | |
| commit | a4276bfd68b6fa226b8a1175cbda785a0d23362b (patch) | |
| tree | 1f2a8d453e99fe07c910a96c9fa376e0ba395f30 /src | |
| parent | Update README.md (diff) | |
Update Keycloakify and setup referrerURI for account
Diffstat (limited to 'src')
| -rw-r--r-- | src/App/App.tsx | 29 |
1 files changed, 27 insertions, 2 deletions
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 ( <div className="App"> <header className="App-header"> @@ -48,7 +73,7 @@ function ContextualizedApp() { <> <h1>You are authenticated !</h1> {/* On older Keycloak version its /auth/realms instead of /realms */} - <a href={`${keycloakUrl}/realms/${keycloakRealm}/account`} target="_blank" rel="noreferrer">Link to your Keycloak account</a> + <a href={accountUrl} target="_blank" rel="noreferrer">Link to your Keycloak account</a> <pre style={{ textAlign: "left" }}>{JSON.stringify(jwt_decode(oidcClient.getAccessToken()), null, 2)}</pre> <button onClick={() => oidcClient.logout({ redirectTo: "home" })}>Logout</button> </> |