Update to oidc-spa v4

This commit is contained in:
Joseph Garrone 2024-01-25 03:53:41 +01:00
parent b0ea463f50
commit 237908d207
3 changed files with 9 additions and 12 deletions

View File

@ -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",

View File

@ -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.

View File

@ -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"