feat(admin-ui): SSO через Keycloak (PKCE, public client)

react-oidc-context + oidc-client-ts. Confidential client тоже работает —
SPA просто не использует client_secret.

- src/auth/oidcConfig.ts — UserManager settings (authority, redirect_uri,
  PKCE, automaticSilentRenew). VITE_KEYCLOAK_{URL,REALM,CLIENT_ID} с дефолтами
  на nstart realm + ordinis client.
- src/auth/TokenSync.tsx — синкает access_token в localStorage и axios default
  header после login/refresh. Existing API код не трогали — interceptor уже
  читает localStorage.
  Bonus: 401 interceptor триггерит signinSilent → signinRedirect fallback.
- src/auth/AuthBadge.tsx — header'ный бейдж: "Войти" если anonymous, имя +
  logout если залогинен.
- main.tsx обёрнут в <AuthProvider>.
- __root.tsx показывает AuthBadge рядом с language switch.
- .env.example с конфигом Keycloak.
- i18n auth.login / auth.logout (RU + EN).

Keycloak client `ordinis` — настроить:
  Valid redirect URIs: https://ordinis.k8s.265.nstart.cloud/*,
                       https://ordinis.k8s.264.nstart.cloud/*,
                       http://localhost:5173/*
  Web Origins: те же + (или "+"), PKCE Code Challenge: S256
This commit is contained in:
Zimin A.N.
2026-05-04 18:28:31 +03:00
parent 2fc9b451e4
commit cef78f9971
9 changed files with 224 additions and 10 deletions
+32
View File
@@ -38,6 +38,9 @@ importers:
i18next-browser-languagedetector:
specifier: ^8.0.2
version: 8.2.1
oidc-client-ts:
specifier: ^3.5.0
version: 3.5.0
react:
specifier: ^19.0.0
version: 19.2.5
@@ -50,6 +53,9 @@ importers:
react-i18next:
specifier: ^17.0.2
version: 17.0.6(i18next@26.0.8(typescript@5.9.3))(react-dom@19.2.5(react@19.2.5))(react@19.2.5)(typescript@5.9.3)
react-oidc-context:
specifier: ^3.3.1
version: 3.3.1(oidc-client-ts@3.5.0)(react@19.2.5)
devDependencies:
'@tailwindcss/vite':
specifier: ^4.0.0-beta.7
@@ -1173,6 +1179,10 @@ packages:
engines: {node: '>=6'}
hasBin: true
jwt-decode@4.0.0:
resolution: {integrity: sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==}
engines: {node: '>=18'}
lightningcss-android-arm64@1.32.0:
resolution: {integrity: sha512-YK7/ClTt4kAK0vo6w3X+Pnm0D2cf2vPHbhOXdoNti1Ga0al1P4TBZhwjATvjNwLEBCnKvjJc2jQgHXH0NEwlAg==}
engines: {node: '>= 12.0.0'}
@@ -1292,6 +1302,10 @@ packages:
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
engines: {node: '>=0.10.0'}
oidc-client-ts@3.5.0:
resolution: {integrity: sha512-l2q8l9CTCTOlbX+AnK4p3M+4CEpKpyQhle6blQkdFhm0IsBqsxm15bYaSa11G7pWdsYr6epdsRZxJpCyCRbT8A==}
engines: {node: '>=18'}
pathe@1.1.2:
resolution: {integrity: sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ==}
@@ -1353,6 +1367,13 @@ packages:
typescript:
optional: true
react-oidc-context@3.3.1:
resolution: {integrity: sha512-/Azvm9W4DhhOtSDBE73kFInh1b6zZRRfILKbgmk2syExMF0PCYJOn/dGdOOi2BFX8x0rCeUe45NXHU+/+xDcrQ==}
engines: {node: '>=18'}
peerDependencies:
oidc-client-ts: ^3.1.0
react: '>=16.14.0'
react-refresh@0.17.0:
resolution: {integrity: sha512-z6F7K9bV85EfseRCp2bzrpyQ0Gkw1uLoCel9XBVWPg/TjRj94SkJzUTGfOa4bs7iJvBWtQG0Wq7wnI0syw3EBQ==}
engines: {node: '>=0.10.0'}
@@ -2526,6 +2547,8 @@ snapshots:
json5@2.2.3: {}
jwt-decode@4.0.0: {}
lightningcss-android-arm64@1.32.0:
optional: true
@@ -2609,6 +2632,10 @@ snapshots:
normalize-path@3.0.0: {}
oidc-client-ts@3.5.0:
dependencies:
jwt-decode: 4.0.0
pathe@1.1.2: {}
pathe@2.0.3: {}
@@ -2651,6 +2678,11 @@ snapshots:
react-dom: 19.2.5(react@19.2.5)
typescript: 5.9.3
react-oidc-context@3.3.1(oidc-client-ts@3.5.0)(react@19.2.5):
dependencies:
oidc-client-ts: 3.5.0
react: 19.2.5
react-refresh@0.17.0: {}
react@19.2.5: {}