aboutsummaryrefslogtreecommitdiffstats
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
parentHomogeneous syntax (diff)
Make it more clear
-rwxr-xr-xpackage.json2
-rw-r--r--src/App/App.tsx17
-rw-r--r--src/App/oidc.tsx9
-rw-r--r--yarn.lock21
4 files changed, 11 insertions, 38 deletions
diff --git a/package.json b/package.json
index 51be40f..49b3ad9 100755
--- a/package.json
+++ b/package.json
@@ -23,7 +23,7 @@
"license": "MIT",
"keywords": [],
"dependencies": {
- "evt": "^2.4.1",
+ "evt": "^2.4.13",
"jwt-decode": "^3.1.2",
"keycloak-js": "^21.0.1",
"keycloakify": "^6.12.1",
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");
diff --git a/yarn.lock b/yarn.lock
index c3f8fcf..19566e3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4314,15 +4314,6 @@ events@^3.2.0:
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
-evt@^2.4.1:
- version "2.4.1"
- resolved "https://registry.yarnpkg.com/evt/-/evt-2.4.1.tgz#68beca2f7bd7eb755fdda5b263a80b934100e046"
- integrity sha512-eo7sZcfDbiVWD5Aw6STkIEMmchYLdeGnJB6tVaM9AXZc7pViin3PmQhb6fgFIFHfl0re9zSEHtSjyu70Y7dRJg==
- dependencies:
- minimal-polyfills "^2.2.2"
- run-exclusive "^2.2.16"
- tsafe "^1.0.1"
-
evt@^2.4.13:
version "2.4.13"
resolved "https://registry.yarnpkg.com/evt/-/evt-2.4.13.tgz#5ef873159ce62e099d58801a3e4b8e0f5b648017"
@@ -7967,13 +7958,6 @@ rollup@^2.43.1:
optionalDependencies:
fsevents "~2.3.2"
-run-exclusive@^2.2.16:
- version "2.2.16"
- resolved "https://registry.yarnpkg.com/run-exclusive/-/run-exclusive-2.2.16.tgz#8fa30a23037760af296c47872a5f6b38f25accf0"
- integrity sha512-cdYv2LDvaBCRnrqXrwDFs1SgzGTx0EIsiEReTpsprEDR6hRUVlSyjoMYu+rez4S1gpz6YbOQxcmYFMXJQknVnQ==
- dependencies:
- minimal-polyfills "^2.2.1"
-
run-exclusive@^2.2.18:
version "2.2.18"
resolved "https://registry.yarnpkg.com/run-exclusive/-/run-exclusive-2.2.18.tgz#ec930edc3a7044750dc827df9372bde8f610f586"
@@ -8713,11 +8697,6 @@ tryer@^1.0.1:
resolved "https://registry.yarnpkg.com/tryer/-/tryer-1.0.1.tgz#f2c85406800b9b0f74c9f7465b81eaad241252f8"
integrity sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==
-tsafe@^1.0.1:
- version "1.0.1"
- resolved "https://registry.yarnpkg.com/tsafe/-/tsafe-1.0.1.tgz#c8c4eb2d75d1478418a4941307c5dd667fd76d23"
- integrity sha512-FgJ1a4rE7YbmW5QIzpsfFl4tsAp0x74FH2bVE6qODb2U8jSrwTr5/ckIazeylme5zXndVbtgKm4BZdqmoGhiPw==
-
tsafe@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/tsafe/-/tsafe-1.4.1.tgz#59cdad8ac41babf88e56dcd1a683ae2fb145d059"