From 237908d2075ab469900a96101321778effea7953 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Thu, 25 Jan 2024 03:53:41 +0100 Subject: [PATCH] Update to oidc-spa v4 --- package.json | 2 +- src/App/oidc.ts | 11 ++++------- yarn.lock | 8 ++++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 2565322..0c79c74 100755 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "keywords": [], "dependencies": { "evt": "^2.5.7", - "oidc-spa": "^3.0.3", + "oidc-spa": "^4.0.0", "keycloakify": "^9.1.9", "powerhooks": "^1.0.8", "react": "18.1.0", diff --git a/src/App/oidc.ts b/src/App/oidc.ts index ca9d863..97cb66b 100644 --- a/src/App/oidc.ts +++ b/src/App/oidc.ts @@ -1,7 +1,7 @@ // See documentation of oidc-spa for more details: // https://docs.oidc-spa.dev -import { createOidcProvider, createUseOidc } from "oidc-spa/react"; +import { createReactOidc } from "oidc-spa/react"; import { z } from "zod"; //On older Keycloak version you need the /auth (e.g: http://localhost:8080/auth) @@ -10,11 +10,11 @@ const keycloakUrl = "https://auth.code.gouv.fr/auth"; const keycloakRealm = "keycloakify"; const keycloakClientId= "starter"; -export const { OidcProvider } = createOidcProvider({ +export const { OidcProvider, useOidc } = createReactOidc({ issuerUri: `${keycloakUrl}/realms/${keycloakRealm}`, clientId: keycloakClientId, // NOTE: You can also pass queries params when calling login() - getExtraQueryParams: () => ({ + extraQueryParams: () => ({ // This adding ui_locales to the url will ensure the consistency of the language between the app and the login pages // If your app implements a i18n system (like i18nifty.dev for example) you should use this and replace "en" by the // current language of the app. @@ -22,10 +22,7 @@ export const { OidcProvider } = createOidcProvider({ "ui_locales": "en", "my_custom_param": "value of foo transferred to login page" }), - publicUrl: process.env.PUBLIC_URL -}); - -export const { useOidc } = createUseOidc({ + publicUrl: process.env.PUBLIC_URL, decodedIdTokenSchema: z.object({ // Use https://jwt.io/ to tell what's in your idToken // It will depend of your Keycloak configuration. diff --git a/yarn.lock b/yarn.lock index d614869..ebc7709 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10931,10 +10931,10 @@ oidc-client-ts@^2.3.0: crypto-js "^4.1.1" jwt-decode "^3.1.2" -oidc-spa@^3.0.3: - version "3.0.3" - resolved "https://registry.yarnpkg.com/oidc-spa/-/oidc-spa-3.0.3.tgz#01e524064e91615e3f2c6d6c906234fc13351787" - integrity sha512-yoAQHaTPw0Eb3AYLQ1ODuCfO0iboUv3agnz45QSm0LWG9o6+9mtN6g71XljrSIPR/G5g4rLria4Ke+Rq/LoJZg== +oidc-spa@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/oidc-spa/-/oidc-spa-4.0.0.tgz#7cec1683686cd6f2b9c85547107b19b6b54ffd39" + integrity sha512-Zy386BfS/LbkUopNTA1xFCWYIMc7fFrQ1Iyc58vt+2dAezTAt15F6YTrYGXGCa4P0q8SpO6Avu8/OmHyO67d9w== dependencies: jwt-decode "^3.1.2" oidc-client-ts "^2.3.0"