antaeus.keycloak.react 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -0
- package/dist/index.d.mts +108 -23
- package/dist/index.d.ts +108 -23
- package/dist/index.js +253 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +250 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,6 +115,28 @@ function MyComponent() {
|
|
|
115
115
|
</KeycloakProvider>
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
+
### 5. Optional / Disabled Mode
|
|
119
|
+
|
|
120
|
+
Wrap legacy paths or feature flags without tearing out the provider:
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
<KeycloakProvider
|
|
124
|
+
authority={import.meta.env.VITE_KEYCLOAK_AUTHORITY ?? ''}
|
|
125
|
+
clientId={import.meta.env.VITE_KEYCLOAK_CLIENT_ID ?? ''}
|
|
126
|
+
enabled={Boolean(import.meta.env.VITE_KEYCLOAK_AUTHORITY)}
|
|
127
|
+
>
|
|
128
|
+
<App />
|
|
129
|
+
</KeycloakProvider>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
When disabled (or missing authority/clientId), the provider exposes a safe stub context—`useAuth()` still works, but no network calls are made. Inspect the state anywhere via:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
import { useKeycloakStatus } from 'antaeus.keycloak.react';
|
|
136
|
+
|
|
137
|
+
const { isEnabled, isConfigured, reason } = useKeycloakStatus();
|
|
138
|
+
```
|
|
139
|
+
|
|
118
140
|
## Configuration Presets
|
|
119
141
|
|
|
120
142
|
| Preset | Session Lifetime | Best For |
|
|
@@ -144,6 +166,61 @@ auth.signinRedirect()
|
|
|
144
166
|
auth.signoutRedirect()
|
|
145
167
|
```
|
|
146
168
|
|
|
169
|
+
## Token Bridge (Non-React Consumers)
|
|
170
|
+
|
|
171
|
+
Expose tokens to plain TypeScript modules (SignalR, fetch helpers, etc.):
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
import {
|
|
175
|
+
KeycloakProvider,
|
|
176
|
+
TokenBridgeSync,
|
|
177
|
+
createTokenBridge,
|
|
178
|
+
} from 'antaeus.keycloak.react';
|
|
179
|
+
|
|
180
|
+
export const tokenBridge = createTokenBridge();
|
|
181
|
+
|
|
182
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
183
|
+
<KeycloakProvider authority="..." clientId="..." tokenBridge={tokenBridge}>
|
|
184
|
+
<TokenBridgeSync bridge={tokenBridge} />
|
|
185
|
+
<App />
|
|
186
|
+
</KeycloakProvider>
|
|
187
|
+
);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Then outside React:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { tokenBridge } from './main';
|
|
194
|
+
|
|
195
|
+
tokenBridge.subscribe((token) => {
|
|
196
|
+
console.log('Token changed:', token);
|
|
197
|
+
});
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Prefer a shared singleton? Use the default bridge:
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
import {
|
|
204
|
+
KeycloakProvider,
|
|
205
|
+
TokenBridgeSync,
|
|
206
|
+
defaultTokenBridge,
|
|
207
|
+
} from 'antaeus.keycloak.react';
|
|
208
|
+
|
|
209
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
210
|
+
<KeycloakProvider authority="..." clientId="..." tokenBridge={defaultTokenBridge}>
|
|
211
|
+
<TokenBridgeSync />
|
|
212
|
+
<App />
|
|
213
|
+
</KeycloakProvider>
|
|
214
|
+
);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
```ts
|
|
218
|
+
// signalr.ts
|
|
219
|
+
import { defaultTokenBridge } from 'antaeus.keycloak.react';
|
|
220
|
+
|
|
221
|
+
const bearer = defaultTokenBridge.getToken();
|
|
222
|
+
```
|
|
223
|
+
|
|
147
224
|
### useProtectedFetch()
|
|
148
225
|
|
|
149
226
|
```tsx
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
2
3
|
import { User, UserManagerSettings } from 'oidc-client-ts';
|
|
3
4
|
export { User } from 'oidc-client-ts';
|
|
4
5
|
import { useLocation } from 'react-router-dom';
|
|
@@ -223,6 +224,40 @@ declare function getConfigPreset(preset: ConfigPreset): Partial<KeycloakConfig>;
|
|
|
223
224
|
*/
|
|
224
225
|
declare function mergeWithPreset(preset: ConfigPreset, customConfig: Partial<KeycloakConfig>): Partial<KeycloakConfig>;
|
|
225
226
|
|
|
227
|
+
type TokenListener = (token: string | null) => void;
|
|
228
|
+
/**
|
|
229
|
+
* Minimal bridge to expose the current Keycloak access token outside React.
|
|
230
|
+
* Consumers can subscribe to token changes or fetch the latest value on demand.
|
|
231
|
+
*/
|
|
232
|
+
declare class TokenBridge {
|
|
233
|
+
private currentToken;
|
|
234
|
+
private listeners;
|
|
235
|
+
/**
|
|
236
|
+
* Update the tracked token and notify subscribers when it changes.
|
|
237
|
+
*/
|
|
238
|
+
setToken(token: string | null): void;
|
|
239
|
+
/**
|
|
240
|
+
* Read the most recent token value.
|
|
241
|
+
*/
|
|
242
|
+
getToken(): string | null;
|
|
243
|
+
/**
|
|
244
|
+
* Convenience helper for async callers.
|
|
245
|
+
*/
|
|
246
|
+
getTokenAsync(): Promise<string | null>;
|
|
247
|
+
/**
|
|
248
|
+
* Subscribe to token changes. Returns an unsubscribe callback.
|
|
249
|
+
*/
|
|
250
|
+
subscribe(listener: TokenListener): () => void;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Factory helper to create an isolated token bridge.
|
|
254
|
+
*/
|
|
255
|
+
declare const createTokenBridge: () => TokenBridge;
|
|
256
|
+
/**
|
|
257
|
+
* Default shared bridge for simple scenarios.
|
|
258
|
+
*/
|
|
259
|
+
declare const defaultTokenBridge: TokenBridge;
|
|
260
|
+
|
|
226
261
|
/**
|
|
227
262
|
* Props for zero-config mode (simplified setup)
|
|
228
263
|
*/
|
|
@@ -240,10 +275,16 @@ interface KeycloakProviderZeroConfigProps {
|
|
|
240
275
|
* @default 'default'
|
|
241
276
|
*/
|
|
242
277
|
preset?: ConfigPreset;
|
|
278
|
+
/**
|
|
279
|
+
* Toggle to disable Keycloak integration entirely.
|
|
280
|
+
* When false, children render with a stub auth context.
|
|
281
|
+
* @default true
|
|
282
|
+
*/
|
|
283
|
+
enabled?: boolean;
|
|
243
284
|
/**
|
|
244
285
|
* Child components to render
|
|
245
286
|
*/
|
|
246
|
-
children:
|
|
287
|
+
children: React__default.ReactNode;
|
|
247
288
|
/**
|
|
248
289
|
* Enable debug logging to console
|
|
249
290
|
* @default false
|
|
@@ -254,6 +295,10 @@ interface KeycloakProviderZeroConfigProps {
|
|
|
254
295
|
* Use this to customize preset or zero-config defaults
|
|
255
296
|
*/
|
|
256
297
|
config?: Partial<Omit<KeycloakConfig, 'authority' | 'clientId'>>;
|
|
298
|
+
/**
|
|
299
|
+
* Optional token bridge instance for exposing tokens outside React.
|
|
300
|
+
*/
|
|
301
|
+
tokenBridge?: TokenBridge;
|
|
257
302
|
}
|
|
258
303
|
/**
|
|
259
304
|
* Props for full-config mode (advanced setup)
|
|
@@ -263,15 +308,25 @@ interface KeycloakProviderFullConfigProps {
|
|
|
263
308
|
* Full Keycloak configuration object
|
|
264
309
|
*/
|
|
265
310
|
config: KeycloakConfig;
|
|
311
|
+
/**
|
|
312
|
+
* Toggle to disable Keycloak integration entirely.
|
|
313
|
+
* When false, children render with a stub auth context.
|
|
314
|
+
* @default true
|
|
315
|
+
*/
|
|
316
|
+
enabled?: boolean;
|
|
266
317
|
/**
|
|
267
318
|
* Child components to render
|
|
268
319
|
*/
|
|
269
|
-
children:
|
|
320
|
+
children: React__default.ReactNode;
|
|
270
321
|
/**
|
|
271
322
|
* Enable debug logging to console
|
|
272
323
|
* @default false
|
|
273
324
|
*/
|
|
274
325
|
debug?: boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Optional token bridge instance for exposing tokens outside React.
|
|
328
|
+
*/
|
|
329
|
+
tokenBridge?: TokenBridge;
|
|
275
330
|
}
|
|
276
331
|
/**
|
|
277
332
|
* Combined props type
|
|
@@ -396,7 +451,7 @@ type KeycloakProviderProps = KeycloakProviderZeroConfigProps | KeycloakProviderF
|
|
|
396
451
|
*
|
|
397
452
|
* All features can be disabled or customized via configuration overrides.
|
|
398
453
|
*/
|
|
399
|
-
declare const KeycloakProvider:
|
|
454
|
+
declare const KeycloakProvider: React__default.FC<KeycloakProviderProps>;
|
|
400
455
|
|
|
401
456
|
/**
|
|
402
457
|
* Context object passed to custom policy function
|
|
@@ -419,7 +474,7 @@ interface ProtectedRouteProps {
|
|
|
419
474
|
/**
|
|
420
475
|
* Child components to render when user is authorized
|
|
421
476
|
*/
|
|
422
|
-
children:
|
|
477
|
+
children: React__default.ReactNode;
|
|
423
478
|
/**
|
|
424
479
|
* Required realm roles (OR logic - user needs at least one)
|
|
425
480
|
*/
|
|
@@ -446,11 +501,11 @@ interface ProtectedRouteProps {
|
|
|
446
501
|
/**
|
|
447
502
|
* Custom loading component to display while checking authentication
|
|
448
503
|
*/
|
|
449
|
-
loadingComponent?:
|
|
504
|
+
loadingComponent?: React__default.ReactNode;
|
|
450
505
|
/**
|
|
451
506
|
* Custom unauthorized component to display when user lacks required permissions
|
|
452
507
|
*/
|
|
453
|
-
unauthorizedComponent?:
|
|
508
|
+
unauthorizedComponent?: React__default.ReactNode;
|
|
454
509
|
/**
|
|
455
510
|
* Path to redirect to if not authenticated
|
|
456
511
|
* @default '/login'
|
|
@@ -577,14 +632,14 @@ interface ProtectedRouteProps {
|
|
|
577
632
|
* </ProtectedRoute>
|
|
578
633
|
* ```
|
|
579
634
|
*/
|
|
580
|
-
declare const ProtectedRoute:
|
|
635
|
+
declare const ProtectedRoute: React__default.FC<ProtectedRouteProps>;
|
|
581
636
|
|
|
582
637
|
interface LoginButtonProps {
|
|
583
638
|
/**
|
|
584
639
|
* Button text
|
|
585
640
|
* @default 'Login'
|
|
586
641
|
*/
|
|
587
|
-
children?:
|
|
642
|
+
children?: React__default.ReactNode;
|
|
588
643
|
/**
|
|
589
644
|
* Additional CSS class names
|
|
590
645
|
*/
|
|
@@ -611,7 +666,7 @@ interface LoginButtonProps {
|
|
|
611
666
|
/**
|
|
612
667
|
* Custom inline styles
|
|
613
668
|
*/
|
|
614
|
-
style?:
|
|
669
|
+
style?: React__default.CSSProperties;
|
|
615
670
|
/**
|
|
616
671
|
* Disable the button
|
|
617
672
|
*/
|
|
@@ -651,14 +706,14 @@ interface LoginButtonProps {
|
|
|
651
706
|
* />
|
|
652
707
|
* ```
|
|
653
708
|
*/
|
|
654
|
-
declare const LoginButton:
|
|
709
|
+
declare const LoginButton: React__default.FC<LoginButtonProps>;
|
|
655
710
|
|
|
656
711
|
interface LogoutButtonProps {
|
|
657
712
|
/**
|
|
658
713
|
* Button text
|
|
659
714
|
* @default 'Logout'
|
|
660
715
|
*/
|
|
661
|
-
children?:
|
|
716
|
+
children?: React__default.ReactNode;
|
|
662
717
|
/**
|
|
663
718
|
* Additional CSS class names
|
|
664
719
|
*/
|
|
@@ -685,7 +740,7 @@ interface LogoutButtonProps {
|
|
|
685
740
|
/**
|
|
686
741
|
* Custom inline styles
|
|
687
742
|
*/
|
|
688
|
-
style?:
|
|
743
|
+
style?: React__default.CSSProperties;
|
|
689
744
|
/**
|
|
690
745
|
* Disable the button
|
|
691
746
|
*/
|
|
@@ -728,7 +783,7 @@ interface LogoutButtonProps {
|
|
|
728
783
|
* />
|
|
729
784
|
* ```
|
|
730
785
|
*/
|
|
731
|
-
declare const LogoutButton:
|
|
786
|
+
declare const LogoutButton: React__default.FC<LogoutButtonProps>;
|
|
732
787
|
|
|
733
788
|
interface UserProfileProps {
|
|
734
789
|
/**
|
|
@@ -758,7 +813,7 @@ interface UserProfileProps {
|
|
|
758
813
|
/**
|
|
759
814
|
* Custom inline styles
|
|
760
815
|
*/
|
|
761
|
-
style?:
|
|
816
|
+
style?: React__default.CSSProperties;
|
|
762
817
|
/**
|
|
763
818
|
* Callback when profile is clicked
|
|
764
819
|
*/
|
|
@@ -802,7 +857,7 @@ interface UserProfileProps {
|
|
|
802
857
|
* />
|
|
803
858
|
* ```
|
|
804
859
|
*/
|
|
805
|
-
declare const UserProfile:
|
|
860
|
+
declare const UserProfile: React__default.FC<UserProfileProps>;
|
|
806
861
|
|
|
807
862
|
interface SessionMonitorProps {
|
|
808
863
|
/**
|
|
@@ -854,7 +909,7 @@ interface SessionMonitorProps {
|
|
|
854
909
|
/**
|
|
855
910
|
* Custom inline styles
|
|
856
911
|
*/
|
|
857
|
-
style?:
|
|
912
|
+
style?: React__default.CSSProperties;
|
|
858
913
|
}
|
|
859
914
|
/**
|
|
860
915
|
* Session monitoring component with countdown timer
|
|
@@ -897,7 +952,7 @@ interface SessionMonitorProps {
|
|
|
897
952
|
* />
|
|
898
953
|
* ```
|
|
899
954
|
*/
|
|
900
|
-
declare const SessionMonitor:
|
|
955
|
+
declare const SessionMonitor: React__default.FC<SessionMonitorProps>;
|
|
901
956
|
|
|
902
957
|
interface DeviceLoginProps {
|
|
903
958
|
/**
|
|
@@ -930,7 +985,7 @@ interface DeviceLoginProps {
|
|
|
930
985
|
/**
|
|
931
986
|
* Custom inline styles
|
|
932
987
|
*/
|
|
933
|
-
style?:
|
|
988
|
+
style?: React__default.CSSProperties;
|
|
934
989
|
}
|
|
935
990
|
/**
|
|
936
991
|
* Device flow login component
|
|
@@ -965,7 +1020,7 @@ interface DeviceLoginProps {
|
|
|
965
1020
|
* />
|
|
966
1021
|
* ```
|
|
967
1022
|
*/
|
|
968
|
-
declare const DeviceLogin:
|
|
1023
|
+
declare const DeviceLogin: React__default.FC<DeviceLoginProps>;
|
|
969
1024
|
|
|
970
1025
|
interface TokenLifecycleManagerProps {
|
|
971
1026
|
/**
|
|
@@ -975,7 +1030,7 @@ interface TokenLifecycleManagerProps {
|
|
|
975
1030
|
/**
|
|
976
1031
|
* Child components to render
|
|
977
1032
|
*/
|
|
978
|
-
children:
|
|
1033
|
+
children: React__default.ReactNode;
|
|
979
1034
|
/**
|
|
980
1035
|
* Enable debug logging
|
|
981
1036
|
* @default false
|
|
@@ -997,7 +1052,19 @@ interface TokenLifecycleManagerProps {
|
|
|
997
1052
|
* </TokenLifecycleManager>
|
|
998
1053
|
* ```
|
|
999
1054
|
*/
|
|
1000
|
-
declare const TokenLifecycleManager:
|
|
1055
|
+
declare const TokenLifecycleManager: React__default.FC<TokenLifecycleManagerProps>;
|
|
1056
|
+
|
|
1057
|
+
interface TokenBridgeProps {
|
|
1058
|
+
/**
|
|
1059
|
+
* Optional custom bridge instance. Defaults to the shared global bridge.
|
|
1060
|
+
*/
|
|
1061
|
+
bridge?: TokenBridge;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Synchronises the current Keycloak access token into an imperative TokenBridge.
|
|
1065
|
+
* Place this component inside your application tree (after KeycloakProvider).
|
|
1066
|
+
*/
|
|
1067
|
+
declare const TokenBridgeSync: React.FC<TokenBridgeProps>;
|
|
1001
1068
|
|
|
1002
1069
|
/**
|
|
1003
1070
|
* Main authentication hook for accessing Keycloak authentication state and methods
|
|
@@ -1406,6 +1473,24 @@ declare class KeycloakConfigBuilder {
|
|
|
1406
1473
|
*/
|
|
1407
1474
|
declare function getConfigFromEnv(): Partial<KeycloakConfig>;
|
|
1408
1475
|
|
|
1476
|
+
type KeycloakDisabledReason = 'disabled' | 'missing-config';
|
|
1477
|
+
interface KeycloakStatus {
|
|
1478
|
+
/**
|
|
1479
|
+
* Whether the Keycloak integration is enabled by configuration.
|
|
1480
|
+
*/
|
|
1481
|
+
isEnabled: boolean;
|
|
1482
|
+
/**
|
|
1483
|
+
* Whether the minimum configuration (authority + clientId) is present.
|
|
1484
|
+
*/
|
|
1485
|
+
isConfigured: boolean;
|
|
1486
|
+
/**
|
|
1487
|
+
* Provides additional context when integration is disabled.
|
|
1488
|
+
*/
|
|
1489
|
+
reason?: KeycloakDisabledReason;
|
|
1490
|
+
}
|
|
1491
|
+
declare const KeycloakStatusProvider: React$1.Provider<KeycloakStatus>;
|
|
1492
|
+
declare const useKeycloakStatus: () => KeycloakStatus;
|
|
1493
|
+
|
|
1409
1494
|
/**
|
|
1410
1495
|
* Device authorization response from Keycloak
|
|
1411
1496
|
*/
|
|
@@ -1517,4 +1602,4 @@ declare function pollForToken(apiBaseUrl: string, deviceCode: string): Promise<T
|
|
|
1517
1602
|
*/
|
|
1518
1603
|
declare function fetchUserInfo(apiBaseUrl: string, accessToken: string): Promise<any>;
|
|
1519
1604
|
|
|
1520
|
-
export { type AdvancedOidcOptions, CONFIG_PRESETS, type ConfigPreset, type DeviceAuthorizationResponse, type DeviceFlowError, DeviceLogin, type DeviceLoginProps, type EventCallbacks, type FeatureFlags, type KeycloakConfig, KeycloakConfigBuilder, KeycloakProvider, type KeycloakProviderFullConfigProps, type KeycloakProviderProps, type KeycloakProviderZeroConfigProps, LoginButton, type LoginButtonProps, LogoutButton, type LogoutButtonProps, type PolicyContext, type PolicyFunction, ProtectedRoute, type ProtectedRouteProps, SessionMonitor, type SessionMonitorProps, type SilentRenewConfig, TokenLifecycleManager, type TokenLifecycleManagerProps, type TokenResponse, type UseProtectedFetchOptions, type UseProtectedFetchReturn, type UseRolesReturn, type UseScopesReturn, type UseTokenLifecycleOptions, type UseTokenLifecycleReturn, UserProfile, type UserProfileProps, defaultConfig, fetchUserInfo, getConfigFromEnv, getConfigPreset, mergeWithPreset, pollForToken, requestDeviceCode, useAuth, useProtectedFetch, useRoles, useScopes, useTokenLifecycle };
|
|
1605
|
+
export { type AdvancedOidcOptions, CONFIG_PRESETS, type ConfigPreset, type DeviceAuthorizationResponse, type DeviceFlowError, DeviceLogin, type DeviceLoginProps, type EventCallbacks, type FeatureFlags, type KeycloakConfig, KeycloakConfigBuilder, type KeycloakDisabledReason, KeycloakProvider, type KeycloakProviderFullConfigProps, type KeycloakProviderProps, type KeycloakProviderZeroConfigProps, type KeycloakStatus, KeycloakStatusProvider, LoginButton, type LoginButtonProps, LogoutButton, type LogoutButtonProps, type PolicyContext, type PolicyFunction, ProtectedRoute, type ProtectedRouteProps, SessionMonitor, type SessionMonitorProps, type SilentRenewConfig, TokenBridge, type TokenBridgeProps, TokenBridgeSync, TokenLifecycleManager, type TokenLifecycleManagerProps, type TokenListener, type TokenResponse, type UseProtectedFetchOptions, type UseProtectedFetchReturn, type UseRolesReturn, type UseScopesReturn, type UseTokenLifecycleOptions, type UseTokenLifecycleReturn, UserProfile, type UserProfileProps, createTokenBridge, defaultConfig, defaultTokenBridge, fetchUserInfo, getConfigFromEnv, getConfigPreset, mergeWithPreset, pollForToken, requestDeviceCode, useAuth, useKeycloakStatus, useProtectedFetch, useRoles, useScopes, useTokenLifecycle };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
2
3
|
import { User, UserManagerSettings } from 'oidc-client-ts';
|
|
3
4
|
export { User } from 'oidc-client-ts';
|
|
4
5
|
import { useLocation } from 'react-router-dom';
|
|
@@ -223,6 +224,40 @@ declare function getConfigPreset(preset: ConfigPreset): Partial<KeycloakConfig>;
|
|
|
223
224
|
*/
|
|
224
225
|
declare function mergeWithPreset(preset: ConfigPreset, customConfig: Partial<KeycloakConfig>): Partial<KeycloakConfig>;
|
|
225
226
|
|
|
227
|
+
type TokenListener = (token: string | null) => void;
|
|
228
|
+
/**
|
|
229
|
+
* Minimal bridge to expose the current Keycloak access token outside React.
|
|
230
|
+
* Consumers can subscribe to token changes or fetch the latest value on demand.
|
|
231
|
+
*/
|
|
232
|
+
declare class TokenBridge {
|
|
233
|
+
private currentToken;
|
|
234
|
+
private listeners;
|
|
235
|
+
/**
|
|
236
|
+
* Update the tracked token and notify subscribers when it changes.
|
|
237
|
+
*/
|
|
238
|
+
setToken(token: string | null): void;
|
|
239
|
+
/**
|
|
240
|
+
* Read the most recent token value.
|
|
241
|
+
*/
|
|
242
|
+
getToken(): string | null;
|
|
243
|
+
/**
|
|
244
|
+
* Convenience helper for async callers.
|
|
245
|
+
*/
|
|
246
|
+
getTokenAsync(): Promise<string | null>;
|
|
247
|
+
/**
|
|
248
|
+
* Subscribe to token changes. Returns an unsubscribe callback.
|
|
249
|
+
*/
|
|
250
|
+
subscribe(listener: TokenListener): () => void;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Factory helper to create an isolated token bridge.
|
|
254
|
+
*/
|
|
255
|
+
declare const createTokenBridge: () => TokenBridge;
|
|
256
|
+
/**
|
|
257
|
+
* Default shared bridge for simple scenarios.
|
|
258
|
+
*/
|
|
259
|
+
declare const defaultTokenBridge: TokenBridge;
|
|
260
|
+
|
|
226
261
|
/**
|
|
227
262
|
* Props for zero-config mode (simplified setup)
|
|
228
263
|
*/
|
|
@@ -240,10 +275,16 @@ interface KeycloakProviderZeroConfigProps {
|
|
|
240
275
|
* @default 'default'
|
|
241
276
|
*/
|
|
242
277
|
preset?: ConfigPreset;
|
|
278
|
+
/**
|
|
279
|
+
* Toggle to disable Keycloak integration entirely.
|
|
280
|
+
* When false, children render with a stub auth context.
|
|
281
|
+
* @default true
|
|
282
|
+
*/
|
|
283
|
+
enabled?: boolean;
|
|
243
284
|
/**
|
|
244
285
|
* Child components to render
|
|
245
286
|
*/
|
|
246
|
-
children:
|
|
287
|
+
children: React__default.ReactNode;
|
|
247
288
|
/**
|
|
248
289
|
* Enable debug logging to console
|
|
249
290
|
* @default false
|
|
@@ -254,6 +295,10 @@ interface KeycloakProviderZeroConfigProps {
|
|
|
254
295
|
* Use this to customize preset or zero-config defaults
|
|
255
296
|
*/
|
|
256
297
|
config?: Partial<Omit<KeycloakConfig, 'authority' | 'clientId'>>;
|
|
298
|
+
/**
|
|
299
|
+
* Optional token bridge instance for exposing tokens outside React.
|
|
300
|
+
*/
|
|
301
|
+
tokenBridge?: TokenBridge;
|
|
257
302
|
}
|
|
258
303
|
/**
|
|
259
304
|
* Props for full-config mode (advanced setup)
|
|
@@ -263,15 +308,25 @@ interface KeycloakProviderFullConfigProps {
|
|
|
263
308
|
* Full Keycloak configuration object
|
|
264
309
|
*/
|
|
265
310
|
config: KeycloakConfig;
|
|
311
|
+
/**
|
|
312
|
+
* Toggle to disable Keycloak integration entirely.
|
|
313
|
+
* When false, children render with a stub auth context.
|
|
314
|
+
* @default true
|
|
315
|
+
*/
|
|
316
|
+
enabled?: boolean;
|
|
266
317
|
/**
|
|
267
318
|
* Child components to render
|
|
268
319
|
*/
|
|
269
|
-
children:
|
|
320
|
+
children: React__default.ReactNode;
|
|
270
321
|
/**
|
|
271
322
|
* Enable debug logging to console
|
|
272
323
|
* @default false
|
|
273
324
|
*/
|
|
274
325
|
debug?: boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Optional token bridge instance for exposing tokens outside React.
|
|
328
|
+
*/
|
|
329
|
+
tokenBridge?: TokenBridge;
|
|
275
330
|
}
|
|
276
331
|
/**
|
|
277
332
|
* Combined props type
|
|
@@ -396,7 +451,7 @@ type KeycloakProviderProps = KeycloakProviderZeroConfigProps | KeycloakProviderF
|
|
|
396
451
|
*
|
|
397
452
|
* All features can be disabled or customized via configuration overrides.
|
|
398
453
|
*/
|
|
399
|
-
declare const KeycloakProvider:
|
|
454
|
+
declare const KeycloakProvider: React__default.FC<KeycloakProviderProps>;
|
|
400
455
|
|
|
401
456
|
/**
|
|
402
457
|
* Context object passed to custom policy function
|
|
@@ -419,7 +474,7 @@ interface ProtectedRouteProps {
|
|
|
419
474
|
/**
|
|
420
475
|
* Child components to render when user is authorized
|
|
421
476
|
*/
|
|
422
|
-
children:
|
|
477
|
+
children: React__default.ReactNode;
|
|
423
478
|
/**
|
|
424
479
|
* Required realm roles (OR logic - user needs at least one)
|
|
425
480
|
*/
|
|
@@ -446,11 +501,11 @@ interface ProtectedRouteProps {
|
|
|
446
501
|
/**
|
|
447
502
|
* Custom loading component to display while checking authentication
|
|
448
503
|
*/
|
|
449
|
-
loadingComponent?:
|
|
504
|
+
loadingComponent?: React__default.ReactNode;
|
|
450
505
|
/**
|
|
451
506
|
* Custom unauthorized component to display when user lacks required permissions
|
|
452
507
|
*/
|
|
453
|
-
unauthorizedComponent?:
|
|
508
|
+
unauthorizedComponent?: React__default.ReactNode;
|
|
454
509
|
/**
|
|
455
510
|
* Path to redirect to if not authenticated
|
|
456
511
|
* @default '/login'
|
|
@@ -577,14 +632,14 @@ interface ProtectedRouteProps {
|
|
|
577
632
|
* </ProtectedRoute>
|
|
578
633
|
* ```
|
|
579
634
|
*/
|
|
580
|
-
declare const ProtectedRoute:
|
|
635
|
+
declare const ProtectedRoute: React__default.FC<ProtectedRouteProps>;
|
|
581
636
|
|
|
582
637
|
interface LoginButtonProps {
|
|
583
638
|
/**
|
|
584
639
|
* Button text
|
|
585
640
|
* @default 'Login'
|
|
586
641
|
*/
|
|
587
|
-
children?:
|
|
642
|
+
children?: React__default.ReactNode;
|
|
588
643
|
/**
|
|
589
644
|
* Additional CSS class names
|
|
590
645
|
*/
|
|
@@ -611,7 +666,7 @@ interface LoginButtonProps {
|
|
|
611
666
|
/**
|
|
612
667
|
* Custom inline styles
|
|
613
668
|
*/
|
|
614
|
-
style?:
|
|
669
|
+
style?: React__default.CSSProperties;
|
|
615
670
|
/**
|
|
616
671
|
* Disable the button
|
|
617
672
|
*/
|
|
@@ -651,14 +706,14 @@ interface LoginButtonProps {
|
|
|
651
706
|
* />
|
|
652
707
|
* ```
|
|
653
708
|
*/
|
|
654
|
-
declare const LoginButton:
|
|
709
|
+
declare const LoginButton: React__default.FC<LoginButtonProps>;
|
|
655
710
|
|
|
656
711
|
interface LogoutButtonProps {
|
|
657
712
|
/**
|
|
658
713
|
* Button text
|
|
659
714
|
* @default 'Logout'
|
|
660
715
|
*/
|
|
661
|
-
children?:
|
|
716
|
+
children?: React__default.ReactNode;
|
|
662
717
|
/**
|
|
663
718
|
* Additional CSS class names
|
|
664
719
|
*/
|
|
@@ -685,7 +740,7 @@ interface LogoutButtonProps {
|
|
|
685
740
|
/**
|
|
686
741
|
* Custom inline styles
|
|
687
742
|
*/
|
|
688
|
-
style?:
|
|
743
|
+
style?: React__default.CSSProperties;
|
|
689
744
|
/**
|
|
690
745
|
* Disable the button
|
|
691
746
|
*/
|
|
@@ -728,7 +783,7 @@ interface LogoutButtonProps {
|
|
|
728
783
|
* />
|
|
729
784
|
* ```
|
|
730
785
|
*/
|
|
731
|
-
declare const LogoutButton:
|
|
786
|
+
declare const LogoutButton: React__default.FC<LogoutButtonProps>;
|
|
732
787
|
|
|
733
788
|
interface UserProfileProps {
|
|
734
789
|
/**
|
|
@@ -758,7 +813,7 @@ interface UserProfileProps {
|
|
|
758
813
|
/**
|
|
759
814
|
* Custom inline styles
|
|
760
815
|
*/
|
|
761
|
-
style?:
|
|
816
|
+
style?: React__default.CSSProperties;
|
|
762
817
|
/**
|
|
763
818
|
* Callback when profile is clicked
|
|
764
819
|
*/
|
|
@@ -802,7 +857,7 @@ interface UserProfileProps {
|
|
|
802
857
|
* />
|
|
803
858
|
* ```
|
|
804
859
|
*/
|
|
805
|
-
declare const UserProfile:
|
|
860
|
+
declare const UserProfile: React__default.FC<UserProfileProps>;
|
|
806
861
|
|
|
807
862
|
interface SessionMonitorProps {
|
|
808
863
|
/**
|
|
@@ -854,7 +909,7 @@ interface SessionMonitorProps {
|
|
|
854
909
|
/**
|
|
855
910
|
* Custom inline styles
|
|
856
911
|
*/
|
|
857
|
-
style?:
|
|
912
|
+
style?: React__default.CSSProperties;
|
|
858
913
|
}
|
|
859
914
|
/**
|
|
860
915
|
* Session monitoring component with countdown timer
|
|
@@ -897,7 +952,7 @@ interface SessionMonitorProps {
|
|
|
897
952
|
* />
|
|
898
953
|
* ```
|
|
899
954
|
*/
|
|
900
|
-
declare const SessionMonitor:
|
|
955
|
+
declare const SessionMonitor: React__default.FC<SessionMonitorProps>;
|
|
901
956
|
|
|
902
957
|
interface DeviceLoginProps {
|
|
903
958
|
/**
|
|
@@ -930,7 +985,7 @@ interface DeviceLoginProps {
|
|
|
930
985
|
/**
|
|
931
986
|
* Custom inline styles
|
|
932
987
|
*/
|
|
933
|
-
style?:
|
|
988
|
+
style?: React__default.CSSProperties;
|
|
934
989
|
}
|
|
935
990
|
/**
|
|
936
991
|
* Device flow login component
|
|
@@ -965,7 +1020,7 @@ interface DeviceLoginProps {
|
|
|
965
1020
|
* />
|
|
966
1021
|
* ```
|
|
967
1022
|
*/
|
|
968
|
-
declare const DeviceLogin:
|
|
1023
|
+
declare const DeviceLogin: React__default.FC<DeviceLoginProps>;
|
|
969
1024
|
|
|
970
1025
|
interface TokenLifecycleManagerProps {
|
|
971
1026
|
/**
|
|
@@ -975,7 +1030,7 @@ interface TokenLifecycleManagerProps {
|
|
|
975
1030
|
/**
|
|
976
1031
|
* Child components to render
|
|
977
1032
|
*/
|
|
978
|
-
children:
|
|
1033
|
+
children: React__default.ReactNode;
|
|
979
1034
|
/**
|
|
980
1035
|
* Enable debug logging
|
|
981
1036
|
* @default false
|
|
@@ -997,7 +1052,19 @@ interface TokenLifecycleManagerProps {
|
|
|
997
1052
|
* </TokenLifecycleManager>
|
|
998
1053
|
* ```
|
|
999
1054
|
*/
|
|
1000
|
-
declare const TokenLifecycleManager:
|
|
1055
|
+
declare const TokenLifecycleManager: React__default.FC<TokenLifecycleManagerProps>;
|
|
1056
|
+
|
|
1057
|
+
interface TokenBridgeProps {
|
|
1058
|
+
/**
|
|
1059
|
+
* Optional custom bridge instance. Defaults to the shared global bridge.
|
|
1060
|
+
*/
|
|
1061
|
+
bridge?: TokenBridge;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Synchronises the current Keycloak access token into an imperative TokenBridge.
|
|
1065
|
+
* Place this component inside your application tree (after KeycloakProvider).
|
|
1066
|
+
*/
|
|
1067
|
+
declare const TokenBridgeSync: React.FC<TokenBridgeProps>;
|
|
1001
1068
|
|
|
1002
1069
|
/**
|
|
1003
1070
|
* Main authentication hook for accessing Keycloak authentication state and methods
|
|
@@ -1406,6 +1473,24 @@ declare class KeycloakConfigBuilder {
|
|
|
1406
1473
|
*/
|
|
1407
1474
|
declare function getConfigFromEnv(): Partial<KeycloakConfig>;
|
|
1408
1475
|
|
|
1476
|
+
type KeycloakDisabledReason = 'disabled' | 'missing-config';
|
|
1477
|
+
interface KeycloakStatus {
|
|
1478
|
+
/**
|
|
1479
|
+
* Whether the Keycloak integration is enabled by configuration.
|
|
1480
|
+
*/
|
|
1481
|
+
isEnabled: boolean;
|
|
1482
|
+
/**
|
|
1483
|
+
* Whether the minimum configuration (authority + clientId) is present.
|
|
1484
|
+
*/
|
|
1485
|
+
isConfigured: boolean;
|
|
1486
|
+
/**
|
|
1487
|
+
* Provides additional context when integration is disabled.
|
|
1488
|
+
*/
|
|
1489
|
+
reason?: KeycloakDisabledReason;
|
|
1490
|
+
}
|
|
1491
|
+
declare const KeycloakStatusProvider: React$1.Provider<KeycloakStatus>;
|
|
1492
|
+
declare const useKeycloakStatus: () => KeycloakStatus;
|
|
1493
|
+
|
|
1409
1494
|
/**
|
|
1410
1495
|
* Device authorization response from Keycloak
|
|
1411
1496
|
*/
|
|
@@ -1517,4 +1602,4 @@ declare function pollForToken(apiBaseUrl: string, deviceCode: string): Promise<T
|
|
|
1517
1602
|
*/
|
|
1518
1603
|
declare function fetchUserInfo(apiBaseUrl: string, accessToken: string): Promise<any>;
|
|
1519
1604
|
|
|
1520
|
-
export { type AdvancedOidcOptions, CONFIG_PRESETS, type ConfigPreset, type DeviceAuthorizationResponse, type DeviceFlowError, DeviceLogin, type DeviceLoginProps, type EventCallbacks, type FeatureFlags, type KeycloakConfig, KeycloakConfigBuilder, KeycloakProvider, type KeycloakProviderFullConfigProps, type KeycloakProviderProps, type KeycloakProviderZeroConfigProps, LoginButton, type LoginButtonProps, LogoutButton, type LogoutButtonProps, type PolicyContext, type PolicyFunction, ProtectedRoute, type ProtectedRouteProps, SessionMonitor, type SessionMonitorProps, type SilentRenewConfig, TokenLifecycleManager, type TokenLifecycleManagerProps, type TokenResponse, type UseProtectedFetchOptions, type UseProtectedFetchReturn, type UseRolesReturn, type UseScopesReturn, type UseTokenLifecycleOptions, type UseTokenLifecycleReturn, UserProfile, type UserProfileProps, defaultConfig, fetchUserInfo, getConfigFromEnv, getConfigPreset, mergeWithPreset, pollForToken, requestDeviceCode, useAuth, useProtectedFetch, useRoles, useScopes, useTokenLifecycle };
|
|
1605
|
+
export { type AdvancedOidcOptions, CONFIG_PRESETS, type ConfigPreset, type DeviceAuthorizationResponse, type DeviceFlowError, DeviceLogin, type DeviceLoginProps, type EventCallbacks, type FeatureFlags, type KeycloakConfig, KeycloakConfigBuilder, type KeycloakDisabledReason, KeycloakProvider, type KeycloakProviderFullConfigProps, type KeycloakProviderProps, type KeycloakProviderZeroConfigProps, type KeycloakStatus, KeycloakStatusProvider, LoginButton, type LoginButtonProps, LogoutButton, type LogoutButtonProps, type PolicyContext, type PolicyFunction, ProtectedRoute, type ProtectedRouteProps, SessionMonitor, type SessionMonitorProps, type SilentRenewConfig, TokenBridge, type TokenBridgeProps, TokenBridgeSync, TokenLifecycleManager, type TokenLifecycleManagerProps, type TokenListener, type TokenResponse, type UseProtectedFetchOptions, type UseProtectedFetchReturn, type UseRolesReturn, type UseScopesReturn, type UseTokenLifecycleOptions, type UseTokenLifecycleReturn, UserProfile, type UserProfileProps, createTokenBridge, defaultConfig, defaultTokenBridge, fetchUserInfo, getConfigFromEnv, getConfigPreset, mergeWithPreset, pollForToken, requestDeviceCode, useAuth, useKeycloakStatus, useProtectedFetch, useRoles, useScopes, useTokenLifecycle };
|