@tidecloak/js 0.14.41 → 0.14.42-staging

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.
Files changed (111) hide show
  1. package/README.md +32 -47
  2. package/dist/cjs/lib/tidecloak-dpop.js +151 -42
  3. package/dist/cjs/lib/tidecloak-dpop.js.map +1 -1
  4. package/dist/cjs/lib/tidecloak.js +300 -378
  5. package/dist/cjs/lib/tidecloak.js.map +1 -1
  6. package/dist/cjs/src/AdminAPI.js +12 -19
  7. package/dist/cjs/src/AdminAPI.js.map +1 -1
  8. package/dist/cjs/src/IAMService.js +155 -2098
  9. package/dist/cjs/src/IAMService.js.map +1 -1
  10. package/dist/cjs/src/index.js +1 -7
  11. package/dist/cjs/src/index.js.map +1 -1
  12. package/dist/esm/lib/tidecloak-dpop.js +151 -42
  13. package/dist/esm/lib/tidecloak-dpop.js.map +1 -1
  14. package/dist/esm/lib/tidecloak.js +300 -377
  15. package/dist/esm/lib/tidecloak.js.map +1 -1
  16. package/dist/esm/src/AdminAPI.js +3 -7
  17. package/dist/esm/src/AdminAPI.js.map +1 -1
  18. package/dist/esm/src/IAMService.js +152 -2065
  19. package/dist/esm/src/IAMService.js.map +1 -1
  20. package/dist/esm/src/index.js +1 -7
  21. package/dist/esm/src/index.js.map +1 -1
  22. package/dist/types/AdminAPI.d.ts +1 -1
  23. package/dist/types/IAMService.d.ts +52 -603
  24. package/dist/types/index.d.ts +1 -11
  25. package/dist/types/lib/tidecloak-dpop.d.ts +19 -3
  26. package/dist/types/lib/tidecloak.d.ts +46 -38
  27. package/dist/types/src/AdminAPI.d.ts +1 -1
  28. package/dist/types/src/IAMService.d.ts +52 -603
  29. package/dist/types/src/index.d.ts +1 -11
  30. package/docs/FRONT_CHANNEL.md +55 -55
  31. package/lib/README.md +10 -14
  32. package/package.json +4 -25
  33. package/dist/cjs/lib/secureFetchPolicy.js +0 -45
  34. package/dist/cjs/lib/secureFetchPolicy.js.map +0 -1
  35. package/dist/cjs/src/dpopRoute.js +0 -30
  36. package/dist/cjs/src/dpopRoute.js.map +0 -1
  37. package/dist/cjs/src/dpopServer.js +0 -77
  38. package/dist/cjs/src/dpopServer.js.map +0 -1
  39. package/dist/cjs/src/generated/dpopAuthAsset.js +0 -7
  40. package/dist/cjs/src/generated/dpopAuthAsset.js.map +0 -1
  41. package/dist/cjs/src/policy-react.js +0 -51
  42. package/dist/cjs/src/policy-react.js.map +0 -1
  43. package/dist/cjs/src/types.js +0 -6
  44. package/dist/cjs/src/types.js.map +0 -1
  45. package/dist/cjs/src/utils/dpopAuthPage.js +0 -69
  46. package/dist/cjs/src/utils/dpopAuthPage.js.map +0 -1
  47. package/dist/cjs/src/utils/fetch.js +0 -39
  48. package/dist/cjs/src/utils/fetch.js.map +0 -1
  49. package/dist/cjs/src/utils/index.js +0 -17
  50. package/dist/cjs/src/utils/index.js.map +0 -1
  51. package/dist/cjs/src/utils/initOptions.js +0 -78
  52. package/dist/cjs/src/utils/initOptions.js.map +0 -1
  53. package/dist/cjs/src/utils/pkce.js +0 -48
  54. package/dist/cjs/src/utils/pkce.js.map +0 -1
  55. package/dist/cjs/src/utils/silentCheckSso.js +0 -138
  56. package/dist/cjs/src/utils/silentCheckSso.js.map +0 -1
  57. package/dist/cjs/src/vite.js +0 -43
  58. package/dist/cjs/src/vite.js.map +0 -1
  59. package/dist/esm/lib/secureFetchPolicy.js +0 -42
  60. package/dist/esm/lib/secureFetchPolicy.js.map +0 -1
  61. package/dist/esm/src/dpopRoute.js +0 -27
  62. package/dist/esm/src/dpopRoute.js.map +0 -1
  63. package/dist/esm/src/dpopServer.js +0 -68
  64. package/dist/esm/src/dpopServer.js.map +0 -1
  65. package/dist/esm/src/generated/dpopAuthAsset.js +0 -4
  66. package/dist/esm/src/generated/dpopAuthAsset.js.map +0 -1
  67. package/dist/esm/src/policy-react.js +0 -45
  68. package/dist/esm/src/policy-react.js.map +0 -1
  69. package/dist/esm/src/types.js +0 -5
  70. package/dist/esm/src/types.js.map +0 -1
  71. package/dist/esm/src/utils/dpopAuthPage.js +0 -63
  72. package/dist/esm/src/utils/dpopAuthPage.js.map +0 -1
  73. package/dist/esm/src/utils/fetch.js +0 -36
  74. package/dist/esm/src/utils/fetch.js.map +0 -1
  75. package/dist/esm/src/utils/index.js +0 -6
  76. package/dist/esm/src/utils/index.js.map +0 -1
  77. package/dist/esm/src/utils/initOptions.js +0 -75
  78. package/dist/esm/src/utils/initOptions.js.map +0 -1
  79. package/dist/esm/src/utils/pkce.js +0 -43
  80. package/dist/esm/src/utils/pkce.js.map +0 -1
  81. package/dist/esm/src/utils/silentCheckSso.js +0 -134
  82. package/dist/esm/src/utils/silentCheckSso.js.map +0 -1
  83. package/dist/esm/src/vite.js +0 -40
  84. package/dist/esm/src/vite.js.map +0 -1
  85. package/dist/types/dpopRoute.d.ts +0 -11
  86. package/dist/types/dpopServer.d.ts +0 -35
  87. package/dist/types/generated/dpopAuthAsset.d.ts +0 -2
  88. package/dist/types/lib/secureFetchPolicy.d.ts +0 -37
  89. package/dist/types/policy-react.d.ts +0 -40
  90. package/dist/types/src/dpopRoute.d.ts +0 -11
  91. package/dist/types/src/dpopServer.d.ts +0 -35
  92. package/dist/types/src/generated/dpopAuthAsset.d.ts +0 -2
  93. package/dist/types/src/policy-react.d.ts +0 -40
  94. package/dist/types/src/types.d.ts +0 -114
  95. package/dist/types/src/utils/dpopAuthPage.d.ts +0 -22
  96. package/dist/types/src/utils/fetch.d.ts +0 -11
  97. package/dist/types/src/utils/index.d.ts +0 -5
  98. package/dist/types/src/utils/initOptions.d.ts +0 -69
  99. package/dist/types/src/utils/pkce.d.ts +0 -24
  100. package/dist/types/src/utils/silentCheckSso.d.ts +0 -82
  101. package/dist/types/src/vite.d.ts +0 -13
  102. package/dist/types/types.d.ts +0 -114
  103. package/dist/types/utils/dpopAuthPage.d.ts +0 -22
  104. package/dist/types/utils/fetch.d.ts +0 -11
  105. package/dist/types/utils/index.d.ts +0 -5
  106. package/dist/types/utils/initOptions.d.ts +0 -69
  107. package/dist/types/utils/pkce.d.ts +0 -24
  108. package/dist/types/utils/silentCheckSso.d.ts +0 -82
  109. package/dist/types/vite.d.ts +0 -13
  110. package/docs/HYBRID_MODE.md +0 -185
  111. package/docs/NATIVE_MODE.md +0 -284
@@ -1,618 +1,67 @@
1
- import TideCloak, { RequestEnclave } from "../lib/tidecloak.js";
2
- /**
3
- * Singleton IAMService wrapping the TideCloak client.
4
- *
5
- * Supports three modes:
6
- * - **Front-channel mode**: Browser handles all token operations (standard OIDC)
7
- * - **Hybrid/BFF mode**: Browser handles PKCE, backend exchanges code for tokens (more secure)
8
- * - **Native mode**: External browser for login, app handles tokens via adapter (Electron, Tauri, React Native)
9
- *
10
- * ---
11
- * ## Front-channel Mode
12
- *
13
- * Handlers are called with the event name first, then the event's arguments.
14
- *
15
- * Usage A: pass an onReady callback directly
16
- * ```js
17
- * import { IAMService } from '@tidecloak/js';
18
- * import tidecloakConfig from './tidecloak.json';
19
- *
20
- * IAMService.initIAM(tidecloakConfig, (_event, authenticated) => {
21
- * if (!authenticated) IAMService.doLogin();
22
- * }).catch(console.error);
23
- * ```
24
- *
25
- * Usage B: attach multiple listeners, then init
26
- * ```js
27
- * IAMService
28
- * .on('ready', (_event, auth) => console.log('ready', auth))
29
- * .on('authError', (_event, err) => console.error('Auth failed', err));
30
- *
31
- * await IAMService.initIAM(tidecloakConfig);
32
- * ```
33
- *
34
- * ---
35
- * ## Hybrid/BFF Mode (Backend-For-Frontend)
36
- *
37
- * In hybrid mode, the browser generates PKCE and redirects to the IdP, but the
38
- * backend exchanges the authorization code for tokens. This keeps tokens server-side
39
- * for improved security.
40
- *
41
- * ### Config shape:
42
- * ```js
43
- * const hybridConfig = {
44
- * authMode: "hybrid",
45
- * oidc: {
46
- * authorizationEndpoint: "https://auth.example.com/realms/myrealm/protocol/openid-connect/auth",
47
- * clientId: "my-client",
48
- * redirectUri: "https://app.example.com/auth/callback",
49
- * scope: "openid profile email", // optional, defaults to "openid profile email"
50
- * prompt: "login" // optional
51
- * },
52
- * tokenExchange: {
53
- * endpoint: "/api/authenticate", // Backend endpoint that exchanges code for tokens
54
- * provider: "tidecloak-auth", // optional, defaults to "tidecloak-auth"
55
- * headers: () => ({ // optional, custom headers (e.g., CSRF token)
56
- * "anti-csrf-token": getCSRFToken()
57
- * })
58
- * }
59
- * };
60
- * ```
61
- *
62
- * ### Login Page:
63
- * ```js
64
- * // Load config and trigger login
65
- * await IAMService.loadConfig(hybridConfig);
66
- * IAMService.doLogin("/dashboard"); // returnUrl after successful auth
67
- * ```
68
- *
69
- * ### Redirect/Callback Page:
70
- * ```js
71
- * // initIAM handles the callback automatically - exchanges code for tokens via backend
72
- * const authenticated = await IAMService.initIAM(hybridConfig);
73
- * if (authenticated) {
74
- * const returnUrl = IAMService.getReturnUrl() || "/";
75
- * window.location.assign(returnUrl);
76
- * }
77
- * ```
78
- *
79
- * ### Token Exchange Request Format:
80
- * The backend endpoint receives a POST request with:
81
- * ```json
82
- * {
83
- * "accessToken": "{\"code\":\"...\",\"code_verifier\":\"...\",\"redirect_uri\":\"...\"}",
84
- * "provider": "tidecloak-auth"
85
- * }
86
- * ```
87
- *
88
- * ---
89
- * ## Events
90
- * Every handler receives `(eventName, ...args)`.
91
- * - `ready` - Emitted when initialization completes (with authenticated boolean)
92
- * - `initError` - Emitted when initialization fails
93
- * - `authSuccess` - Emitted on successful authentication
94
- * - `authError` - Emitted on authentication failure
95
- * - `authRefreshSuccess` - Emitted when token refresh succeeds (front-channel only)
96
- * - `authRefreshError` - Emitted when token refresh fails (front-channel only)
97
- * - `logout` - Emitted on logout
98
- * - `tokenExpired` - Emitted when token expires (front-channel only)
99
- */
100
- declare class IAMService {
101
- _tc: TideCloak | null;
102
- _config: {
103
- constructor: Function;
104
- toString(): string;
105
- toLocaleString(): string;
106
- valueOf(): Object;
107
- hasOwnProperty(v: PropertyKey): boolean;
108
- isPrototypeOf(v: Object): boolean;
109
- propertyIsEnumerable(v: PropertyKey): boolean;
110
- } | null;
111
- _listeners: {};
112
- _hybridAuthenticated: boolean;
113
- _hybridReturnUrl: string | null;
114
- _hybridCallbackHandled: boolean;
115
- _hybridCallbackPromise: Promise<boolean> | null;
116
- _cachedCallbackData: {
117
- isCallback: boolean;
118
- code: string;
119
- verifier: string;
120
- redirectUri: any;
121
- returnUrl: string;
122
- provider: any;
123
- error: string | null;
124
- errorDescription: string | null;
125
- } | {
126
- isCallback: boolean;
127
- code: string;
128
- verifier: string;
129
- redirectUri: any;
130
- returnUrl: string;
131
- provider: any;
132
- error: null;
133
- errorDescription: null;
134
- } | null;
135
- _nativeAdapter: any;
136
- _nativeAuthenticated: boolean;
137
- _nativeTokens: any;
138
- _nativeCallbackUnsubscribe: any;
139
- _nativeCallbackHandled: boolean;
140
- _nativeCallbackPromise: Promise<boolean> | null;
141
- _nativeCallbackProcessing: boolean;
142
- _nativeDoken: any;
143
- _nativeDokenParsed: Object | null;
144
- _nativeVoucher: any;
145
- _nativeRequestEnclave: RequestEnclave | null;
146
- _nativeEncryptionCallbackUnsubscribe: any;
147
- _pendingEncryptionRequests: Map<any, any>;
148
- _dpopProvider: import("../lib/tidecloak-dpop.js").DPoPSignatureProvider | null;
149
- _frontchannelInitPromise: Promise<boolean> | null;
150
- constructor();
151
- /**
152
- * Register an event listener. The handler is called as `handler(event, ...args)`,
153
- * so the event name comes first, e.g. `on('ready', (_event, authenticated) => ...)`.
154
- * @param {'ready'|'initError'|'authSuccess'|'authError'|'authRefreshSuccess'|'authRefreshError'|'logout'|'tokenExpired'} event
155
- * @param {Function} handler
156
- * @returns {this}
157
- */
158
- on(event: 'ready' | 'initError' | 'authSuccess' | 'authError' | 'authRefreshSuccess' | 'authRefreshError' | 'logout' | 'tokenExpired', handler: Function): this;
159
- /**
160
- * Unregister an event listener.
161
- * @param {string} event
162
- * @param {Function} handler
163
- * @returns {this}
164
- */
165
- off(event: string, handler: Function): this;
166
- /** @private */
167
- private _emit;
168
- /**
169
- * Check if running in hybrid mode.
170
- * @returns {boolean}
171
- */
172
- isHybridMode(): boolean;
173
- /**
174
- * Check if running in native mode.
175
- * @returns {boolean}
176
- */
177
- isNativeMode(): boolean;
178
- /**
179
- * Load TideCloak configuration and instantiate the client once.
180
- * @param {Object} config - TideCloak configuration object.
181
- * @returns {Promise<Object|null>} The loaded config, or null on failure.
182
- */
183
- loadConfig(config: Object): Promise<Object | null>;
184
- /**
185
- * Initialize the TideCloak SSO client with silent SSO check.
186
- * In hybrid mode, handles the redirect callback if present.
187
- * @param {Object} config - TideCloak configuration object.
188
- * @param {Function} [onReady] - Optional 'ready' handler, called as `(event, authenticated)`.
189
- * @returns {Promise<boolean>} true if authenticated, else false.
190
- */
191
- initIAM(config: Object, onReady?: Function): Promise<boolean>;
192
- /**
193
- * Drive the one-and-only `TideCloak.init()` for front-channel mode and emit the
194
- * resulting `ready` state. Split out of {@link initIAM} so the in-flight promise
195
- * can be shared with concurrent callers.
196
- * @private
197
- * @param {Object} config
1
+ declare class IAMServiceImplementation {
2
+ #private;
3
+ get tide(): Readonly<{
4
+ encrypt: (toEncrypt: any, decryptionPolicy: any) => Promise<(string | Uint8Array<ArrayBufferLike>)[]>;
5
+ decrypt: (toDecrypt: any, decryptionPolicy: any) => Promise<(string | Uint8Array<ArrayBufferLike>)[]>;
6
+ draftEncryption: (toEncrypt: any) => Promise<Uint8Array<ArrayBufferLike>>;
7
+ commitEncryption: (request: any, decryptionPolicy: any) => Promise<Uint8Array<ArrayBufferLike>[]>;
8
+ draftDecryption: (toDecrypt: any) => Promise<Uint8Array<ArrayBufferLike>>;
9
+ commitDecryption: (request: any, decryptionPolicy: any) => Promise<Uint8Array<ArrayBufferLike>[]>;
10
+ createTideRequest: (encodedRequest: any) => Promise<Uint8Array<ArrayBufferLike>>;
11
+ requestTideOperatorApproval: (requests: any) => Promise<{
12
+ id: string;
13
+ request: Uint8Array;
14
+ status: 'approved' | 'denied' | 'pending';
15
+ }[]>;
16
+ executeSignRequest: (request: any, waitForAll: any) => Promise<any[]>;
17
+ }>;
18
+ /**
19
+ * Initialize from the TideCloak adapter config (tidecloak.json)
20
+ * @param {Record<string, any>} json The contents of tidecloak.json
21
+ * @param {import("../lib/tidecloak.js").TideCloakInitOptions | undefined} options Overrides the defaults
22
+ * (check-sso, S256 PKCE, request enclave on, dpopConfig / checkLoginIframe from tidecloak.json, and
23
+ * silentCheckSsoRedirectUri at `<origin>/silent-check-sso.html`). Apps that serve the silent SSO page
24
+ * elsewhere pass their own `silentCheckSsoRedirectUri`.
198
25
  * @returns {Promise<boolean>}
199
26
  */
200
- private _initFrontchannel;
201
- /** @private */
202
- private getTideCloakClient;
27
+ init(json: Record<string, any>, options: import("../lib/tidecloak.js").TideCloakInitOptions | undefined): Promise<boolean>;
203
28
  /**
204
- * Write the access token to the `kcToken` cookie used by the server middleware.
205
- * Uses `SameSite=Lax` to blunt CSRF (the cookie is not sent on cross-site
206
- * subrequests) while still allowing the post-login top-level redirect, and
207
- * marks it `Secure` whenever the page is served over HTTPS.
208
- * @private
209
- */
210
- private _setTokenCookie;
211
- /** @private */
212
- private _clearTokenCookie;
213
- /**
214
- * Restrict a post-login return URL to a same-origin, root-relative path to
215
- * prevent open-redirect. The OAuth `state` (and the sessionStorage fallback)
216
- * round-trips this value and is then handed to `window.location.assign`, so an
217
- * attacker-seeded absolute/protocol-relative URL ("https://evil", "//evil",
218
- * "/\\evil", "javascript:...") must be rejected. Falls back to "/".
219
- * @private
220
- */
221
- private _sanitizeReturnUrl;
222
- /** @returns {Object} Loaded config */
223
- getConfig(): Object;
224
- /**
225
- * Whether initialization has already run to completion for the current mode.
226
29
  *
227
- * "Settled", not "started": while an init is still in flight this returns
228
- * `false`, because the auth state it will produce does not exist yet and reading
229
- * it would report a spurious logged-out state.
230
- *
231
- * Consumers that subscribe to events LATE (a React provider re-running its
232
- * effect and re-subscribing, say) must use this to re-read the current auth
233
- * state synchronously rather than waiting on a `ready` event that has already
234
- * been emitted and is gone.
235
- *
236
- * @returns {boolean}
237
- */
238
- isInitialized(): boolean;
239
- /** @returns {boolean} Whether there's a valid token (or session in hybrid/native mode) */
240
- isLoggedIn(): boolean;
241
- /**
242
- * Get valid token (refreshing if needed). Resolves to `null` in native mode
243
- * when no tokens are stored or a refresh fails.
244
- * @returns {Promise<string|null>}
245
- * @throws {Error} In hybrid mode (tokens are server-side)
246
- */
247
- getToken(): Promise<string | null>;
248
- /**
249
- * Seconds until token expiry.
250
- * @returns {number}
251
- * @throws {Error} In hybrid mode (tokens are server-side)
252
- */
253
- getTokenExp(): number;
254
- /**
255
- * Get ID token.
256
- * @returns {string|null}
257
- * @throws {Error} In hybrid mode (tokens are server-side)
258
- */
259
- getIDToken(): string | null;
260
- /**
261
- * Get username (preferred_username claim).
262
- * @returns {string}
263
- * @throws {Error} In hybrid mode (tokens are server-side)
264
- */
265
- getName(): string;
266
- /**
267
- * Get the return URL after successful hybrid authentication.
268
- * Only available in hybrid mode after successful auth.
269
- * @returns {string|null}
270
- */
271
- getReturnUrl(): string | null;
272
- /**
273
- * Check if user has a realm role.
274
- * @param {string} role - the name of the role to check
275
- * @returns {boolean} Whether the user has a given realm role
276
- * @throws {Error} In hybrid mode (role checks not available client-side)
277
- */
278
- hasRealmRole(role: string): boolean;
279
- /**
280
- * Check if user has a client role.
281
- * @param {string} role - the name of the role to check
282
- * @param {string} [client] - optional client-ID (defaults to the configured adapter resource)
283
- * @returns {boolean} - whether the user has that role
284
- * @throws {Error} In hybrid mode (role checks not available client-side)
285
- */
286
- hasClientRole(role: string, client?: string): boolean;
287
- /**
288
- * Get custom claim from access token.
289
- * @param {string} key - The name of the claim to retrieve from the Access token's payload.
290
- * @returns {*} Custom claim from access token
291
- * @throws {Error} In hybrid mode (tokens are server-side)
292
- */
293
- getValueFromToken(key: string): any;
294
- /**
295
- * Get custom claim from ID token.
296
- * @param {string} key - The name of the claim to retrieve from the ID token's payload.
297
- * @returns {*} Custom claim from ID token
298
- * @throws {Error} In hybrid mode (tokens are server-side)
299
- */
300
- getValueFromIDToken(key: string): any;
301
- /**
302
- * Alias of {@link IAMService#getValueFromIDToken}, with the same casing as the React context.
303
- * @param {string} key - The name of the claim to retrieve from the ID token's payload.
304
- * @returns {*} Custom claim from ID token
305
- * @throws {Error} In hybrid mode (tokens are server-side)
306
- */
307
- getValueFromIdToken(key: string): any;
308
- /**
309
- * Refreshes token if expired or about to expire.
310
- * @returns {Promise<boolean>}
311
- * @throws {Error} In hybrid mode (token refresh handled server-side)
312
- */
313
- updateIAMToken(): Promise<boolean>;
314
- /**
315
- * Force immediate refresh (min validity = -1).
316
- * @returns {Promise<boolean>}
317
- * @throws {Error} In hybrid mode (token refresh handled server-side)
318
- */
319
- forceUpdateToken(): Promise<boolean>;
320
- /**
321
- * Start login redirect.
322
- * In hybrid mode, initiates PKCE flow and redirects to IdP.
323
- * In native mode, opens external browser with auth URL.
324
- * @param {string} [returnUrl] - URL to redirect to after successful auth (hybrid/native mode)
325
- * @returns {void|Promise<void>} Resolves once the redirect/external-browser flow is initiated (hybrid/native); returns void in front-channel mode.
326
- */
327
- doLogin(returnUrl?: string): void | Promise<void>;
328
- /**
329
- * Encrypt data via adapter.
330
- * Not available in hybrid mode (encryption requires client-side doken).
331
- * In native mode, passing a decryption policy throws.
332
- * @param {{ data: string | Uint8Array, tags: string[] }[]} data - Array of objects to encrypt
333
- * @param {Uint8Array} [decryption_policy] Optional policy to protect the encrypted data
334
- * @returns {Promise<(string | Uint8Array)[]>} Array of encrypted values
335
- */
336
- doEncrypt(data: {
337
- data: string | Uint8Array;
338
- tags: string[];
339
- }[], decryption_policy?: Uint8Array): Promise<(string | Uint8Array)[]>;
340
- /**
341
- * Decrypt data via adapter.
342
- * Not available in hybrid mode (decryption requires client-side doken).
343
- * In native mode, passing a decryption policy throws.
344
- * @param {{ encrypted: string | Uint8Array, tags: string[] }[]} data - Array of objects to decrypt
345
- * @param {Uint8Array} [decryption_policy] Optional policy the data was encrypted under
346
- * @returns {Promise<(string | Uint8Array)[]>} Array of decrypted values
347
- */
348
- doDecrypt(data: {
349
- encrypted: string | Uint8Array;
350
- tags: string[];
351
- }[], decryption_policy?: Uint8Array): Promise<(string | Uint8Array)[]>;
352
- /**
353
- * Draft an encryption request (two-step encryption flow).
354
- * Not available in hybrid or native mode.
355
- * @param {{ data: Uint8Array, tags: string[] }[]} data - Array of objects to draft encryption for
356
- * @returns {Promise<Uint8Array>} Draft encryption request
357
- */
358
- doDraftEncryption(data: {
359
- data: Uint8Array;
360
- tags: string[];
361
- }[]): Promise<Uint8Array>;
362
- /**
363
- * Commit a drafted encryption request with a specified policy.
364
- * Not available in hybrid or native mode.
365
- * @param {Uint8Array} request - Draft request from doDraftEncryption
366
- * @param {Uint8Array} decryption_policy - Policy to protect the encrypted data
367
- * @returns {Promise<Uint8Array[]>} Encrypted data
368
- */
369
- doCommitEncryption(request: Uint8Array, decryption_policy: Uint8Array): Promise<Uint8Array[]>;
370
- /**
371
- * Draft a decryption request (two-step decryption flow).
372
- * Not available in hybrid or native mode.
373
- * @param {{ encrypted: Uint8Array, tags: string[] }[]} data - Array of objects to draft decryption for
374
- * @returns {Promise<Uint8Array>} Draft decryption request
375
- */
376
- doDraftDecryption(data: {
377
- encrypted: Uint8Array;
378
- tags: string[];
379
- }[]): Promise<Uint8Array>;
380
- /**
381
- * Commit a drafted decryption request.
382
- * Not available in hybrid or native mode.
383
- * @param {Uint8Array} request - Draft request from doDraftDecryption
384
- * @param {Uint8Array} decryption_policy - Policy to decrypt the data
385
- * @returns {Promise<Uint8Array[]>} Decrypted data
30
+ * @param {import("../lib/tidecloak.js").TideCloakLoginOptions?} loginOpts
386
31
  */
387
- doCommitDecryption(request: Uint8Array, decryption_policy: Uint8Array): Promise<Uint8Array[]>;
32
+ doLogin(loginOpts: import("../lib/tidecloak.js").TideCloakLoginOptions | null): Promise<void>;
388
33
  /**
389
- * Drop-in replacement for fetch that automatically handles DPoP authentication.
390
- * If the request includes a Bearer token matching the TideCloak-managed token,
391
- * it's replaced with DPoP authorization and proof. Also manages resource server
392
- * nonces automatically. Otherwise, behaves like regular fetch.
393
34
  *
394
- * @param {string|URL|RequestInfo} url - The resource URL to fetch
395
- * @param {RequestInit} [init] - Optional fetch init options (same as standard fetch)
396
- * @returns {Promise<Response>} A promise that resolves to the fetch Response
397
- * @throws {Error} In hybrid mode (tokens are server-side)
398
- *
399
- * @example
400
- * ```js
401
- * const token = await IAMService.getToken();
402
- * const response = await IAMService.secureFetch('https://api.example.com/data', {
403
- * method: 'POST',
404
- * headers: {
405
- * 'Authorization': `Bearer ${token}`,
406
- * 'Content-Type': 'application/json',
407
- * },
408
- * body: JSON.stringify({ key: 'value' }),
409
- * });
410
- * ```
411
- */
412
- secureFetch(url: string | URL | RequestInfo, init?: RequestInit): Promise<Response>;
413
- /**
414
- * Native mode secure fetch with DPoP support.
415
- * @private
416
- */
417
- private _nativeSecureFetch;
418
- /**
419
- * Logout, clear cookie/session, then redirect.
420
- * In hybrid mode, clears local state and emits logout event.
421
- * In native mode, deletes tokens via adapter and emits logout event.
422
- */
423
- doLogout(): Promise<void>;
424
- /**
425
- * Base URL for Tidecloak realm (no trailing slash).
426
- * In hybrid mode returns empty string.
35
+ * @param {import("../lib/tidecloak.js").TideCloakLogoutOptions?} logoutOpts
427
36
  */
428
- getBaseUrl(): any;
37
+ doLogout(logoutOpts: import("../lib/tidecloak.js").TideCloakLogoutOptions | null): Promise<void>;
38
+ getToken(): string | undefined;
429
39
  /**
430
- * Start hybrid login flow: generate PKCE, store verifier, redirect to IdP.
431
- * @private
432
- * @param {string} returnUrl - URL to redirect to after successful auth
40
+ * When the access token expires, in browser time (adjusted for server clock skew).
41
+ * @returns {Date | undefined}
433
42
  */
434
- private _startHybridLogin;
43
+ getTokenExp(): Date | undefined;
44
+ getClaim(name: any): any;
45
+ getName(): any;
46
+ hasRealmRole(role: any): boolean;
47
+ hasClientRole(role: any): boolean;
48
+ updateToken(): Promise<boolean>;
49
+ forceUpdateToken(): Promise<boolean>;
435
50
  /**
436
- * Get hybrid callback data for custom token exchange.
437
- * Use this when you need to handle token exchange with your own auth system
438
- * (e.g., using a custom useLogin hook) instead of IAMService's built-in fetchJson.
439
- *
440
- * @param {Object} [opts] - Options
441
- * @param {boolean} [opts.clearStorage=true] - Whether to clear sessionStorage after reading
442
- * @param {string} [opts.redirectUri] - Override redirect URI (use when config isn't loaded)
443
- * @param {string} [opts.provider] - Override provider (defaults to "tidecloak-auth")
444
- * @returns {{
445
- * isCallback: boolean,
446
- * code: string,
447
- * verifier: string,
448
- * redirectUri: string,
449
- * returnUrl: string,
450
- * provider: string,
451
- * error: string|null,
452
- * errorDescription: string|null
453
- * }}
454
51
  *
455
- * @example
456
- * // With redirectUri override (recommended for callback pages after full navigation)
457
- * const data = IAMService.getHybridCallbackData({
458
- * redirectUri: process.env.KEYCLOAK_REDIRECTURI,
459
- * });
460
- * if (data.isCallback && data.code && data.verifier) {
461
- * login.execute({
462
- * accessToken: JSON.stringify({
463
- * code: data.code,
464
- * code_verifier: data.verifier,
465
- * redirect_uri: data.redirectUri,
466
- * }),
467
- * provider: data.provider,
468
- * });
469
- * }
470
- */
471
- getHybridCallbackData(opts?: {
472
- clearStorage?: boolean;
473
- redirectUri?: string;
474
- provider?: string;
475
- }): {
476
- isCallback: boolean;
477
- code: string;
478
- verifier: string;
479
- redirectUri: string;
480
- returnUrl: string;
481
- provider: string;
482
- error: string | null;
483
- errorDescription: string | null;
484
- };
485
- /**
486
- * Handle hybrid redirect callback: exchange code for tokens via backend endpoint.
487
- * @private
488
- * @param {Object} opts - Options
489
- * @param {string} [opts.onMissingVerifierRedirectTo] - URL to redirect if verifier is missing
490
- * @returns {Promise<{handled: boolean, authenticated: boolean, returnUrl: string}>}
491
- */
492
- private _handleHybridRedirectCallback;
493
- /**
494
- * Get OIDC configuration from the native config.
495
- * @private
496
- * @returns {{ authServerUrl: string, realm: string, clientId: string, scope: string }}
497
- */
498
- private _getNativeOIDCConfig;
499
- /**
500
- * Get encryption configuration from the native config.
501
- * Automatically selects clientOriginAuth based on window.location.origin.
502
- * @private
503
- * @returns {{ vendorId: string, homeOrkUrl: string, clientOriginAuth: string } | null}
504
- */
505
- private _getNativeEncryptionConfig;
506
- /**
507
- * Start native login flow: generate PKCE, open external browser with auth URL.
508
- * @private
509
- * @param {string} returnUrl - URL to redirect to after successful auth
510
- */
511
- private _startNativeLogin;
512
- /**
513
- * Handle native auth callback: exchange code for tokens.
514
- * @private
515
- * @param {string} code - Authorization code from IdP
516
- * @param {string} [voucher] - Optional voucher fetched during login (for encryption)
517
- */
518
- private _handleNativeCallback;
519
- /**
520
- * Refresh native token using refresh token.
521
- * @private
522
- * @param {string} refreshToken - The refresh token
523
- * @returns {Promise<Object>} New token data
52
+ * @param {'ready'|'authSuccess'|'authError'|'authRefreshSuccess'|'authRefreshError'|'logout'|'tokenExpired'} event
53
+ * @param {*Function} callback
524
54
  */
525
- private _refreshNativeToken;
55
+ on(event: 'ready' | 'authSuccess' | 'authError' | 'authRefreshSuccess' | 'authRefreshError' | 'logout' | 'tokenExpired', callback: any): this;
526
56
  /**
527
- * Initialize the native RequestEnclave for encryption/decryption.
528
- * @private
529
- * @param {string} voucherDataUrl - Pre-fetched voucher as data URL
530
- */
531
- private _initNativeRequestEnclave;
532
- /**
533
- * Build the encryption page URL for external browser.
534
- * This page is hosted on the TideCloak server and has session cookies.
535
- * @private
536
- * @param {string} operation - 'encrypt' or 'decrypt'
537
- * @param {string} requestId - Unique request ID
538
- * @param {string} dataBase64 - Base64-encoded data to process
539
- * @param {string} tagsJson - JSON-encoded tags array
540
- * @param {string} callbackUrl - URL to redirect with result
541
- * @returns {string} URL to open in external browser
542
- */
543
- private _buildEncryptionPageUrl;
544
- /**
545
- * Perform an encryption operation via external browser.
546
- * @private
547
- * @param {'encrypt' | 'decrypt'} operation - The operation to perform
548
- * @param {string} dataBase64 - Base64-encoded data to process
549
- * @param {string[]} tags - Tags for the operation
550
- * @returns {Promise<string>} Base64-encoded result
551
- */
552
- private _doExternalBrowserOperation;
553
- /**
554
- * Get the voucher URL for native mode.
555
- * @private
556
- * @returns {string} Voucher URL
557
- */
558
- private _getNativeVoucherUrl;
559
- /**
560
- * Check if user has a realm role (native mode helper).
561
- * @private
562
- * @param {string} role - Role to check
563
- * @returns {boolean}
564
- */
565
- private _nativeHasRealmRole;
566
- /**
567
- * Native mode encryption using RequestEnclave.
568
- * Uses either a pre-fetched voucher (as data URL) or the live voucherURL
569
- * that the ORK iframe will fetch with session cookies.
570
- * @private
571
- * @param {{ data: string | Uint8Array, tags: string[] }[]} toEncrypt
572
- * @returns {Promise<(string | Uint8Array)[]>}
573
- */
574
- private _nativeEncrypt;
575
- /**
576
- * Native mode decryption using RequestEnclave.
577
- * Uses either a pre-fetched voucher (as data URL) or the live voucherURL
578
- * that the ORK iframe will fetch with session cookies.
579
- * @private
580
- * @param {{ encrypted: string | Uint8Array, tags: string[] }[]} toDecrypt
581
- * @returns {Promise<(string | Uint8Array)[]>}
582
- */
583
- private _nativeDecrypt;
584
- /**
585
- * Convert string to Uint8Array.
586
- * @private
587
- */
588
- private _stringToUint8Array;
589
- /**
590
- * Convert Uint8Array to string.
591
- * @private
592
- */
593
- private _stringFromUint8Array;
594
- /**
595
- * Convert bytes to base64.
596
- * @private
597
- */
598
- private _bytesToBase64;
599
- /**
600
- * Convert base64 to bytes.
601
- * @private
602
- */
603
- private _base64ToBytes;
604
- /**
605
- * Parse a JWT token and return its payload.
606
- * @private
607
- * @param {string} token - JWT token string
608
- * @returns {Object|null} Parsed token payload or null on error
609
- */
610
- private _parseToken;
611
- /**
612
- * Cleanup native mode resources.
613
- */
614
- destroy(): void;
57
+ * Unregister an event listener.
58
+ * @param {string} event
59
+ * @param {Function} handler
60
+ * @returns {this}
61
+ */
62
+ off(event: string, handler: Function): this;
63
+ fetch(url: any, init?: {}): Promise<Response>;
64
+ isLoggedIn(): boolean;
615
65
  }
616
- declare const IAMServiceInstance: IAMService;
617
- export { IAMServiceInstance as IAMService };
618
- export default IAMServiceInstance;
66
+ export declare const IAMService: IAMServiceImplementation;
67
+ export {};