aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar garronej <[email protected]>2023-03-04 20:26:13 +0100
committerGravatar garronej <[email protected]>2023-03-04 20:26:13 +0100
commit598f164112ba622bfabb11baa137014b88df1507 (patch)
tree88e71fa258bb9c1bd7f765b72e0b904d5c6ae1b6 /src
parentHomogeneous syntax (diff)
Make it more clear
Diffstat (limited to 'src')
-rw-r--r--src/App/App.tsx17
-rw-r--r--src/App/oidc.tsx9
2 files changed, 10 insertions, 16 deletions
diff --git a/src/App/App.tsx b/src/App/App.tsx
index 2ea3624..1cfbeac 100644
--- a/src/App/App.tsx
+++ b/src/App/App.tsx
@@ -3,16 +3,15 @@ import logo from "./logo.svg";
import myimg from "./myimg.png";
import { createOidcClientProvider, useOidcClient } from "./oidc";
import { addFooToQueryParams, addBarToQueryParams } from "../keycloak-theme/valuesTransferredOverUrl";
-import { Evt } from "evt";
-import { id } from "tsafe/id";
import jwt_decode from "jwt-decode";
const { OidcClientProvider } = createOidcClientProvider({
url: "https://auth.code.gouv.fr/auth",
realm: "keycloakify",
clientId: "starter",
- log: console.log,
- //The login pages will be in english.
+ //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.
getUiLocales: () => "en",
transformUrlBeforeRedirect: url =>
[url]
@@ -21,13 +20,7 @@ const { OidcClientProvider } = createOidcClientProvider({
.map(url => addFooToQueryParams({ url, value: { foo: 42 } }))
.map(url => addBarToQueryParams({ url, value: "value of bar transferred to login page" }))
[0],
- // An event emitter that posts whenever the user interacts with the app
- // This is to tell if we should allow the token to expires.
- evtUserActivity:
- Evt.merge([
- Evt.from(document, "mousemove"),
- Evt.from(document, "keydown")
- ]).pipe(() => [id<void>(undefined)]),
+ log: console.log
});
export default function App() {
@@ -49,7 +42,7 @@ function ContextualizedApp() {
{
oidcClient.isUserLoggedIn ?
<>
- <h1>You are authenticated</h1>
+ <h1>You are authenticated !</h1>
<pre>{JSON.stringify(jwt_decode(oidcClient.accessToken))}</pre>
<button onClick={() => oidcClient.logout({ redirectTo: "home" })}>Logout</button>
</>
diff --git a/src/App/oidc.tsx b/src/App/oidc.tsx
index 991dfae..832a80f 100644
--- a/src/App/oidc.tsx
+++ b/src/App/oidc.tsx
@@ -6,8 +6,8 @@ import type { ReturnType } from "tsafe/ReturnType";
import type { Param0 } from "tsafe/Param0";
import { assert } from "tsafe/assert";
import { createKeycloakAdapter } from "keycloakify";
-import type { NonPostableEvt } from "evt";
import jwt_decode from "jwt-decode";
+import { Evt } from "evt";
export declare type OidcClient = OidcClient.LoggedIn | OidcClient.NotLoggedIn;
@@ -34,7 +34,6 @@ type Params = {
realm: string;
clientId: string;
transformUrlBeforeRedirect: (url: string) => string;
- evtUserActivity: NonPostableEvt<void>;
getUiLocales: () => string;
log?: typeof console.log;
};
@@ -45,7 +44,6 @@ async function createKeycloakOidcClient(params: Params): Promise<OidcClient> {
realm,
clientId,
transformUrlBeforeRedirect,
- evtUserActivity,
getUiLocales,
log
} = params;
@@ -135,7 +133,10 @@ async function createKeycloakOidcClient(params: Params): Promise<OidcClient> {
`OIDC access token will expire in ${minValiditySecond} seconds, waiting for user activity before renewing`
);
- await evtUserActivity.waitFor();
+ await Evt.merge([
+ Evt.from(document, "mousemove"),
+ Evt.from(document, "keydown")
+ ]).waitFor();
log?.("User activity detected. Refreshing access token now");