@forgerock/login-widget 1.3.0 → 2.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/LICENSE +1 -1
- package/README.md +243 -530
- package/dist/browser-DluKPU6C.js +1500 -0
- package/dist/browser-DluKPU6C.js.map +1 -0
- package/dist/core/captcha.config.d.ts +15 -0
- package/dist/core/component.store.d.ts +40 -0
- package/dist/core/interfaces.d.ts +12 -0
- package/dist/core/journey/config.store.d.ts +50 -0
- package/dist/core/journey/journey.interfaces.d.ts +91 -0
- package/dist/core/links.store.d.ts +26 -0
- package/dist/core/locale.store.d.ts +417 -0
- package/dist/core/oauth/oauth.store.d.ts +33 -0
- package/dist/core/oidc/oidc.store.d.ts +45 -0
- package/dist/core/protect/protect.store.d.ts +77 -0
- package/dist/core/style.store.d.ts +182 -0
- package/dist/core/user/user.store.d.ts +32 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +25002 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +72 -0
- package/dist/signals-sdk-DbtqPU1J.js +12331 -0
- package/dist/signals-sdk-DbtqPU1J.js.map +1 -0
- package/dist/stats.html +4950 -0
- package/dist/types.d.ts +79 -0
- package/dist/widget.css +1 -0
- package/dist/widget.iife.js +94 -0
- package/dist/widget.iife.js.map +1 -0
- package/package.json +66 -8
- package/CHANGELOG.md +0 -586
- package/index.cjs +0 -47270
- package/index.cjs.map +0 -1
- package/index.d.ts +0 -2565
- package/index.js +0 -47260
- package/index.js.map +0 -1
- package/types.d.ts +0 -2568
- package/widget.css +0 -1881
package/README.md
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/@forgerock/login-widget)
|
|
3
2
|
[](http://commitizen.github.io/cz-cli/)
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://github.com/ForgeRock">
|
|
6
|
+
<img src="https://www.forgerock.com/themes/custom/forgerock/images/fr-logo-horz-color.svg" alt="ForgeRock Logo">
|
|
7
|
+
</a>
|
|
8
|
+
<h2 align="center">ForgeRock Login Widget</h2>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@forgerock/login-widget">npm</a>
|
|
11
|
+
·
|
|
12
|
+
<a href="#support">Support</a>
|
|
13
|
+
·
|
|
14
|
+
<a href="https://backstage.forgerock.com/docs/sdks/latest/javascript/webloginframework.html">Docs</a>
|
|
15
|
+
</p>
|
|
16
|
+
<hr/>
|
|
17
|
+
</p>
|
|
5
18
|
|
|
6
19
|
## Table of Contents
|
|
7
20
|
|
|
8
21
|
- [Overview](#overview)
|
|
9
22
|
- [Requirements](#requirements)
|
|
10
|
-
- [Quick Start
|
|
11
|
-
- [
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [Requesting values from the ForgeRock platform](#requesting-values-from-the-forgerock-platform)
|
|
21
|
-
- [User Promises](#using-promises)
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
24
|
+
- [Install](#install)
|
|
25
|
+
- [Add CSS](#add-css)
|
|
26
|
+
- [Mount the Widget](#mount-the-widget)
|
|
27
|
+
- [Observables Pattern](#observables-pattern)
|
|
28
|
+
- [Subscribe to Events](#subscribe-to-events)
|
|
29
|
+
- [Unsubscribe](#unsubscribe)
|
|
30
|
+
- [Get Current Values](#get-current-values)
|
|
31
|
+
- [Request Fresh Values](#request-fresh-values)
|
|
32
|
+
- [Use Promises](#use-promises)
|
|
22
33
|
- [Complete Widget API](#complete-widget-api)
|
|
23
34
|
- [Widget](#widget)
|
|
24
35
|
- [Configuration](#configuration)
|
|
@@ -26,92 +37,66 @@
|
|
|
26
37
|
- [Component](#component)
|
|
27
38
|
- [User](#user)
|
|
28
39
|
- [Request](#request)
|
|
29
|
-
- [Styling
|
|
30
|
-
- [Links
|
|
31
|
-
- [Content
|
|
32
|
-
- [
|
|
40
|
+
- [Styling Configuration](#styling-configuration)
|
|
41
|
+
- [Links Configuration](#links-configuration)
|
|
42
|
+
- [Content Configuration](#content-configuration)
|
|
43
|
+
- [Supported Callbacks](#supported-callbacks)
|
|
33
44
|
- [Disclaimer](#disclaimer)
|
|
34
45
|
- [License](#license)
|
|
35
46
|
|
|
36
47
|
## Overview
|
|
37
48
|
|
|
38
|
-
The Login Widget
|
|
39
|
-
|
|
40
|
-
This Widget uses the ForgeRock JavaScript SDK internally. It adds a UI rendering layer on top of the SDK to help eliminate the need to develop and maintain the UI components necessary for providing complex authentication flows. Although this rendering layer is developed with Svelte and Tailwind, it is "compiled away" and has no runtime dependencies. It is library and framework agnostic.
|
|
49
|
+
The Login Widget is an all-inclusive UI component for handling login, registration, and related user flows in any modern JavaScript app. It works with React, Vue, Angular, Svelte, or vanilla JavaScript — it does not currently support Node.js or server-side rendering (SSR).
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
The widget uses [Journey Client](https://developer.pingidentity.com/orchsdks/journey/usage/javascript/index.html) for journey execution, and the [ForgeRock SDK for JavaScript](https://docs.pingidentity.com/sdks/latest/sdks/tutorials/javascript/index.html) for OAuth/OIDC tokens, user info, and request utilities. It adds a UI rendering layer on top of these SDKs to eliminate the need to develop and maintain UI components for complex authentication flows. Although this rendering layer is developed with Svelte and Tailwind, both are "compiled away" and have no runtime dependencies. The resulting widget is library- and framework-agnostic.
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
2. **Inline** type: this is just the form elements themselves, no container. This component is intended to be rendered _inside_ your app's controlled DOM.
|
|
53
|
+
The widget can be rendered in two form factors:
|
|
46
54
|
|
|
47
|
-
|
|
55
|
+
1. **Modal** (default): Renders form elements inside a modal dialog that opens and closes. Mounted _outside_ your app's controlled DOM.
|
|
56
|
+
2. **Inline**: Just the form elements with no container. Mounted _inside_ your app's controlled DOM.
|
|
48
57
|
|
|
49
|
-
|
|
58
|
+
Both form factors provide the same authentication, OAuth/OIDC, and user features. Start with Modal — it provides the quickest path to adding login/registration with minimal disruption to your existing codebase.
|
|
50
59
|
|
|
51
60
|
## Requirements
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
- An ECMAScript module or CommonJS enabled client-side JavaScript app
|
|
63
|
+
- A modern, fully-supported browser: Chrome, Firefox, Safari, or Chromium Edge
|
|
55
64
|
|
|
56
|
-
|
|
65
|
+
**Not supported**: Internet Explorer, Legacy Edge, WebView, Electron, and other modified browser-like environments.
|
|
57
66
|
|
|
58
|
-
## Quick Start
|
|
67
|
+
## Quick Start
|
|
59
68
|
|
|
60
|
-
###
|
|
69
|
+
### Install
|
|
61
70
|
|
|
62
71
|
```shell
|
|
63
72
|
npm install @forgerock/login-widget
|
|
64
73
|
```
|
|
65
74
|
|
|
66
|
-
###
|
|
67
|
-
|
|
68
|
-
There are a few ways to add the Widget's CSS to your product:
|
|
69
|
-
|
|
70
|
-
1. Import it into your JavaScript project as a module
|
|
71
|
-
2. Import it using a CSS preprocessor, like Sass, Less or PostCSS
|
|
72
|
-
3. Copy the CSS file from the package and link it into your HTML
|
|
73
|
-
|
|
74
|
-
If you decide to import the CSS into your JavaScript, make sure your bundler knows how to import and process the CSS as a module. If using a CSS preprocessor, ensure you configure your preprocessor to access files from within your `package/` directory.
|
|
75
|
+
### Add CSS
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Importing into your JavaScript:
|
|
77
|
+
Import into your JavaScript:
|
|
79
78
|
|
|
80
79
|
```js
|
|
81
|
-
// app.js
|
|
82
80
|
import '@forgerock/login-widget/widget.css';
|
|
83
81
|
```
|
|
84
82
|
|
|
85
|
-
|
|
83
|
+
Import into your CSS:
|
|
86
84
|
|
|
87
85
|
```css
|
|
88
|
-
/* style.css */
|
|
89
86
|
@import '@forgerock/login-widget/widget.css';
|
|
90
87
|
```
|
|
91
88
|
|
|
92
|
-
|
|
89
|
+
Or link in HTML (copy the CSS file from the npm module into your static files):
|
|
93
90
|
|
|
94
91
|
```html
|
|
95
|
-
|
|
96
|
-
<!doctype html>
|
|
97
|
-
<html lang="en">
|
|
98
|
-
<head>
|
|
99
|
-
<!-- ... -->
|
|
100
|
-
<link rel="stylesheet" href="/path/to/file/widget.css" />
|
|
101
|
-
</head>
|
|
102
|
-
<body>
|
|
103
|
-
<!-- ... -->
|
|
104
|
-
</body>
|
|
105
|
-
</html>
|
|
92
|
+
<link rel="stylesheet" href="/path/to/file/widget.css" />
|
|
106
93
|
```
|
|
107
94
|
|
|
108
|
-
#### Controlling the CSS
|
|
109
|
-
|
|
110
|
-
Though not required, this helps solve common style issues that may pop up related to the CSS cascade. Using `@layer` will ensure the browser applies the CSS in the way you intend, regardless of the order you import or declare the CSS in your project. You can [read more about this new browser feature in the Mozilla docs](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer).
|
|
95
|
+
#### Controlling the CSS Cascade
|
|
111
96
|
|
|
112
|
-
|
|
97
|
+
Though not required, using `@layer` ensures the browser applies CSS in the intended order regardless of import order. [Read more about @layer](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer).
|
|
113
98
|
|
|
114
|
-
1. Wrap your
|
|
99
|
+
1. Wrap your CSS in a layer:
|
|
115
100
|
|
|
116
101
|
```css
|
|
117
102
|
@layer app {
|
|
@@ -119,14 +104,11 @@ Steps recommended:
|
|
|
119
104
|
}
|
|
120
105
|
```
|
|
121
106
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
2. Declare the order of layers in your index HTML file before any CSS is loaded:
|
|
107
|
+
2. Declare layer order in your HTML before any CSS loads:
|
|
125
108
|
|
|
126
109
|
```html
|
|
127
110
|
<style type="text/css">
|
|
128
111
|
@layer app;
|
|
129
|
-
/* List the Widget layers last */
|
|
130
112
|
@layer 'fr-widget.base';
|
|
131
113
|
@layer 'fr-widget.utilities';
|
|
132
114
|
@layer 'fr-widget.components';
|
|
@@ -134,246 +116,66 @@ Steps recommended:
|
|
|
134
116
|
</style>
|
|
135
117
|
```
|
|
136
118
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
### Using the Widget component
|
|
140
|
-
|
|
141
|
-
#### Add element to your HTML file
|
|
119
|
+
Widget CSS is fully namespaced — it will not overwrite your app's CSS unless you use the same selector naming convention.
|
|
142
120
|
|
|
143
|
-
|
|
121
|
+
### Mount the Widget
|
|
144
122
|
|
|
145
|
-
|
|
123
|
+
Add a dedicated element to your HTML file as a direct child of `<body>`, separate from your main app root:
|
|
146
124
|
|
|
147
125
|
```html
|
|
148
|
-
|
|
149
|
-
<
|
|
150
|
-
<
|
|
151
|
-
|
|
152
|
-
</head>
|
|
153
|
-
<body>
|
|
154
|
-
<!-- Root element for main app -->
|
|
155
|
-
<div id="root"></div>
|
|
156
|
-
|
|
157
|
-
<!-- Root element for Widget -->
|
|
158
|
-
<div id="widget-root"></div>
|
|
159
|
-
|
|
160
|
-
<!-- scripts ... -->
|
|
161
|
-
</body>
|
|
162
|
-
</html>
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
NOTE: We do not recommend mounting the Widget on a dynamic element that's inside your main application's "controlled DOM". If you're not experienced with mixed rendering types in the Virtual DOM, you may find this challenging at first. So, to ensure success at the start, manually adding it outside of your application's controlled DOM is best. It's recommended to put the element for Widget mounting in your static HTML file as a child of the `<body>` tag.
|
|
166
|
-
|
|
167
|
-
#### Instantiate the Widget
|
|
168
|
-
|
|
169
|
-
You can import the Widget into your app wherever you would like as a modal dialog (aka "lightbox"), this form factor is the default. Once the Widget is imported, you will need to instantiate it.
|
|
170
|
-
|
|
171
|
-
```js
|
|
172
|
-
// As modal dialog
|
|
173
|
-
import Widget from '@forgerock/login-widget';
|
|
174
|
-
|
|
175
|
-
// ...
|
|
176
|
-
|
|
177
|
-
// Grab the root element added to your HTML file
|
|
178
|
-
const widgetRootEl = document.getElementById('widget-root');
|
|
179
|
-
|
|
180
|
-
// Instantiate Widget with the `new` keyword
|
|
181
|
-
new Widget({
|
|
182
|
-
target: widgetRootEl, // Any existing element from static HTML file
|
|
183
|
-
});
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
This instantiates the component and mounts the Widget into the DOM. By default, it will be the Modal version, and will therefore be be hidden at first. Component controls will be discussed shortly.
|
|
187
|
-
|
|
188
|
-
Note: [See additional documentation about configuring the JS SDK](https://backstage.forgerock.com/docs/sdks/3.3/javascript/configuring/configuring-forgerock-sdk-settings-for-your-javascript-app.html).
|
|
189
|
-
|
|
190
|
-
#### The component lifecycle
|
|
191
|
-
|
|
192
|
-
When using the default Modal form factor, the first thing you'll want to do is open it. To do this, you need to import the `component` function. Executing this function will return a `componentEvents` object, you can name this whatever you'd like. Calling the `componentEvents.open` method will trigger the modal to animate into view.
|
|
193
|
-
|
|
194
|
-
```js
|
|
195
|
-
import Widget, { component } from '@forgerock/login-widget';
|
|
196
|
-
|
|
197
|
-
// ...
|
|
198
|
-
|
|
199
|
-
const componentEvents = component();
|
|
200
|
-
|
|
201
|
-
new Widget({ target: widgetRootEl }); // Instantiate the Widget
|
|
202
|
-
|
|
203
|
-
componentEvents.open(); // Ensure this is called after the Widget has been instantiated
|
|
204
|
-
|
|
205
|
-
// A more realistic pattern is calling this within a button click
|
|
206
|
-
const loginButton = document.getElementById('loginButton');
|
|
207
|
-
loginButton.addEventListener('click', () => {
|
|
208
|
-
componentEvents.open();
|
|
209
|
-
});
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
NOTE: Opening the modal by itself will just reveal the modal with a loading spinner. This is because the Widget has no data to inform it on what to render. We will solve this in the "Starting a journey" section.
|
|
213
|
-
|
|
214
|
-
In addition to being able to open the modal, you'll likely want to know when it's mounted, or closed by the user or upon completed authentication. This is done via the same API. A `subscribe` method will be on this `componentEvents` object (which technically makes this an observable), and all component related events will trigger the `subscribe` function to be called passing the `event` state to your callback function.
|
|
215
|
-
|
|
216
|
-
```js
|
|
217
|
-
componentEvents.subscribe((event) => {
|
|
218
|
-
if (event.mounted) {
|
|
219
|
-
console.log('Widget is mounted!');
|
|
220
|
-
}
|
|
221
|
-
});
|
|
126
|
+
<body>
|
|
127
|
+
<div id="root"></div>
|
|
128
|
+
<div id="widget-root"></div>
|
|
129
|
+
</body>
|
|
222
130
|
```
|
|
223
131
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
```js
|
|
227
|
-
componentEvents.subscribe((event) => {
|
|
228
|
-
if (event.mounted) {
|
|
229
|
-
console.log('Widget is mounted!');
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (event.open === false) {
|
|
233
|
-
console.log(event.reason); // The reason for closing will be provided
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
```
|
|
132
|
+
> **Tip**: Do not mount the modal form factor on a dynamic element inside your app's Virtual DOM. Hard-code it in your static HTML file.
|
|
237
133
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
#### Configuring the Widget
|
|
241
|
-
|
|
242
|
-
Before the Widget can interact with the ForgeRock platform, it will need to be configured. We have a `configuration` function for this API.
|
|
243
|
-
|
|
244
|
-
First, import the `configuration` function from the module and call it to receive the config API. This API has a single method called `set`. Let's start with the minimal configuration.
|
|
134
|
+
Import, configure, and instantiate:
|
|
245
135
|
|
|
246
136
|
```js
|
|
247
|
-
import {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
137
|
+
import Widget, { configure, journey } from '@forgerock/login-widget';
|
|
138
|
+
|
|
139
|
+
// 1. Configure — async; awaiting it ensures both clients are ready before use
|
|
140
|
+
await configure({
|
|
141
|
+
// REQUIRED — the well-known URL, shared by the journey and OIDC clients
|
|
142
|
+
wellknown: 'https://your-tenant.forgeblocks.com/am/oauth2/alpha/.well-known/openid-configuration',
|
|
143
|
+
// REQUIRED if you use OAuth/OIDC tokens, user info, or logout
|
|
144
|
+
oidcClient: {
|
|
145
|
+
clientId: 'YourOauthClient',
|
|
146
|
+
redirectUri: `${window.location.origin}/callback`,
|
|
147
|
+
scope: 'openid profile email',
|
|
256
148
|
},
|
|
257
149
|
});
|
|
258
|
-
```
|
|
259
150
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
For the Widget to display the appropriate form fields, a request needs to be made to ForgeRock for the first step of the journey. To render the first step, you'll need to import the `journey` function and execute it to receive the `journeyEvents` object (you'll notice this is a pattern throughout the Widget API). Once you have this `journeyEvents` object, you can call the `journeyEvents.start` method. Calling `start` makes the initial request to the ForgeRock server for the initial form fields.
|
|
265
|
-
|
|
266
|
-
```js
|
|
267
|
-
import Widget, { journey } from '@forgerock/login-widget';
|
|
151
|
+
// 2. Instantiate
|
|
152
|
+
const widgetRootEl = document.getElementById('widget-root');
|
|
153
|
+
new Widget({ target: widgetRootEl });
|
|
268
154
|
|
|
155
|
+
// 3. Start a journey
|
|
269
156
|
const journeyEvents = journey();
|
|
270
|
-
|
|
271
|
-
// ...
|
|
272
|
-
|
|
273
|
-
new Widget({
|
|
274
|
-
target: widgetRootEl, // Any existing element in the DOM
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// Ensure you call `.start` *AFTER* instantiating the Widget
|
|
278
157
|
journeyEvents.start();
|
|
279
|
-
|
|
280
|
-
// OR, in a more typical situation, call on button click
|
|
281
|
-
buttonElement.addEventListener('click', (event) => {
|
|
282
|
-
journeyEvents.start();
|
|
283
|
-
});
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
NOTE: This `journeyEvents.start` method can be called anywhere in your application, or anytime, as long as it's _after_ calling the configuration's `set` method and _after_ instantiating the Widget (which mounts it to the DOM) as both are requirements for a journey.
|
|
287
|
-
|
|
288
|
-
#### Getting a session
|
|
289
|
-
|
|
290
|
-
By default, the Widget is going to do more than just get a user's session. It will also get OAuth/OIDC tokens and retrieve user information. But, let's start small.
|
|
291
|
-
|
|
292
|
-
Let's only ask for session information, and disable OAuth and user info. This will simplify our initial setup. To do this, call the `journey` function passing false for `oauth` and `user`.
|
|
293
|
-
|
|
294
|
-
```js
|
|
295
|
-
const journeyEvents = journey({ oauth: false, user: false });
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
Now, when you call `journeyEvents.start()`, you will only get session information upon successful authentication.
|
|
299
|
-
|
|
300
|
-
NOTE: It's also worth nothing that if you don't declare what journey you want to use, the ForgeRock platform will use what is marked as the default journey, usually just the basic Login journey.
|
|
301
|
-
|
|
302
|
-
#### Listening for journey completion
|
|
303
|
-
|
|
304
|
-
Use the `journeyEvents.subscribe` method (this is the observable part) to know when a user has completed their journey. Pass a callback function into this method to run on journey related events (there will be a quite a few of them). You will receive an event object with a lot of data in it. You'll want to conditionally check for the events you're interested in and ignore what you don't need.
|
|
305
|
-
|
|
306
|
-
```js
|
|
307
|
-
// ...
|
|
308
|
-
|
|
309
|
-
journeyEvents.subscribe((event) => {
|
|
310
|
-
// Will be called multiple times, so narrowing what you're interested in is important
|
|
311
|
-
if (event.journey.successful) {
|
|
312
|
-
// Will log once to the console when authentication has succeeded and returned session data
|
|
313
|
-
console.log(event);
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
158
|
```
|
|
317
159
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
### Want to inline the Widget into your app (no modal)?
|
|
160
|
+
> **Tip**: `configure()` is async — always `await` it at the top level of your application (`index.js` or `app.js`) before calling `journey().start()` or any other Widget API. This ensures both the OIDC and journey clients are fully constructed before any fetch is attempted.
|
|
321
161
|
|
|
322
|
-
|
|
162
|
+
## Observables Pattern
|
|
323
163
|
|
|
324
|
-
|
|
164
|
+
Most Widget APIs are asynchronous and use an event-centric observable pattern. The widget uses Svelte's simplified, standard observable implementation called a "store" — these are embedded in the widget and are not a dependency your app needs to manage.
|
|
325
165
|
|
|
326
|
-
|
|
166
|
+
[Read more about the Svelte store contract](https://svelte.dev/docs#component-format-script-4-prefix-stores-with-$-to-access-their-values-store-contract).
|
|
327
167
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
```js
|
|
331
|
-
// As inline
|
|
332
|
-
import Widget from '@forgerock/login-widget';
|
|
333
|
-
|
|
334
|
-
// ...
|
|
335
|
-
|
|
336
|
-
new Widget({
|
|
337
|
-
target: mountedDomElement, // ensure this is a reference to a real DOM element
|
|
338
|
-
props: {
|
|
339
|
-
type: 'inline', // Your JS SDK configuration; see below
|
|
340
|
-
},
|
|
341
|
-
});
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
This mounts your Widget into the DOM. If you choose the modal version, it will be hidden at first.
|
|
345
|
-
|
|
346
|
-
Note: [See additional documentation about configuring the JS SDK](https://backstage.forgerock.com/docs/sdks/3.3/javascript/configuring/configuring-forgerock-sdk-settings-for-your-javascript-app.html).
|
|
347
|
-
|
|
348
|
-
## What you need to know
|
|
349
|
-
|
|
350
|
-
Most of this Widget's APIs are asynchronous. As with many things in the JavaScript world, there are multiple patterns to handle asynchronous behavior. We've decided to centralize the Widget's APIs around the event-centric, Observable pattern. Since this Widget is powered by Svelte's compiler, we use Svelte's simplified, but standard Observable implementation called a "store". You can [read more about the Svelte store contract in their docs](https://svelte.dev/docs#component-format-script-4-prefix-stores-with-$-to-access-their-values-store-contract).
|
|
351
|
-
|
|
352
|
-
We believe this is an optimal pattern for UI development as it allows for a more dynamic, user experience. Your application will be updated with each event from emitted from within the Widget. These events could be "loading", "completed", "success" or "failure". To help illustrate this, let's take a look at one of the `user` APIs:
|
|
353
|
-
|
|
354
|
-
### Import the API object
|
|
168
|
+
### Subscribe to Events
|
|
355
169
|
|
|
356
170
|
```js
|
|
357
171
|
import { user } from '@forgerock/login-widget';
|
|
358
|
-
```
|
|
359
172
|
|
|
360
|
-
### Call API method to initiate observable
|
|
361
|
-
|
|
362
|
-
Create a variable and assign the created observable:
|
|
363
|
-
|
|
364
|
-
```js
|
|
365
173
|
const userInfoEvents = user.info();
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
### Use the subscribe method
|
|
369
|
-
|
|
370
|
-
It's important to note that an observable is a "stream" of events over time. This means that the callback function in a subscribe will be called for each and every event until you unsubscribe from it (more on this later).
|
|
371
174
|
|
|
372
|
-
```js
|
|
373
175
|
userInfoEvents.subscribe((event) => {
|
|
374
176
|
if (event.loading) {
|
|
375
177
|
console.log('User info is being requested from server');
|
|
376
|
-
} else if (event.
|
|
178
|
+
} else if (event.successful) {
|
|
377
179
|
console.log('User info request was successful');
|
|
378
180
|
console.log(event.response);
|
|
379
181
|
} else if (event.error) {
|
|
@@ -383,432 +185,343 @@ userInfoEvents.subscribe((event) => {
|
|
|
383
185
|
});
|
|
384
186
|
```
|
|
385
187
|
|
|
386
|
-
###
|
|
387
|
-
|
|
388
|
-
Observables are not like a Promise in that Observables don't resolve and get "torn-down" after completion. Observables need to be unsubscribed from if they are no longer needed. This is especially important if you are subscribing to Observables in a component that gets created and destroyed many times over. Subscribing to an Observable over and over without unsubscribing will create a memory leak.
|
|
188
|
+
### Unsubscribe
|
|
389
189
|
|
|
390
|
-
|
|
190
|
+
Observables are not like Promises — they don't resolve and get cleaned up. You must unsubscribe when no longer needed, especially in components that are created and destroyed frequently:
|
|
391
191
|
|
|
392
192
|
```js
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
// ...
|
|
193
|
+
const unsubscribe = userInfoEvents.subscribe((event) => console.log(event));
|
|
396
194
|
|
|
397
|
-
//
|
|
398
|
-
|
|
195
|
+
// Later, when no longer needed:
|
|
196
|
+
unsubscribe();
|
|
399
197
|
```
|
|
400
198
|
|
|
401
|
-
|
|
199
|
+
> **Note**: If subscribing at a top-level component that persists over the lifetime of your app, unsubscribing is not needed.
|
|
402
200
|
|
|
403
|
-
###
|
|
201
|
+
### Get Current Values
|
|
404
202
|
|
|
405
|
-
|
|
203
|
+
To get the current value stored within the Widget without subscribing to future events, call `subscribe` and immediately call the returned unsubscribe function:
|
|
406
204
|
|
|
407
205
|
```js
|
|
408
|
-
// Create variable for user info
|
|
409
206
|
let userInfo;
|
|
410
|
-
|
|
411
|
-
userInfoEvents.subscribe((event) => (userinfo = event.response))(); // <-- notice the second pair of parentheses
|
|
207
|
+
userInfoEvents.subscribe((event) => (userInfo = event.response))();
|
|
412
208
|
```
|
|
413
209
|
|
|
414
|
-
|
|
210
|
+
### Request Fresh Values
|
|
415
211
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
You can ask the Widget to request new, fresh values from the ForgeRock server, rather than just what it has stored locally. This is done by calling the Observables action methods, like `get`.
|
|
212
|
+
Call action methods like `get` to request new values from the server. Any active `subscribe` callbacks will receive the resulting events:
|
|
419
213
|
|
|
420
214
|
```js
|
|
421
215
|
userInfoEvents.get();
|
|
422
216
|
```
|
|
423
217
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
### Using Promises
|
|
218
|
+
### Use Promises
|
|
427
219
|
|
|
428
|
-
|
|
220
|
+
All Widget APIs that involve network calls also support Promises:
|
|
429
221
|
|
|
430
222
|
```js
|
|
431
|
-
// async
|
|
432
|
-
|
|
433
|
-
async function example() {
|
|
434
|
-
try {
|
|
435
|
-
userInfo = await userInfoEvents.get();
|
|
436
|
-
} catch (err) {
|
|
437
|
-
console.log(err);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
223
|
+
// async/await
|
|
224
|
+
const userInfo = await userInfoEvents.get();
|
|
440
225
|
|
|
441
|
-
// Promise
|
|
442
|
-
let userInfo;
|
|
226
|
+
// Promise chain
|
|
443
227
|
userInfoEvents
|
|
444
228
|
.get()
|
|
445
|
-
.then((data) => (
|
|
446
|
-
.catch((err) => console.
|
|
229
|
+
.then((data) => console.log(data))
|
|
230
|
+
.catch((err) => console.error(err));
|
|
447
231
|
```
|
|
448
232
|
|
|
449
233
|
## Complete Widget API
|
|
450
234
|
|
|
451
|
-
The Widget comes with methods and event handlers used to control the lifecycle of user journeys/authentication.
|
|
452
|
-
|
|
453
235
|
### Widget
|
|
454
236
|
|
|
455
237
|
```js
|
|
456
238
|
import Widget from '@forgerock/login-widget';
|
|
457
239
|
|
|
458
|
-
// Instantiate
|
|
240
|
+
// Instantiate
|
|
459
241
|
const widget = new Widget({
|
|
460
|
-
target: widgetRootEl, // REQUIRED;
|
|
242
|
+
target: widgetRootEl, // REQUIRED; a real DOM element
|
|
461
243
|
props: {
|
|
462
|
-
type: 'modal', // OPTIONAL; "modal" or "inline"
|
|
244
|
+
type: 'modal', // OPTIONAL; "modal" (default) or "inline"
|
|
463
245
|
},
|
|
464
246
|
});
|
|
465
247
|
|
|
466
|
-
//
|
|
248
|
+
// Remove widget from DOM and destroy listeners
|
|
467
249
|
widget.$destroy();
|
|
468
250
|
```
|
|
469
251
|
|
|
470
|
-
|
|
252
|
+
> **Note**: Call `$destroy()` if instantiating the Widget in a component that is frequently created and destroyed. We recommend instantiating higher in your application tree, in a component created once and preserved.
|
|
471
253
|
|
|
472
254
|
### Configuration
|
|
473
255
|
|
|
474
|
-
This configuration function produces a config API, and its `set` method is required for the underlying JavaScript SDK to interaction with the ForgeRock platform or access stored tokens.
|
|
475
|
-
|
|
476
256
|
```js
|
|
477
|
-
import {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* OPTIONAL, *BUT ENCOURAGED*, CONFIGURATION
|
|
491
|
-
* Remaining config is optional with fallback values shown
|
|
492
|
-
*/
|
|
493
|
-
clientId: 'WebLoginWidgetClient', // String; defaults to 'WebLoginWidgetClient'
|
|
494
|
-
realmPath: 'alpha', // String; defaults to 'alpha'
|
|
495
|
-
redirectUri: window.location.href, // URL string; defaults to `window.location.href`
|
|
496
|
-
scope: 'openid email', // String; defaults to 'openid email'
|
|
497
|
-
/**
|
|
498
|
-
* NOT RECOMMENDED
|
|
499
|
-
* Rather, configure a journey/tree through the `.start({ journey: 'Login' })` options object,
|
|
500
|
-
* avoid setting it here
|
|
501
|
-
*/
|
|
502
|
-
tree: 'Login', // String, but NOT recommended.
|
|
257
|
+
import { configure } from '@forgerock/login-widget';
|
|
258
|
+
|
|
259
|
+
// configure() is async — await it before calling any other Widget API
|
|
260
|
+
await configure({
|
|
261
|
+
// REQUIRED — the well-known URL, shared by the journey and OIDC clients
|
|
262
|
+
wellknown:
|
|
263
|
+
'https://your-tenant.forgeblocks.com/am/oauth2/realms/root/realms/alpha/.well-known/openid-configuration',
|
|
264
|
+
// REQUIRED if you use OAuth/OIDC tokens, user info, or logout
|
|
265
|
+
oidcClient: {
|
|
266
|
+
clientId: 'WebOAuthClient',
|
|
267
|
+
redirectUri: `${window.location.origin}/callback`,
|
|
268
|
+
scope: 'openid profile email',
|
|
503
269
|
},
|
|
504
|
-
|
|
505
|
-
* OPTIONAL; See below for the Content Configuration section
|
|
506
|
-
*/
|
|
270
|
+
// OPTIONAL — see dedicated sections below
|
|
507
271
|
content: {},
|
|
508
|
-
/**
|
|
509
|
-
* OPTIONAL; See below for the Links Configuration section
|
|
510
|
-
*/
|
|
511
272
|
links: {},
|
|
512
|
-
/**
|
|
513
|
-
* OPTIONAL; See below for Styling Configuration section
|
|
514
|
-
*/
|
|
515
273
|
style: {},
|
|
516
274
|
});
|
|
517
275
|
```
|
|
518
276
|
|
|
519
|
-
|
|
277
|
+
> **Migration note (2.0.0):** The `forgerock` config object has been replaced by `oidcClient`.
|
|
278
|
+
> Endpoint discovery is now driven by a single top-level `wellknown` URL, shared by the
|
|
279
|
+
> journey and OIDC clients — `baseUrl`, `realmPath`, `timeout`, and `support` are no longer
|
|
280
|
+
> used. `clientId`, `redirectUri`, and `scope` are now required when configuring `oidcClient`.
|
|
520
281
|
|
|
521
282
|
### Journey
|
|
522
283
|
|
|
523
|
-
The `journey` object:
|
|
524
|
-
|
|
525
284
|
```js
|
|
526
285
|
import { journey } from '@forgerock/login-widget';
|
|
527
286
|
|
|
528
|
-
// Call to start the journey
|
|
529
|
-
// Optional config can be passed in, see below for more details
|
|
530
287
|
const journeyEvents = journey({
|
|
531
|
-
oauth: true, // OPTIONAL;
|
|
532
|
-
user: true, // OPTIONAL; default
|
|
288
|
+
oauth: true, // OPTIONAL; default true; use OAuth flow for tokens
|
|
289
|
+
user: true, // OPTIONAL; default true; fetch user info from /userinfo
|
|
533
290
|
});
|
|
534
291
|
|
|
535
292
|
// Start a journey
|
|
536
293
|
journeyEvents.start({
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
resumeUrl: window.location.href, // OPTIONAL; the full URL for resuming a tree (see resuming a journey section)
|
|
294
|
+
journey: 'Login', // OPTIONAL; journey name (omit to let AM choose the default)
|
|
295
|
+
resumeUrl: window.location.href, // OPTIONAL; URL for resuming a suspended journey
|
|
540
296
|
});
|
|
541
297
|
|
|
542
|
-
// Change a journey
|
|
298
|
+
// Change to a different journey
|
|
543
299
|
journeyEvents.change({
|
|
544
|
-
|
|
545
|
-
journey: 'Registration', // OPTIONAL; choice the journey or tree you want to start
|
|
300
|
+
journey: 'Registration',
|
|
546
301
|
});
|
|
547
302
|
|
|
548
|
-
//
|
|
549
|
-
|
|
550
|
-
journey.
|
|
551
|
-
|
|
303
|
+
// Listen for events
|
|
304
|
+
journeyEvents.subscribe((event) => {
|
|
305
|
+
if (event.journey.successful) {
|
|
306
|
+
console.log('Authentication succeeded', event);
|
|
307
|
+
}
|
|
552
308
|
});
|
|
553
309
|
```
|
|
554
310
|
|
|
555
|
-
|
|
311
|
+
**Journey event schema:**
|
|
556
312
|
|
|
557
313
|
```js
|
|
558
|
-
// response
|
|
559
314
|
{
|
|
560
315
|
journey: {
|
|
561
|
-
completed: false,
|
|
562
|
-
error: null,
|
|
563
|
-
loading: false,
|
|
564
|
-
step: null,
|
|
565
|
-
successful: false,
|
|
566
|
-
response: null,
|
|
316
|
+
completed: false, // boolean
|
|
317
|
+
error: null, // null or { code, message, step }
|
|
318
|
+
loading: false, // boolean
|
|
319
|
+
step: null, // null or step object from ForgeRock AM
|
|
320
|
+
successful: false, // boolean
|
|
321
|
+
response: null, // null or success response from AM
|
|
567
322
|
},
|
|
568
323
|
oauth: {
|
|
569
|
-
completed: false,
|
|
570
|
-
error: null,
|
|
571
|
-
loading: false,
|
|
572
|
-
successful: false,
|
|
573
|
-
response: null,
|
|
324
|
+
completed: false, // boolean
|
|
325
|
+
error: null, // null or { code, message }
|
|
326
|
+
loading: false, // boolean
|
|
327
|
+
successful: false, // boolean
|
|
328
|
+
response: null, // null or OAuth/OIDC tokens
|
|
574
329
|
},
|
|
575
330
|
user: {
|
|
576
|
-
completed: false,
|
|
577
|
-
error: null,
|
|
578
|
-
loading: false,
|
|
579
|
-
successful: false,
|
|
580
|
-
response: null,
|
|
331
|
+
completed: false, // boolean
|
|
332
|
+
error: null, // null or { code, message }
|
|
333
|
+
loading: false, // boolean
|
|
334
|
+
successful: false, // boolean
|
|
335
|
+
response: null, // null or user info (driven by OAuth scope)
|
|
581
336
|
},
|
|
582
337
|
}
|
|
583
338
|
```
|
|
584
339
|
|
|
585
340
|
### Component
|
|
586
341
|
|
|
587
|
-
The
|
|
342
|
+
The `component` API controls the widget's lifecycle. For the modal form factor, it provides `open` and `close` methods.
|
|
588
343
|
|
|
589
344
|
```js
|
|
590
345
|
import { component } from '@forgerock/login-widget';
|
|
591
346
|
|
|
592
|
-
// Initiate the component API
|
|
593
347
|
const componentEvents = component();
|
|
594
348
|
|
|
595
|
-
//
|
|
596
|
-
// When using the modal type, you will also receive open and close events.
|
|
597
|
-
// The property `reason` will be either "auto", "external", or "user" (see below)
|
|
598
|
-
componentEvents.subscribe((event) => {
|
|
599
|
-
/* Run anything you want */
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
// Open the modal
|
|
349
|
+
// Open/close the modal
|
|
603
350
|
componentEvents.open();
|
|
604
|
-
|
|
605
|
-
// Close the modal
|
|
606
351
|
componentEvents.close();
|
|
352
|
+
|
|
353
|
+
// Listen for lifecycle events
|
|
354
|
+
componentEvents.subscribe((event) => {
|
|
355
|
+
if (event.mounted) console.log('Widget is mounted');
|
|
356
|
+
if (event.open === false) console.log('Modal closed:', event.reason);
|
|
357
|
+
});
|
|
607
358
|
```
|
|
608
359
|
|
|
609
|
-
|
|
360
|
+
**Component event schema:**
|
|
610
361
|
|
|
611
362
|
```js
|
|
612
363
|
{
|
|
613
|
-
error: null,
|
|
364
|
+
error: null, // null or { code, message, step }
|
|
614
365
|
mounted: false, // boolean
|
|
615
|
-
open: null,
|
|
616
|
-
reason: null,
|
|
617
|
-
type: null,
|
|
366
|
+
open: null, // boolean or null (null for inline type)
|
|
367
|
+
reason: null, // "user" | "auto" | "external"
|
|
368
|
+
type: null, // "modal" | "inline"
|
|
618
369
|
}
|
|
619
370
|
```
|
|
620
371
|
|
|
621
|
-
|
|
372
|
+
**Close reasons:**
|
|
622
373
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
374
|
+
| Reason | Description |
|
|
375
|
+
| ------------ | -------------------------------------------- |
|
|
376
|
+
| `"user"` | User closed the dialog via UI |
|
|
377
|
+
| `"auto"` | Modal closed after successful authentication |
|
|
378
|
+
| `"external"` | Application called `componentEvents.close()` |
|
|
626
379
|
|
|
627
380
|
### User
|
|
628
381
|
|
|
629
382
|
```js
|
|
630
383
|
import { user } from '@forgerock/login-widget';
|
|
631
384
|
|
|
632
|
-
|
|
633
|
-
* User info API
|
|
634
|
-
*/
|
|
385
|
+
// User info
|
|
635
386
|
const userEvents = user.info();
|
|
636
|
-
|
|
637
|
-
userEvents.
|
|
638
|
-
// Will return current, *local*, user info and future state changes
|
|
639
|
-
console.log(event);
|
|
640
|
-
});
|
|
641
|
-
// Fetch/get fresh user info from ForgeRock server
|
|
642
|
-
userEvents.get(); // New state will be returned in your `userEvents.subscribe` callback function
|
|
387
|
+
userEvents.subscribe((event) => console.log(event));
|
|
388
|
+
userEvents.get(); // Fetch fresh user info from server
|
|
643
389
|
|
|
644
|
-
|
|
645
|
-
* User tokens API
|
|
646
|
-
*/
|
|
390
|
+
// User tokens
|
|
647
391
|
const tokenEvents = user.tokens();
|
|
648
|
-
|
|
649
|
-
tokenEvents.
|
|
650
|
-
// Will return current, *local*, user tokens and future state changes
|
|
651
|
-
console.log(event);
|
|
652
|
-
});
|
|
653
|
-
// Fetch/get fresh user tokens from ForgeRock server
|
|
654
|
-
tokenEvents.get(); // New state will be returned in your tokenEvents.subscribe` callback function
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* Logout
|
|
658
|
-
* Log user out and clear user data (info and tokens)
|
|
659
|
-
*/
|
|
660
|
-
user.logout(); // Resets user and emits event to your info and tokens' `.subscribe` callback function
|
|
661
|
-
```
|
|
392
|
+
tokenEvents.subscribe((event) => console.log(event));
|
|
393
|
+
tokenEvents.get(); // Fetch fresh tokens from server
|
|
662
394
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
```js
|
|
666
|
-
{
|
|
667
|
-
completed: false, // boolean
|
|
668
|
-
error: null, // null or object with `code`, `message` and `step` that failed
|
|
669
|
-
loading: false, // boolean
|
|
670
|
-
successful: false, // boolean
|
|
671
|
-
response: null, // object returned from the `/userinfo` endpoint configured in ForgeRock
|
|
672
|
-
}
|
|
395
|
+
// Logout
|
|
396
|
+
user.logout(); // Clears user data and emits events to subscribers
|
|
673
397
|
```
|
|
674
398
|
|
|
675
|
-
|
|
399
|
+
**User info / token event schema:**
|
|
676
400
|
|
|
677
401
|
```js
|
|
678
402
|
{
|
|
679
|
-
completed: false,
|
|
680
|
-
error: null,
|
|
681
|
-
loading: false,
|
|
403
|
+
completed: false, // boolean
|
|
404
|
+
error: null, // null or { code, message }
|
|
405
|
+
loading: false, // boolean
|
|
682
406
|
successful: false, // boolean
|
|
683
|
-
response: null,
|
|
407
|
+
response: null, // object from /userinfo or /access_token endpoint
|
|
684
408
|
}
|
|
685
409
|
```
|
|
686
410
|
|
|
687
|
-
###
|
|
411
|
+
### Calling protected resources
|
|
688
412
|
|
|
689
|
-
The
|
|
690
|
-
|
|
691
|
-
|
|
413
|
+
> **Removed in 2.0.0:** The `request` export (an alias to the legacy `HttpClient.request`) has been
|
|
414
|
+
> removed. `@forgerock/oidc-client` does not provide an HTTP client. Get the access token from
|
|
415
|
+
> `user.tokens()` and call `fetch` directly, adding the `Authorization` header yourself:
|
|
692
416
|
|
|
693
417
|
```js
|
|
694
|
-
import
|
|
695
|
-
|
|
696
|
-
// See below for more details on the options
|
|
697
|
-
const response = await request({ init: { method: 'GET' }, url: 'https://protected.resource.com' });
|
|
698
|
-
```
|
|
418
|
+
import { user } from '@forgerock/login-widget';
|
|
699
419
|
|
|
700
|
-
|
|
420
|
+
const tokenEvents = user.tokens();
|
|
421
|
+
const { response: tokens } = await tokenEvents.get();
|
|
701
422
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
// Options object for `fetch` API: https://developer.mozilla.org/en-US/docs/Web/API/fetch
|
|
423
|
+
const response = await fetch('https://protected.resource.com', {
|
|
424
|
+
method: 'GET',
|
|
425
|
+
headers: {
|
|
426
|
+
Authorization: `Bearer ${tokens.accessToken}`,
|
|
707
427
|
},
|
|
708
|
-
|
|
709
|
-
url: 'https://protected.resource.com', // String; the URL of the resource
|
|
710
|
-
|
|
711
|
-
// Unsupported properties
|
|
712
|
-
authorization: {},
|
|
713
|
-
requiresNewToken: () => {},
|
|
714
|
-
}
|
|
428
|
+
});
|
|
715
429
|
```
|
|
716
430
|
|
|
717
|
-
|
|
431
|
+
> **Note**: The legacy `request` automatically refreshed tokens on a 401 and parsed Identity Gateway
|
|
432
|
+
> policy advice. Those behaviors are not provided by the new SDK and must be implemented by the consumer if needed.
|
|
718
433
|
|
|
719
434
|
### Styling Configuration
|
|
720
435
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
Example:
|
|
436
|
+
Configure the widget's visual appearance:
|
|
724
437
|
|
|
725
438
|
```js
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
config.set({
|
|
439
|
+
await configure({
|
|
729
440
|
style: {
|
|
730
|
-
checksAndRadios: 'animated', // OPTIONAL;
|
|
731
|
-
labels: 'floating', // OPTIONAL;
|
|
441
|
+
checksAndRadios: 'animated', // OPTIONAL; 'animated' or 'standard'
|
|
442
|
+
labels: 'floating', // OPTIONAL; 'floating' or 'stacked'
|
|
732
443
|
logo: {
|
|
733
|
-
// OPTIONAL;
|
|
734
|
-
dark: 'https://example.com/img/white-logo.png',
|
|
735
|
-
light: 'https://example.com/img/black-logo.png', // REQUIRED if logo
|
|
736
|
-
height: 300,
|
|
737
|
-
width: 400,
|
|
444
|
+
// OPTIONAL; modal only
|
|
445
|
+
dark: 'https://example.com/img/white-logo.png',
|
|
446
|
+
light: 'https://example.com/img/black-logo.png', // REQUIRED if logo provided
|
|
447
|
+
height: 300,
|
|
448
|
+
width: 400,
|
|
738
449
|
},
|
|
739
450
|
sections: {
|
|
740
|
-
// OPTIONAL;
|
|
741
|
-
header: false, //
|
|
451
|
+
// OPTIONAL; modal only
|
|
452
|
+
header: false, // Display a header section with logo
|
|
742
453
|
},
|
|
743
454
|
stage: {
|
|
744
|
-
icon: true, // OPTIONAL;
|
|
455
|
+
icon: true, // OPTIONAL; display generic stage icons
|
|
745
456
|
},
|
|
746
457
|
},
|
|
747
458
|
});
|
|
748
459
|
```
|
|
749
460
|
|
|
750
|
-
Note
|
|
461
|
+
> **Note**: The `logo` and `sections` properties only apply to the modal form factor.
|
|
751
462
|
|
|
752
463
|
### Links Configuration
|
|
753
464
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
Example:
|
|
465
|
+
Set the URL for your Terms & Conditions page (used by `TermsAndConditionsCallback`):
|
|
757
466
|
|
|
758
467
|
```js
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
config.set({
|
|
468
|
+
await configure({
|
|
762
469
|
links: {
|
|
763
|
-
termsAndConditions: 'https://example.com/terms',
|
|
470
|
+
termsAndConditions: 'https://example.com/terms',
|
|
764
471
|
},
|
|
765
472
|
});
|
|
766
473
|
```
|
|
767
474
|
|
|
768
475
|
### Content Configuration
|
|
769
476
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
Example:
|
|
477
|
+
Override the widget's default content with custom text. For the full schema, see the [en-US locale file](https://github.com/ForgeRock/forgerock-web-login-framework/tree/main/core/locales).
|
|
773
478
|
|
|
774
479
|
```js
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
480
|
+
await configure({
|
|
481
|
+
content: {
|
|
482
|
+
// Custom content that overrides Widget defaults
|
|
483
|
+
},
|
|
779
484
|
});
|
|
780
485
|
```
|
|
781
486
|
|
|
782
|
-
|
|
487
|
+
### CAPTCHA Configuration
|
|
488
|
+
|
|
489
|
+
AM does not signal invisible mode in the callback payload for either `ReCaptchaCallback` or `ReCaptchaEnterpriseCallback`. Use the `captcha` option to configure invisible rendering:
|
|
490
|
+
|
|
491
|
+
```js
|
|
492
|
+
await configure({
|
|
493
|
+
captcha: {
|
|
494
|
+
mode: 'invisible', // 'visible' (default) | 'invisible'
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
```
|
|
783
498
|
|
|
784
|
-
|
|
499
|
+
**Script loading:** The widget automatically injects the required CAPTCHA script at mount time — no manual `<script>` tag is needed. If the provider API (`window.grecaptcha` / `window.hcaptcha`) is already present on the page when the widget mounts, injection is skipped.
|
|
785
500
|
|
|
786
|
-
|
|
787
|
-
2. Device Profile
|
|
501
|
+
## Supported Callbacks
|
|
788
502
|
|
|
789
|
-
|
|
503
|
+
The widget supports the following ForgeRock callbacks:
|
|
790
504
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
505
|
+
- Page node
|
|
506
|
+
- Username, Password
|
|
507
|
+
- WebAuthn (registration and login)
|
|
508
|
+
- Push authentication
|
|
509
|
+
- One-time password verification
|
|
510
|
+
- Social login (Apple, Facebook, Google)
|
|
511
|
+
- Email suspend ("magic links")
|
|
512
|
+
- Device profile
|
|
513
|
+
- reCAPTCHA v2 (visible + invisible), reCAPTCHA Enterprise, hCaptcha (visible + invisible)
|
|
514
|
+
- QR codes
|
|
515
|
+
- Ping Protect
|
|
798
516
|
|
|
799
517
|
## Disclaimer
|
|
800
518
|
|
|
801
|
-
> **This code is provided by ForgeRock on an
|
|
802
|
-
|
|
803
|
-
<!---------------------------------------------------------------------------------------------------------->
|
|
804
|
-
<!-- LICENSE - Links to the MIT LICENSE file in each repo. -->
|
|
519
|
+
> **This code is provided by ForgeRock on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. ForgeRock does not represent or warrant or make any guarantee regarding the use of this code or the accuracy, timeliness or completeness of any data or information relating to this code, and ForgeRock hereby disclaims all warranties whether express, or implied or statutory, including without limitation the implied warranties of merchantability, fitness for a particular purpose, and any warranty of non-infringement. ForgeRock shall not have any liability arising out of or related to any use, implementation or configuration of this code, including but not limited to use for any commercial purpose. Any action or suit relating to the use of the code may be brought only in the courts of a jurisdiction wherein ForgeRock resides or in which ForgeRock conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions.**
|
|
805
520
|
|
|
806
521
|
## License
|
|
807
522
|
|
|
808
|
-
This project is licensed under the MIT License
|
|
523
|
+
This project is licensed under the MIT License — see the [LICENSE](https://github.com/ForgeRock/forgerock-web-login-framework/blob/main/LICENSE) file for details.
|
|
809
524
|
|
|
810
525
|
---
|
|
811
526
|
|
|
812
|
-
© Copyright 2022-
|
|
813
|
-
|
|
814
|
-
[forgerock-logo]: https://www.forgerock.com/themes/custom/forgerock/images/fr-logo-horz-color.svg 'ForgeRock Logo'
|
|
527
|
+
© Copyright 2022-2026 Ping Identity Corporation. All Rights Reserved.
|