2022-09-06 19:22:23 +02:00
|
|
|
import "./App.css";
|
|
|
|
|
import logo from "./logo.svg";
|
|
|
|
|
import myimg from "./myimg.png";
|
2023-03-04 17:58:09 +01:00
|
|
|
import { createOidcClientProvider, useOidcClient } from "./oidc";
|
|
|
|
|
import { addFooToQueryParams, addBarToQueryParams } from "../keycloak-theme/valuesTransferredOverUrl";
|
|
|
|
|
import jwt_decode from "jwt-decode";
|
|
|
|
|
|
|
|
|
|
const { OidcClientProvider } = createOidcClientProvider({
|
|
|
|
|
url: "https://auth.code.gouv.fr/auth",
|
|
|
|
|
realm: "keycloakify",
|
|
|
|
|
clientId: "starter",
|
2023-03-04 20:26:13 +01:00
|
|
|
//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.
|
2023-03-04 17:58:09 +01:00
|
|
|
getUiLocales: () => "en",
|
|
|
|
|
transformUrlBeforeRedirect: url =>
|
|
|
|
|
[url]
|
|
|
|
|
//Instead of foo and bar you could have isDark for example or any other state that you wish to
|
|
|
|
|
//transfer from the main app to the login pages.
|
|
|
|
|
.map(url => addFooToQueryParams({ url, value: { foo: 42 } }))
|
2023-03-04 18:06:49 +01:00
|
|
|
.map(url => addBarToQueryParams({ url, value: "value of bar transferred to login page" }))
|
2023-03-04 17:58:09 +01:00
|
|
|
[0],
|
2023-03-04 20:26:13 +01:00
|
|
|
log: console.log
|
2023-03-04 17:58:09 +01:00
|
|
|
});
|
2022-09-06 19:22:23 +02:00
|
|
|
|
|
|
|
|
export default function App() {
|
2023-03-04 17:58:09 +01:00
|
|
|
return (
|
|
|
|
|
<OidcClientProvider>
|
|
|
|
|
<ContextualizedApp />
|
|
|
|
|
</OidcClientProvider>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ContextualizedApp() {
|
|
|
|
|
|
|
|
|
|
const { oidcClient } = useOidcClient();
|
|
|
|
|
|
2022-09-06 19:22:23 +02:00
|
|
|
return (
|
|
|
|
|
<div className="App">
|
|
|
|
|
<header className="App-header">
|
2023-03-04 17:58:09 +01:00
|
|
|
{
|
|
|
|
|
oidcClient.isUserLoggedIn ?
|
|
|
|
|
<>
|
2023-03-04 20:26:13 +01:00
|
|
|
<h1>You are authenticated !</h1>
|
2023-03-04 17:58:09 +01:00
|
|
|
<pre>{JSON.stringify(jwt_decode(oidcClient.accessToken))}</pre>
|
|
|
|
|
<button onClick={() => oidcClient.logout({ redirectTo: "home" })}>Logout</button>
|
|
|
|
|
</>
|
|
|
|
|
:
|
|
|
|
|
<>
|
|
|
|
|
<button onClick={() => oidcClient.login({ doesCurrentHrefRequiresAuth: false })}>Login</button>
|
|
|
|
|
</>
|
|
|
|
|
}
|
2022-09-06 19:22:23 +02:00
|
|
|
<img src={logo} className="App-logo" alt="logo" />
|
|
|
|
|
<img src={myimg} alt="test_image" />
|
|
|
|
|
<p style={{ "fontFamily": '"Work Sans"' }}>Hello world</p>
|
|
|
|
|
</header>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|