@strivacity/sdk-react 3.0.0-rc.0 → 3.0.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/CHANGELOG.md +16 -0
- package/README.md +203 -241
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# 3.0.0 (2026-04-09)
|
|
2
|
+
|
|
3
|
+
### 🚀 Features
|
|
4
|
+
|
|
5
|
+
- ⚠️ EmbeddedFlow implemented ([a0e3ad8](https://github.com/Strivacity/sdk-js/commit/a0e3ad8))
|
|
6
|
+
- ⚠️ NativeFlow entry function now returns an object instead of a string ([9a8942d](https://github.com/Strivacity/sdk-js/commit/9a8942d))
|
|
7
|
+
|
|
8
|
+
### ⚠️ Breaking Changes
|
|
9
|
+
|
|
10
|
+
- EmbeddedFlow implemented ([a0e3ad8](https://github.com/Strivacity/sdk-js/commit/a0e3ad8))
|
|
11
|
+
- NativeFlow entry function now returns an object instead of a string ([9a8942d](https://github.com/Strivacity/sdk-js/commit/9a8942d))
|
|
12
|
+
|
|
13
|
+
### 🧱 Updated Dependencies
|
|
14
|
+
|
|
15
|
+
- Updated sdk-core to 3.0.0
|
|
16
|
+
|
|
1
17
|
## 3.0.0-rc.0 (2026-02-18)
|
|
2
18
|
|
|
3
19
|
### 🚀 Features
|
package/README.md
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
# @strivacity/sdk-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React library that integrates Strivacity's policy-driven authentication journeys into your application using the OAuth 2.0 PKCE flow. Supports `redirect`, `popup`, `native`, and `embedded` modes.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
See our [Developer Portal](https://www.strivacity.com/learn-support/developer-hub) to get started with developing with the Strivacity product.
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This SDK allows you to integrate Strivacity's policy-driven journeys into your React application. It wraps the `@strivacity/sdk-core` library as a React context provider and exposes a `useStrivacity` hook that provides authentication state and methods throughout your component tree. The SDK uses the OAuth 2.0 PKCE flow to authenticate with Strivacity. For detailed configuration options, available modes, and advanced usage refer to the [`@strivacity/sdk-core` documentation](https://github.com/Strivacity/sdk-js/blob/main/packages/sdk-core/README.md).
|
|
10
|
+
|
|
11
|
+
## Demo Application
|
|
6
12
|
|
|
7
13
|
- [Example app](https://github.com/Strivacity/sdk-js/tree/main/apps/react)
|
|
8
14
|
- [Ionic Example app](https://github.com/Strivacity/sdk-js/tree/main/apps/ionic-react)
|
|
9
15
|
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- React: 18+
|
|
19
|
+
|
|
10
20
|
## Install
|
|
11
21
|
|
|
12
22
|
```bash
|
|
@@ -15,16 +25,17 @@ npm install @strivacity/sdk-react
|
|
|
15
25
|
|
|
16
26
|
## Usage
|
|
17
27
|
|
|
18
|
-
###
|
|
28
|
+
### Initialization
|
|
19
29
|
|
|
20
|
-
|
|
30
|
+
Wrap your application with `StyAuthProvider` in your entry point:
|
|
21
31
|
|
|
22
32
|
```tsx
|
|
23
|
-
import {
|
|
33
|
+
import { createRoot } from 'react-dom/client';
|
|
34
|
+
import { BrowserRouter, Route, Routes } from 'react-router';
|
|
24
35
|
import { StyAuthProvider, type SDKOptions } from '@strivacity/sdk-react';
|
|
25
36
|
|
|
26
37
|
const options: SDKOptions = {
|
|
27
|
-
mode: 'redirect', // or 'popup'
|
|
38
|
+
mode: 'redirect', // or 'popup', 'native', 'embedded'
|
|
28
39
|
issuer: 'https://<YOUR_DOMAIN>',
|
|
29
40
|
scopes: ['openid', 'profile'],
|
|
30
41
|
clientId: '<YOUR_CLIENT_ID>',
|
|
@@ -35,28 +46,28 @@ createRoot(document.getElementById('app')!).render(
|
|
|
35
46
|
<BrowserRouter>
|
|
36
47
|
<StyAuthProvider options={options}>
|
|
37
48
|
<Routes>
|
|
38
|
-
<Route path="/" element={<App />}
|
|
39
|
-
...
|
|
40
|
-
</Route>
|
|
49
|
+
<Route path="/" element={<App />} />
|
|
41
50
|
</Routes>
|
|
42
51
|
</StyAuthProvider>
|
|
43
52
|
</BrowserRouter>,
|
|
44
53
|
);
|
|
45
54
|
```
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#### Redirect or popup mode
|
|
56
|
+
Use the `useStrivacity` hook in any component to access authentication state:
|
|
50
57
|
|
|
51
|
-
|
|
58
|
+
```tsx
|
|
59
|
+
import { useStrivacity } from '@strivacity/sdk-react';
|
|
52
60
|
|
|
53
|
-
|
|
61
|
+
export default function MyComponent() {
|
|
62
|
+
const { loading, isAuthenticated, idTokenClaims } = useStrivacity();
|
|
63
|
+
}
|
|
64
|
+
```
|
|
54
65
|
|
|
55
|
-
|
|
66
|
+
### Redirect / Popup mode
|
|
56
67
|
|
|
57
|
-
|
|
68
|
+
In `redirect` mode the user is taken to the identity provider in the same window; in `popup` mode authentication happens in a popup. Both are initiated the same way from code.
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
#### Login page example
|
|
60
71
|
|
|
61
72
|
```tsx
|
|
62
73
|
import { useEffect } from 'react';
|
|
@@ -77,9 +88,9 @@ export default function Login() {
|
|
|
77
88
|
}
|
|
78
89
|
```
|
|
79
90
|
|
|
80
|
-
|
|
91
|
+
#### Callback page example
|
|
81
92
|
|
|
82
|
-
The callback page handles the response from the identity provider
|
|
93
|
+
The callback page handles the response from the identity provider. It calls `handleCallback()` and redirects to `/profile` on success:
|
|
83
94
|
|
|
84
95
|
```tsx
|
|
85
96
|
import { useEffect } from 'react';
|
|
@@ -109,11 +120,7 @@ export default function Callback() {
|
|
|
109
120
|
}
|
|
110
121
|
```
|
|
111
122
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
The profile page displays user information and authentication details after successful login. It uses the `useStrivacity` hook to access the authentication state and display relevant data such as access tokens, ID token claims, and expiration status.
|
|
115
|
-
|
|
116
|
-
We check if the user is authenticated and display their profile information. If the user is not authenticated, we redirect them to the login page.
|
|
123
|
+
#### Profile page example
|
|
117
124
|
|
|
118
125
|
```tsx
|
|
119
126
|
import { useStrivacity } from '@strivacity/sdk-react';
|
|
@@ -164,11 +171,9 @@ export default function Profile() {
|
|
|
164
171
|
}
|
|
165
172
|
```
|
|
166
173
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
The logout page handles user logout by terminating their session. The `postLogoutRedirectUri` parameter is optional and specifies where users should be redirected after logout. If not provided, users will be redirected to the identity provider's logout page.
|
|
174
|
+
#### Logout page example
|
|
170
175
|
|
|
171
|
-
This URI must be configured in the Admin Console as an allowed post-logout redirect URI
|
|
176
|
+
The `postLogoutRedirectUri` parameter is optional and specifies where users are redirected after logout. This URI must be configured in the Admin Console as an allowed post-logout redirect URI.
|
|
172
177
|
|
|
173
178
|
```tsx
|
|
174
179
|
import { useEffect } from 'react';
|
|
@@ -197,15 +202,34 @@ export default function Logout() {
|
|
|
197
202
|
}
|
|
198
203
|
```
|
|
199
204
|
|
|
200
|
-
####
|
|
205
|
+
#### Component example
|
|
201
206
|
|
|
202
|
-
|
|
207
|
+
```tsx
|
|
208
|
+
import { useStrivacity } from '@strivacity/sdk-react';
|
|
203
209
|
|
|
204
|
-
|
|
210
|
+
export default function Nav() {
|
|
211
|
+
const { isAuthenticated, idTokenClaims, login, logout } = useStrivacity();
|
|
212
|
+
const name = `${idTokenClaims?.given_name} ${idTokenClaims?.family_name}`;
|
|
213
|
+
|
|
214
|
+
return isAuthenticated ? (
|
|
215
|
+
<div>
|
|
216
|
+
<div>Welcome, {name}!</div>
|
|
217
|
+
<button onClick={() => logout()}>Logout</button>
|
|
218
|
+
</div>
|
|
219
|
+
) : (
|
|
220
|
+
<div>
|
|
221
|
+
<div>Not logged in</div>
|
|
222
|
+
<button onClick={() => login()}>Log in</button>
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Native mode
|
|
205
229
|
|
|
206
|
-
|
|
230
|
+
In `native` mode the `StyLoginRenderer` component renders the authentication UI inline using your custom widget components. You can define custom components for each input type; see [Example widgets](https://github.com/Strivacity/sdk-js/tree/main/apps/react/src/components/widgets).
|
|
207
231
|
|
|
208
|
-
The example widgets use SCSS for styling and Luxon for date handling
|
|
232
|
+
The example widgets use SCSS for styling and Luxon for date handling:
|
|
209
233
|
|
|
210
234
|
```bash
|
|
211
235
|
npm install sass luxon
|
|
@@ -242,110 +266,71 @@ export const widgets = {
|
|
|
242
266
|
};
|
|
243
267
|
```
|
|
244
268
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
##### Login page example
|
|
269
|
+
#### Login page example
|
|
248
270
|
|
|
249
|
-
The
|
|
250
|
-
|
|
251
|
-
This example demonstrates how to handle session management, implement callback functions for various authentication events, and manage URL parameters for session continuity.
|
|
271
|
+
The login page extracts `session_id` from the URL on load, cleans up the URL, and passes it to the renderer. When a `session_id` is present the renderer calls `startSession(sessionId)` to resume the existing flow instead of starting a new one.
|
|
252
272
|
|
|
253
273
|
```tsx
|
|
254
|
-
import {
|
|
274
|
+
import { useEffect, useState } from 'react';
|
|
255
275
|
import { useNavigate } from 'react-router';
|
|
256
|
-
import {
|
|
276
|
+
import { StyLoginRenderer, FallbackError, type LoginFlowState } from '@strivacity/sdk-react';
|
|
257
277
|
import { widgets } from '@/components/widgets';
|
|
258
278
|
|
|
259
279
|
export default function Login() {
|
|
260
280
|
const navigate = useNavigate();
|
|
261
|
-
const { options, login } = useStrivacity();
|
|
262
281
|
const [sessionId, setSessionId] = useState<string | null>(null);
|
|
263
282
|
|
|
264
|
-
/**
|
|
265
|
-
* Extract session_id from URL parameters and clean up the URL
|
|
266
|
-
* This is necessary for maintaining session state across external login providers
|
|
267
|
-
*/
|
|
268
283
|
useEffect(() => {
|
|
269
284
|
if (window.location.search !== '') {
|
|
270
285
|
const url = new URL(window.location.href);
|
|
271
|
-
|
|
272
|
-
setSessionId(sid);
|
|
286
|
+
setSessionId(url.searchParams.get('session_id'));
|
|
273
287
|
url.search = '';
|
|
274
288
|
window.history.replaceState({}, '', url.toString());
|
|
275
289
|
}
|
|
276
290
|
}, []);
|
|
277
291
|
|
|
278
|
-
/**
|
|
279
|
-
* Called when authentication is successful
|
|
280
|
-
* Redirects user to the profile page
|
|
281
|
-
*/
|
|
282
292
|
const onLogin = async () => {
|
|
283
293
|
await navigate('/profile');
|
|
284
294
|
};
|
|
285
295
|
|
|
286
|
-
/**
|
|
287
|
-
* Called when native flow cannot handle the authentication
|
|
288
|
-
* Falls back to redirect mode by navigating to the provided URL
|
|
289
|
-
* @param error - FallbackError containing the fallback URL and message
|
|
290
|
-
*/
|
|
291
296
|
const onFallback = (error: FallbackError) => {
|
|
292
297
|
if (error.url) {
|
|
293
|
-
console.log(`Fallback: ${error.url}`);
|
|
294
298
|
window.location.href = error.url.toString();
|
|
295
299
|
} else {
|
|
296
|
-
console.error(`FallbackError without URL: ${error.message}`);
|
|
297
300
|
alert(error);
|
|
298
301
|
}
|
|
299
302
|
};
|
|
300
303
|
|
|
301
|
-
/**
|
|
302
|
-
* Called when an error occurs during the authentication process
|
|
303
|
-
* @param error - Error message describing what went wrong
|
|
304
|
-
*/
|
|
305
304
|
const onError = (error: string) => {
|
|
306
|
-
console.error(`Error: ${error}`);
|
|
307
305
|
alert(error);
|
|
308
306
|
};
|
|
309
307
|
|
|
310
|
-
/**
|
|
311
|
-
* Called when the authentication flow wants to display a global message
|
|
312
|
-
* @param message - Message to display to the user
|
|
313
|
-
*/
|
|
314
308
|
const onGlobalMessage = (message: string) => {
|
|
315
309
|
alert(message);
|
|
316
310
|
};
|
|
317
311
|
|
|
318
|
-
/**
|
|
319
|
-
* Called when the authentication flow transitions between states
|
|
320
|
-
* Useful for tracking flow progress and inject custom logic such as logging or analytics
|
|
321
|
-
* @param params - Object containing previous and current flow states
|
|
322
|
-
*/
|
|
323
312
|
const onBlockReady = ({ previousState, state }: { previousState: LoginFlowState; state: LoginFlowState }) => {
|
|
324
313
|
console.log('previousState', previousState);
|
|
325
314
|
console.log('state', state);
|
|
326
315
|
};
|
|
327
316
|
|
|
328
317
|
return (
|
|
329
|
-
<
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
/>
|
|
339
|
-
</Suspense>
|
|
318
|
+
<StyLoginRenderer
|
|
319
|
+
widgets={widgets}
|
|
320
|
+
sessionId={sessionId}
|
|
321
|
+
onFallback={onFallback}
|
|
322
|
+
onLogin={() => void onLogin()}
|
|
323
|
+
onError={onError}
|
|
324
|
+
onGlobalMessage={onGlobalMessage}
|
|
325
|
+
onBlockReady={onBlockReady}
|
|
326
|
+
/>
|
|
340
327
|
);
|
|
341
328
|
}
|
|
342
329
|
```
|
|
343
330
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
The native mode callback page handles authentication responses when external identity providers redirect back to your application. This page checks for session IDs in the URL parameters and either continues the native flow or falls back to standard callback handling.
|
|
331
|
+
#### Callback page example
|
|
347
332
|
|
|
348
|
-
|
|
333
|
+
When a `session_id` is present in the URL the native flow is resumed by forwarding it to the login page. Otherwise the standard `handleCallback()` path is used:
|
|
349
334
|
|
|
350
335
|
```tsx
|
|
351
336
|
import { useEffect } from 'react';
|
|
@@ -353,7 +338,6 @@ import { useNavigate } from 'react-router';
|
|
|
353
338
|
import { useStrivacity } from '@strivacity/sdk-react';
|
|
354
339
|
|
|
355
340
|
export default function Callback() {
|
|
356
|
-
const query = globalThis?.window ? Object.fromEntries(new URLSearchParams(globalThis.window.location.search)) : {};
|
|
357
341
|
const navigate = useNavigate();
|
|
358
342
|
const { handleCallback } = useStrivacity();
|
|
359
343
|
|
|
@@ -375,45 +359,95 @@ export default function Callback() {
|
|
|
375
359
|
})();
|
|
376
360
|
}, []);
|
|
377
361
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
<
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
<h4>{query.error}</h4>
|
|
384
|
-
<p>{query.error_description}</p>
|
|
385
|
-
</div>
|
|
386
|
-
</section>
|
|
387
|
-
);
|
|
388
|
-
} else {
|
|
389
|
-
return (
|
|
390
|
-
<section>
|
|
391
|
-
<h1>Logging in...</h1>
|
|
392
|
-
</section>
|
|
393
|
-
);
|
|
394
|
-
}
|
|
362
|
+
return (
|
|
363
|
+
<section>
|
|
364
|
+
<h1>Logging in...</h1>
|
|
365
|
+
</section>
|
|
366
|
+
);
|
|
395
367
|
}
|
|
396
368
|
```
|
|
397
369
|
|
|
398
|
-
|
|
370
|
+
#### Entry page example
|
|
371
|
+
|
|
372
|
+
The entry page processes flows started by an external process (e.g. password reset) by calling `entry()` to extract the necessary parameters to resume the flow and forwarding them to the callback page:
|
|
373
|
+
|
|
374
|
+
```tsx
|
|
375
|
+
import { useEffect } from 'react';
|
|
376
|
+
import { useNavigate } from 'react-router';
|
|
377
|
+
import { useStrivacity } from '@strivacity/sdk-react';
|
|
378
|
+
|
|
379
|
+
export default function Entry() {
|
|
380
|
+
const navigate = useNavigate();
|
|
381
|
+
const { entry } = useStrivacity();
|
|
382
|
+
|
|
383
|
+
useEffect(() => {
|
|
384
|
+
(async () => {
|
|
385
|
+
try {
|
|
386
|
+
const data = await entry();
|
|
387
|
+
|
|
388
|
+
if (data && Object.keys(data).length > 0) {
|
|
389
|
+
await navigate(`/callback?${new URLSearchParams(data).toString()}`);
|
|
390
|
+
} else {
|
|
391
|
+
await navigate('/');
|
|
392
|
+
}
|
|
393
|
+
} catch (error) {
|
|
394
|
+
console.error('Entry failed:', error);
|
|
395
|
+
await navigate('/');
|
|
396
|
+
}
|
|
397
|
+
})();
|
|
398
|
+
}, []);
|
|
399
|
+
|
|
400
|
+
return (
|
|
401
|
+
<section>
|
|
402
|
+
<h1>Loading...</h1>
|
|
403
|
+
</section>
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
#### Profile page example
|
|
399
409
|
|
|
400
410
|
Same as the profile page example in redirect/popup mode.
|
|
401
411
|
|
|
402
|
-
|
|
412
|
+
#### Logout page example
|
|
403
413
|
|
|
404
414
|
Same as the logout page example in redirect/popup mode.
|
|
405
415
|
|
|
416
|
+
### Embedded mode
|
|
417
|
+
|
|
418
|
+
In `embedded` mode the `<sty-login>` web component (loaded via `bundle.js` from the cluster) handles rendering. Import the bundle at application startup to register the Strivacity web components:
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
import { createRoot } from 'react-dom/client';
|
|
422
|
+
import { StyAuthProvider } from '@strivacity/sdk-react';
|
|
423
|
+
|
|
424
|
+
void import(`${import.meta.env.VITE_ISSUER}/assets/components/bundle.js`);
|
|
425
|
+
|
|
426
|
+
createRoot(document.getElementById('app')!).render(
|
|
427
|
+
<StyAuthProvider
|
|
428
|
+
options={{
|
|
429
|
+
mode: 'embedded',
|
|
430
|
+
issuer: 'https://<YOUR_DOMAIN>',
|
|
431
|
+
scopes: ['openid', 'profile'],
|
|
432
|
+
clientId: '<YOUR_CLIENT_ID>',
|
|
433
|
+
redirectUri: '<YOUR_REDIRECT_URI>',
|
|
434
|
+
}}
|
|
435
|
+
>
|
|
436
|
+
<App />
|
|
437
|
+
</StyAuthProvider>,
|
|
438
|
+
);
|
|
439
|
+
```
|
|
440
|
+
|
|
406
441
|
## Logging
|
|
407
442
|
|
|
408
443
|
The SDK supports optional logging to help you debug authentication flows and monitor SDK behavior. You can enable the built-in console logger or provide your own custom logger implementation.
|
|
409
444
|
|
|
410
445
|
### Using the Default Logger
|
|
411
446
|
|
|
412
|
-
Enable the default console logger by adding the `logging` option
|
|
447
|
+
Enable the default console logger by adding the `logging` option:
|
|
413
448
|
|
|
414
449
|
```tsx
|
|
415
|
-
import {
|
|
416
|
-
import { StyAuthProvider, type SDKOptions, DefaultLogging } from '@strivacity/sdk-react';
|
|
450
|
+
import { StyAuthProvider, DefaultLogging, type SDKOptions } from '@strivacity/sdk-react';
|
|
417
451
|
|
|
418
452
|
const options: SDKOptions = {
|
|
419
453
|
mode: 'redirect',
|
|
@@ -421,23 +455,13 @@ const options: SDKOptions = {
|
|
|
421
455
|
scopes: ['openid', 'profile'],
|
|
422
456
|
clientId: '<YOUR_CLIENT_ID>',
|
|
423
457
|
redirectUri: '<YOUR_REDIRECT_URI>',
|
|
424
|
-
logging: DefaultLogging,
|
|
458
|
+
logging: DefaultLogging,
|
|
425
459
|
};
|
|
426
|
-
|
|
427
|
-
createRoot(document.getElementById('app')!).render(
|
|
428
|
-
<BrowserRouter>
|
|
429
|
-
<StyAuthProvider options={options}>
|
|
430
|
-
<Routes>{/* Your routes */}</Routes>
|
|
431
|
-
</StyAuthProvider>
|
|
432
|
-
</BrowserRouter>,
|
|
433
|
-
);
|
|
434
460
|
```
|
|
435
461
|
|
|
436
|
-
The default logger writes to the browser console and automatically prefixes messages with a correlation ID when available (via the `xEventId` property).
|
|
437
|
-
|
|
438
462
|
### Creating a Custom Logger
|
|
439
463
|
|
|
440
|
-
|
|
464
|
+
Implement the `SDKLogging` interface and pass your class to the `logging` option:
|
|
441
465
|
|
|
442
466
|
```typescript
|
|
443
467
|
import type { SDKLogging } from '@strivacity/sdk-react';
|
|
@@ -446,7 +470,6 @@ export class MyLogger implements SDKLogging {
|
|
|
446
470
|
xEventId?: string;
|
|
447
471
|
|
|
448
472
|
debug(message: string): void {
|
|
449
|
-
// Send to your logging pipeline
|
|
450
473
|
console.debug(this.xEventId ? `[${this.xEventId}] ${message}` : message);
|
|
451
474
|
}
|
|
452
475
|
|
|
@@ -464,161 +487,100 @@ export class MyLogger implements SDKLogging {
|
|
|
464
487
|
}
|
|
465
488
|
```
|
|
466
489
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
```tsx
|
|
470
|
-
import { StyAuthProvider } from '@strivacity/sdk-react';
|
|
471
|
-
import { MyLogger } from './logging/MyLogger';
|
|
472
|
-
|
|
473
|
-
const options: SDKOptions = {
|
|
474
|
-
mode: 'redirect',
|
|
475
|
-
issuer: 'https://<YOUR_DOMAIN>',
|
|
476
|
-
scopes: ['openid', 'profile'],
|
|
477
|
-
clientId: '<YOUR_CLIENT_ID>',
|
|
478
|
-
redirectUri: '<YOUR_REDIRECT_URI>',
|
|
479
|
-
logging: MyLogger, // Use your custom logger
|
|
480
|
-
};
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
### Logger Interface
|
|
484
|
-
|
|
485
|
-
The `SDKLogging` interface requires the following methods:
|
|
486
|
-
|
|
487
|
-
- **`debug(message: string): void`** - Log debug-level messages
|
|
488
|
-
- **`info(message: string): void`** - Log informational messages
|
|
489
|
-
- **`warn(message: string): void`** - Log warning messages
|
|
490
|
-
- **`error(message: string, error: Error): void`** - Log error messages with error objects
|
|
491
|
-
|
|
492
|
-
The optional `xEventId` property, when set by the SDK, provides a correlation ID to trace related log messages across the authentication flow.
|
|
490
|
+
The `SDKLogging` interface requires `debug`, `info`, `warn`, and `error` methods. The optional `xEventId` property, when set by the SDK, provides a correlation ID to trace related log messages across the authentication flow.
|
|
493
491
|
|
|
494
|
-
|
|
492
|
+
## API Documentation
|
|
495
493
|
|
|
496
|
-
|
|
494
|
+
### `useStrivacity` hook
|
|
497
495
|
|
|
498
496
|
```typescript
|
|
499
497
|
useStrivacity<T extends PopupContext | RedirectContext | NativeContext>(): T;
|
|
500
498
|
```
|
|
501
499
|
|
|
502
|
-
|
|
500
|
+
The hook returns a different context type depending on the `mode` configured in `StyAuthProvider`.
|
|
503
501
|
|
|
504
|
-
**
|
|
502
|
+
**Shared properties (all modes)**
|
|
505
503
|
|
|
506
|
-
- **`
|
|
507
|
-
- **`
|
|
508
|
-
- **`
|
|
509
|
-
- **`
|
|
510
|
-
- **`
|
|
511
|
-
- **`
|
|
512
|
-
- **`
|
|
504
|
+
- **`sdk: RedirectFlow | PopupFlow | NativeFlow`**: The underlying SDK flow instance.
|
|
505
|
+
- **`loading: boolean`**: `true` while the session is being initialized.
|
|
506
|
+
- **`options: SDKOptions`**: The configured SDK options.
|
|
507
|
+
- **`isAuthenticated: boolean`**: `true` when the user has a valid session.
|
|
508
|
+
- **`idTokenClaims: IdTokenClaims | null`**: Claims from the ID token, or `null` if not authenticated.
|
|
509
|
+
- **`accessToken: string | null`**: The current access token.
|
|
510
|
+
- **`refreshToken: string | null`**: The current refresh token.
|
|
511
|
+
- **`accessTokenExpired: boolean`**: `true` when the access token has expired.
|
|
512
|
+
- **`accessTokenExpirationDate: number | null`**: Expiration timestamp (Unix seconds) of the access token.
|
|
513
513
|
|
|
514
514
|
---
|
|
515
515
|
|
|
516
|
-
Type: `RedirectContext
|
|
517
|
-
Represents the available methods for Redirect-based interactions.
|
|
516
|
+
**Type: `RedirectContext`**
|
|
518
517
|
|
|
519
|
-
- **`login(options?: LoginOptions): Promise<void>`**: Initiates
|
|
520
|
-
|
|
521
|
-
- **`
|
|
522
|
-
|
|
523
|
-
- **`
|
|
524
|
-
- **`
|
|
525
|
-
- **`
|
|
526
|
-
- `options` (optional): Configuration options for logout.
|
|
527
|
-
- **`handleCallback(url?: string): Promise<void>`**: Handles the callback after a redirect-based authentication or token exchange.
|
|
528
|
-
- `url` (optional): The URL to handle for the callback.
|
|
518
|
+
- **`login(options?: LoginOptions): Promise<void>`**: Initiates login by redirecting to the identity provider.
|
|
519
|
+
- **`register(options?: RegisterOptions): Promise<void>`**: Initiates registration using a redirect flow.
|
|
520
|
+
- **`refresh(): Promise<void>`**: Refreshes the user's session.
|
|
521
|
+
- **`revoke(): Promise<void>`**: Revokes the current session tokens.
|
|
522
|
+
- **`logout(options?: LogoutOptions): Promise<void>`**: Logs the user out via redirect.
|
|
523
|
+
- **`handleCallback(url?: string): Promise<void>`**: Processes the authorization callback after redirect.
|
|
524
|
+
- **`entry(): Promise<Record<string, string>>`**: Processes an externally-initiated flow URL and returns the parameters needed to resume the flow.
|
|
529
525
|
|
|
530
526
|
---
|
|
531
527
|
|
|
532
|
-
Type: `PopupContext
|
|
533
|
-
Represents the available methods for Popup-based interactions.
|
|
528
|
+
**Type: `PopupContext`**
|
|
534
529
|
|
|
535
|
-
- **`login(options?: LoginOptions): Promise<void>`**: Initiates
|
|
536
|
-
|
|
537
|
-
- **`
|
|
538
|
-
|
|
539
|
-
- **`
|
|
540
|
-
- **`
|
|
541
|
-
- **`
|
|
542
|
-
- `options` (optional): Configuration options for logout.
|
|
543
|
-
- **`handleCallback(url?: string): Promise<void>`**: Handles the callback after a popup-based authentication or token exchange.
|
|
544
|
-
- `url` (optional): The URL to handle for the callback.
|
|
530
|
+
- **`login(options?: LoginOptions): Promise<void>`**: Initiates login using a popup window.
|
|
531
|
+
- **`register(options?: RegisterOptions): Promise<void>`**: Initiates registration using a popup.
|
|
532
|
+
- **`refresh(): Promise<void>`**: Refreshes the user's session.
|
|
533
|
+
- **`revoke(): Promise<void>`**: Revokes the current session tokens.
|
|
534
|
+
- **`logout(options?: LogoutOptions): Promise<void>`**: Logs the user out via popup.
|
|
535
|
+
- **`handleCallback(url?: string): Promise<void>`**: Processes the authorization callback.
|
|
536
|
+
- **`entry(): Promise<Record<string, string>>`**: Processes an externally-initiated flow URL.
|
|
545
537
|
|
|
546
538
|
---
|
|
547
539
|
|
|
548
|
-
Type: `NativeContext
|
|
549
|
-
Represents the available methods for native-based interactions.
|
|
540
|
+
**Type: `NativeContext`**
|
|
550
541
|
|
|
551
|
-
- **`login(options?: LoginOptions): Promise<NativeFlowHandler>`**: Initiates
|
|
552
|
-
|
|
553
|
-
- **`register(options?: RegisterOptions): Promise<NativeFlowHandler>`**: Registers a new user using a native flow.
|
|
554
|
-
- `options` (optional): Configuration options for registration.
|
|
542
|
+
- **`login(options?: LoginOptions): Promise<NativeFlowHandler>`**: Initiates login using the native flow.
|
|
543
|
+
- **`register(options?: RegisterOptions): Promise<NativeFlowHandler>`**: Initiates registration using the native flow.
|
|
555
544
|
- **`refresh(): Promise<void>`**: Refreshes the user's session.
|
|
556
545
|
- **`revoke(): Promise<void>`**: Revokes the current session tokens.
|
|
557
|
-
- **`logout(options?: LogoutOptions): Promise<void>`**: Logs
|
|
558
|
-
|
|
559
|
-
- **`
|
|
560
|
-
- `url` (optional): The URL to handle for the callback.
|
|
561
|
-
|
|
562
|
-
#### `StyLoginRenderer` component
|
|
563
|
-
|
|
564
|
-
The `StyLoginRenderer` component is used in native mode to render the authentication UI directly within your application. It provides a fully customizable login experience using your own UI components.
|
|
546
|
+
- **`logout(options?: LogoutOptions): Promise<void>`**: Logs the user out via redirect.
|
|
547
|
+
- **`handleCallback(url?: string): Promise<void>`**: Processes the authorization callback.
|
|
548
|
+
- **`entry(): Promise<Record<string, string>>`**: Processes an externally-initiated flow URL.
|
|
565
549
|
|
|
566
|
-
|
|
567
|
-
StyLoginRenderer: React.FC<{
|
|
568
|
-
params?: NativeParams;
|
|
569
|
-
widgets?: PartialRecord<WidgetType, React.ComponentType<any>>;
|
|
570
|
-
sessionId?: string | null;
|
|
571
|
-
onLogin?: (claims?: IdTokenClaims | null) => void;
|
|
572
|
-
onFallback?: (error: FallbackError) => void;
|
|
573
|
-
onError?: (error: any) => void;
|
|
574
|
-
onGlobalMessage?: (message: string) => void;
|
|
575
|
-
onBlockReady?: ({ previousState, state }: { previousState: LoginFlowState; state: LoginFlowState }) => void;
|
|
576
|
-
}>;
|
|
577
|
-
```
|
|
578
|
-
|
|
579
|
-
**Properties**
|
|
580
|
-
|
|
581
|
-
- **`params?: NativeParams`** (optional): Additional parameters to pass to the native login flow. These parameters can include custom configuration options for the authentication process.
|
|
582
|
-
|
|
583
|
-
- **`widgets?: PartialRecord<WidgetType, React.ComponentType<any>>`** (optional): A collection of React components that define the UI widgets used in the authentication flow. Each widget type (input, button, layout, etc.) can be customized with your own components.
|
|
550
|
+
---
|
|
584
551
|
|
|
585
|
-
|
|
552
|
+
### `StyLoginRenderer` component
|
|
586
553
|
|
|
587
|
-
|
|
554
|
+
Used in `native` mode to render the authentication UI with your own widget components.
|
|
588
555
|
|
|
589
|
-
|
|
556
|
+
**Props**
|
|
590
557
|
|
|
591
|
-
- **`
|
|
558
|
+
- **`params?: NativeParams`**: Additional parameters for the native login flow.
|
|
559
|
+
- **`widgets?: PartialRecord<WidgetType, React.ComponentType>`**: Custom React components for each widget type used in the flow.
|
|
560
|
+
- **`sessionId?: string | null`**: Session ID for resuming an existing authentication session.
|
|
592
561
|
|
|
593
|
-
|
|
562
|
+
**Event callbacks**
|
|
594
563
|
|
|
595
|
-
- **`
|
|
564
|
+
- **`onLogin`**: Called on successful authentication. Receives `IdTokenClaims | null`.
|
|
565
|
+
- **`onFallback`**: Called when the native flow needs to fall back to redirect. Receives `FallbackError` with a fallback URL.
|
|
566
|
+
- **`onError`**: Called when an error occurs during authentication.
|
|
567
|
+
- **`onGlobalMessage`**: Called when the flow wants to display a global message (e.g. account lockout warning).
|
|
568
|
+
- **`onBlockReady`**: Called on flow state transitions. Receives `{ previousState: LoginFlowState; state: LoginFlowState }`. Useful for analytics and custom logging.
|
|
596
569
|
|
|
597
|
-
|
|
570
|
+
## Vulnerability Reporting
|
|
598
571
|
|
|
599
|
-
The
|
|
572
|
+
The [Guidelines for responsible disclosure](https://www.strivacity.com/report-a-security-issue) details the procedure for disclosing security issues. Please do not report security vulnerabilities on the public issue tracker.
|
|
600
573
|
|
|
601
|
-
|
|
602
|
-
- `date`: For date input fields
|
|
603
|
-
- `input`: For text input fields
|
|
604
|
-
- `layout`: For layout containers and form structure
|
|
605
|
-
- `loading`: For loading indicators
|
|
606
|
-
- `multiSelect`: For multi-select dropdown fields
|
|
607
|
-
- `passcode`: For passcode input fields
|
|
608
|
-
- `password`: For password input fields
|
|
609
|
-
- `phone`: For phone number input fields
|
|
610
|
-
- `select`: For single-select dropdown fields
|
|
611
|
-
- `static`: For static text and display elements
|
|
612
|
-
- `submit`: For form submission buttons
|
|
574
|
+
## License
|
|
613
575
|
|
|
614
|
-
|
|
576
|
+
@strivacity/sdk-react is available under the MIT License. See the [LICENSE](https://github.com/Strivacity/sdk-js/blob/main/LICENSE) file for more info.
|
|
615
577
|
|
|
616
|
-
|
|
578
|
+
## Contributing
|
|
617
579
|
|
|
618
|
-
[
|
|
580
|
+
Please see our [contributing guide](https://github.com/Strivacity/sdk-js/blob/main/CONTRIBUTING.md).
|
|
619
581
|
|
|
620
582
|
## Migrating to v3.0
|
|
621
583
|
|
|
622
584
|
### Entry API Major Changes
|
|
623
585
|
|
|
624
|
-
Strivacity SDK's `entry()` API now returns a structured object instead of a plain string.
|
|
586
|
+
Strivacity SDK's `entry()` API now returns a structured object instead of a plain string. Check the example above in the usage section for more details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strivacity/sdk-react",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Strivacity React SDK client",
|
|
6
6
|
"author": "strivacity <opensource@strivacity.com>",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "https://github.com/Strivacity/sdk-js"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@strivacity/sdk-core": "3.0.0
|
|
12
|
+
"@strivacity/sdk-core": "3.0.0"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"react": ">=18"
|