Make it more clear

This commit is contained in:
garronej committed 2023-03-04 20:26:13 +01:00
1 parent 00059fbb80
commit 598f164112
4 files changed
+11 -38

No files matched your search

+1 -1
View File
@@ -23,7 +23,7 @@
"license": "MIT", "license": "MIT",
"keywords": [], "keywords": [],
"dependencies": { "dependencies": {
"evt": "^2.4.1", "evt": "^2.4.13",
"jwt-decode": "^3.1.2", "jwt-decode": "^3.1.2",
"keycloak-js": "^21.0.1", "keycloak-js": "^21.0.1",
"keycloakify": "^6.12.1", "keycloakify": "^6.12.1",
+5 -12
View File
@@ -3,16 +3,15 @@ import logo from "./logo.svg";
import myimg from "./myimg.png"; import myimg from "./myimg.png";
import { createOidcClientProvider, useOidcClient } from "./oidc"; import { createOidcClientProvider, useOidcClient } from "./oidc";
import { addFooToQueryParams, addBarToQueryParams } from "../keycloak-theme/valuesTransferredOverUrl"; import { addFooToQueryParams, addBarToQueryParams } from "../keycloak-theme/valuesTransferredOverUrl";
import { Evt } from "evt";
import { id } from "tsafe/id";
import jwt_decode from "jwt-decode"; import jwt_decode from "jwt-decode";
const { OidcClientProvider } = createOidcClientProvider({ const { OidcClientProvider } = createOidcClientProvider({
url: "https://auth.code.gouv.fr/auth", url: "https://auth.code.gouv.fr/auth",
realm: "keycloakify", realm: "keycloakify",
clientId: "starter", clientId: "starter",
log: console.log, //This function will be called just before redirecting,
//The login pages will be in english. //it should return the current langue.
//kcContext.locale.currentLanguageTag will be what this function returned just before redirecting.
getUiLocales: () => "en", getUiLocales: () => "en",
transformUrlBeforeRedirect: url => transformUrlBeforeRedirect: url =>
[url] [url]
@@ -21,13 +20,7 @@ const { OidcClientProvider } = createOidcClientProvider({
.map(url => addFooToQueryParams({ url, value: { foo: 42 } })) .map(url => addFooToQueryParams({ url, value: { foo: 42 } }))
.map(url => addBarToQueryParams({ url, value: "value of bar transferred to login page" })) .map(url => addBarToQueryParams({ url, value: "value of bar transferred to login page" }))
[0], [0],
// An event emitter that posts whenever the user interacts with the app log: console.log
// 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)]),
}); });
export default function App() { export default function App() {
@@ -49,7 +42,7 @@ function ContextualizedApp() {
{ {
oidcClient.isUserLoggedIn ? oidcClient.isUserLoggedIn ?
<> <>
<h1>You are authenticated</h1> <h1>You are authenticated !</h1>
<pre>{JSON.stringify(jwt_decode(oidcClient.accessToken))}</pre> <pre>{JSON.stringify(jwt_decode(oidcClient.accessToken))}</pre>
<button onClick={() => oidcClient.logout({ redirectTo: "home" })}>Logout</button> <button onClick={() => oidcClient.logout({ redirectTo: "home" })}>Logout</button>
</> </>
+5 -4
View File
@@ -6,8 +6,8 @@ import type { ReturnType } from "tsafe/ReturnType";
import type { Param0 } from "tsafe/Param0"; import type { Param0 } from "tsafe/Param0";
import { assert } from "tsafe/assert"; import { assert } from "tsafe/assert";
import { createKeycloakAdapter } from "keycloakify"; import { createKeycloakAdapter } from "keycloakify";
import type { NonPostableEvt } from "evt";
import jwt_decode from "jwt-decode"; import jwt_decode from "jwt-decode";
import { Evt } from "evt";
export declare type OidcClient = OidcClient.LoggedIn | OidcClient.NotLoggedIn; export declare type OidcClient = OidcClient.LoggedIn | OidcClient.NotLoggedIn;
@@ -34,7 +34,6 @@ type Params = {
realm: string; realm: string;
clientId: string; clientId: string;
transformUrlBeforeRedirect: (url: string) => string; transformUrlBeforeRedirect: (url: string) => string;
evtUserActivity: NonPostableEvt<void>;
getUiLocales: () => string; getUiLocales: () => string;
log?: typeof console.log; log?: typeof console.log;
}; };
@@ -45,7 +44,6 @@ async function createKeycloakOidcClient(params: Params): Promise<OidcClient> {
realm, realm,
clientId, clientId,
transformUrlBeforeRedirect, transformUrlBeforeRedirect,
evtUserActivity,
getUiLocales, getUiLocales,
log log
} = params; } = 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` `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"); log?.("User activity detected. Refreshing access token now");
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff. Show more