# Embed the widget

## Embed the widget
**Widget host URLs**
| Environment | Widget host |
|  --- | --- |
| Production | `https://wgt.stitchcredit.com` |
| Development | `https://efx-dev.stitchcredit.com` |

**Entry points**
Three URL paths control the layout the user sees after authentication. Pick one — everything else (events, configuration, token flow) is identical between them.
| Path | Layout | `redirectView` |
|  --- | --- | --- |
| `/login-aio` | All-in-one single scrollable page with all credit data | `all-in-one` |
| `/login-direct` | Full dashboard with tabbed navigation | `dashboard` |
| `/login-tile` | Compact tile/card-based layout | `tile-view` |

**Standalone components**
If you don't want the full widget shell, individual views can be embedded on their own. This is useful for adding a single piece of credit data — say, a score gauge on a dashboard — without taking up the full page. Each component runs in its own iframe and is authenticated with a **user access token** (not a preauth token), passed as the `standAloneToken` query parameter.
> **Live demo — standalone components.** [https://efx-dev.stitchcredit.com/widget-manager.html](https://efx-dev.stitchcredit.com/widget-manager.html)

| Path | Component |
|  --- | --- |
| `/score` | Credit score |
| `/report` | Credit report |
| `/monitor` | Monitoring alerts |
| `/score-up` | Score improvement |
| `/identity-restoration` | ID restoration |
| `/score-gauge` | Score gauge |
| `/score-details` | Score details |

To get the user access token, your server runs the same three steps as the full widget (`POST /direct/login` → `GET /direct/preauth-token/{id}` → `GET /users/preauth-token/{preauthToken}`) and uses the token returned by step 3 as `standAloneToken`.

```html
<iframe
  id="sc-score-gauge"
  src="https://{widget-host}/score-gauge?standAloneToken={userAccessToken}"
  width="320" height="320" frameborder="0"
></iframe>
```
**Server Start (no JavaScript required)**
The simplest possible embed. Point the iframe at `/api/users/start` with your host key and the widget handles tokens, registration, and login itself.
> **Live demo — full flow (registration + login + identity).** [https://wgt.stitchcredit.com/stitch_demo.html](https://wgt.stitchcredit.com/stitch_demo.html)


```html
<iframe
  id="sc-iframe"
  src="https://{widget-host}/api/users/start?key=your-host-key"
  width="100%" height="100vh" frameborder="0"
></iframe>
```
Optional query parameters override the host configuration:
| Parameter | Description |
|  --- | --- |
| `key` | Your host key (required) |
| `ocf` | Override feature flags (bitmask) |
| `oct` | Override theme color (hex without `#`) |
| `ocl` | Override logo URL (URL-encoded) |
| `view` | Initial view (`all-in-one` / `dashboard` / `tile-view`) |
| `verificationMethod` | Identity flow: `dit_smfa` (default) / `prefill_onboarding` / `dit_customer_otp` |

**Direct API: iframe + postMessage initialization**
When you manage users yourself, the widget loads in a "hung" state and waits for two things from your page over `postMessage` before it can do anything: its **configuration** (branding, flags, identity flow) and a **preauth token** (so it can authenticate the user).
> **Live demo — hybrid flow (you manage users, we handle identity verification).** [https://efx-dev.stitchcredit.com/hybrid/](https://efx-dev.stitchcredit.com/hybrid/)

The handshake looks like this:
1. The widget loads and posts
**`INIT_CONFIG`**
 to your page.
2. Your page replies with a
**`WIDGET_CONFIGS`**
 message — host key, theme, feature flags, identity flow, etc.
3. The widget then posts
**`AUTH_REQUIRED`**
 when it needs to authenticate a user.
4. Your server fetches a fresh
**preauth token**
 (
`GET /direct/preauth-token/{id}`
, 30-second lifetime), and your page replies with a
**`PREAUTH`**
 message containing the token.
5. The widget exchanges the preauth for a user access token internally and renders the credit experience.

Your page must register a single `message` listener and dispatch on `event.data.type`. Here is a complete, working example using the All-in-One entry point:

```html
<iframe
  id="sc-iframe"
  allowtransparency="true"
  src="https://{widget-host}/login-aio"
  width="100%" height="100vh" frameborder="0"
></iframe>

<script>
const userId = 'e4f403ca-e089-40ff-a840-88f7bb4fe949';
const accessToken = '...';   // your host token from POST /direct/login

window.addEventListener('message', receiveMessage, false);

function receiveMessage(event) {
  if (!event.data) return;
  const es = event.source;

  switch (event.data.type) {
    case 'INIT_CONFIG':
      // 1) Widget asks for its config — send it back.
      es.postMessage({
        type: 'WIDGET_CONFIGS',
        data: {
          key: 'your-host-uuid',
          flags: '65535',                // see Feature flags table
          theme: '#3f7cfc',
          formLabelColor: '#0F94A1',
          linkColor: '#0F94A1',
          popupModeForms: false,
          redirectView: 'all-in-one',
          identityDisclaimer: true,
          identityScreenTitleText: 'Sign Up',
          mobileIdentityScreenTitleText: 'Mobile Verification',
          hideBackgroundImg: true,
          hideHeaderLogo: true,
          eidFailedRedirect: 'close',
          // Identity flow: 'dit_smfa' (default) | 'prefill_onboarding' | 'dit_customer_otp'
          verificationMethod: 'dit_smfa'
        }
      }, '*');
      break;

    case 'AUTH_REQUIRED':
      // 2) Widget needs a preauth token — fetch from your backend, then send it.
      fetch('https://{api-host}/api/direct/preauth-token/' + userId, {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + accessToken
        }
      })
      .then(res => res.json())
      .then(data => {
        es.postMessage({ type: 'PREAUTH', token: data.token }, '*');
      })
      .catch(() => {
        es.postMessage({ type: 'PREAUTH', token: null }, '*');
      });
      break;

    case 'IDENTITY_STARTED':
      // (Optional) Pre-fill identity fields. Both the classic and
      // prefill + onboarding flows use fname/lname/mobile.
      es.postMessage({
        type: 'IDENTITY',
        data: {
          fname: 'John', lname: 'Doe',
          mobile: '5551234567',
          street1: '123 Main St', street2: '',
          city: 'Atlanta', state: 'GA', zip: '30301',
          ssn: '123456789',
          dob: '01-15-1985',
          immutable: false              // true = read-only fields
        }
      }, '*');
      break;

    case 'LOGIN_SUCCESSFUL':   /* user logged in */ break;
    case 'USER_ENROLLED':      /* identity + enrollment complete */ break;
    case 'IDENTITY_FAILED':    /* user failed identity verification */ break;
    case 'SERVICE_FAILURE':    /* external service is down */ break;
  }
}
</script>
```
[See the Direct authentication endpoints →](/client-spec/direct-authentication)

Version: v3

## Description:

  - `Embed the widget` ()
    **Widget host URLs** | Environment | Widget host |
|  --- | --- |
| Production | `https://wgt.stitchcredit.com` |
| Development | `https://efx-dev.stitchcredit.com` | **Entry points** Three URL paths control the layout the user sees after authentication. Pick one — everything else (events, configuration, token flow) is identical between them. | Path | Layout | `redirectView` |
|  --- | --- | --- |
| `/login-aio` | All-in-one single scrollable page with all credit data | `all-in-one` |
| `/login-direct` | Full dashboard with tabbed navigation | `dashboard` |
| `/login-tile` | Compact tile/card-based layout | `tile-view` | **Standalone components** If you don't want the full widget shell, individual views can be embedded on their own. This is useful for adding a single piece of credit data — say, a score gauge on a dashboard — without taking up the full page. Each component runs in its own iframe and is authenticated with a **user access token** (not a preauth token), passed as the `standAloneToken` query parameter. > **Live demo — standalone components.** [https://efx-dev.stitchcredit.com/widget-manager.html](https://efx-dev.stitchcredit.com/widget-manager.html) | Path | Component |
|  --- | --- |
| `/score` | Credit score |
| `/report` | Credit report |
| `/monitor` | Monitoring alerts |
| `/score-up` | Score improvement |
| `/identity-restoration` | ID restoration |
| `/score-gauge` | Score gauge |
| `/score-details` | Score details | To get the user access token, your server runs the same three steps as the full widget (`POST /direct/login` → `GET /direct/preauth-token/{id}` → `GET /users/preauth-token/{preauthToken}`) and uses the token returned by step 3 as `standAloneToken`. ```html
<iframe
  id="sc-score-gauge"
  src="https://{widget-host}/score-gauge?standAloneToken={userAccessToken}"
  width="320" height="320" frameborder="0"
></iframe>
``` **Server Start (no JavaScript required)** The simplest possible embed. Point the iframe at `/api/users/start` with your host key and the widget handles tokens, registration, and login itself. > **Live demo — full flow (registration + login + identity).** [https://wgt.stitchcredit.com/stitch_demo.html](https://wgt.stitchcredit.com/stitch_demo.html) ```html
<iframe
  id="sc-iframe"
  src="https://{widget-host}/api/users/start?key=your-host-key"
  width="100%" height="100vh" frameborder="0"
></iframe>
``` Optional query parameters override the host configuration: | Parameter | Description |
|  --- | --- |
| `key` | Your host key (required) |
| `ocf` | Override feature flags (bitmask) |
| `oct` | Override theme color (hex without `#`) |
| `ocl` | Override logo URL (URL-encoded) |
| `view` | Initial view (`all-in-one` / `dashboard` / `tile-view`) |
| `verificationMethod` | Identity flow: `dit_smfa` (default) / `prefill_onboarding` / `dit_customer_otp` | **Direct API: iframe + postMessage initialization** When you manage users yourself, the widget loads in a "hung" state and waits for two things from your page over `postMessage` before it can do anything: its **configuration** (branding, flags, identity flow) and a **preauth token** (so it can authenticate the user). > **Live demo — hybrid flow (you manage users, we handle identity verification).** [https://efx-dev.stitchcredit.com/hybrid/](https://efx-dev.stitchcredit.com/hybrid/) The handshake looks like this: 1. The widget loads and posts
**`INIT_CONFIG`**
 to your page.
2. Your page replies with a
**`WIDGET_CONFIGS`**
 message — host key, theme, feature flags, identity flow, etc.
3. The widget then posts
**`AUTH_REQUIRED`**
 when it needs to authenticate a user.
4. Your server fetches a fresh
**preauth token**
 (
`GET /direct/preauth-token/{id}`
, 30-second lifetime), and your page replies with a
**`PREAUTH`**
 message containing the token.
5. The widget exchanges the preauth for a user access token internally and renders the credit experience. Your page must register a single `message` listener and dispatch on `event.data.type`. Here is a complete, working example using the All-in-One entry point: ```html
<iframe
  id="sc-iframe"
  allowtransparency="true"
  src="https://{widget-host}/login-aio"
  width="100%" height="100vh" frameborder="0"
></iframe>

<script>
const userId = 'e4f403ca-e089-40ff-a840-88f7bb4fe949';
const accessToken = '...';   // your host token from POST /direct/login

window.addEventListener('message', receiveMessage, false);

function receiveMessage(event) {
  if (!event.data) return;
  const es = event.source;

  switch (event.data.type) {
    case 'INIT_CONFIG':
      // 1) Widget asks for its config — send it back.
      es.postMessage({
        type: 'WIDGET_CONFIGS',
        data: {
          key: 'your-host-uuid',
          flags: '65535',                // see Feature flags table
          theme: '#3f7cfc',
          formLabelColor: '#0F94A1',
          linkColor: '#0F94A1',
          popupModeForms: false,
          redirectView: 'all-in-one',
          identityDisclaimer: true,
          identityScreenTitleText: 'Sign Up',
          mobileIdentityScreenTitleText: 'Mobile Verification',
          hideBackgroundImg: true,
          hideHeaderLogo: true,
          eidFailedRedirect: 'close',
          // Identity flow: 'dit_smfa' (default) | 'prefill_onboarding' | 'dit_customer_otp'
          verificationMethod: 'dit_smfa'
        }
      }, '*');
      break;

    case 'AUTH_REQUIRED':
      // 2) Widget needs a preauth token — fetch from your backend, then send it.
      fetch('https://{api-host}/api/direct/preauth-token/' + userId, {
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + accessToken
        }
      })
      .then(res => res.json())
      .then(data => {
        es.postMessage({ type: 'PREAUTH', token: data.token }, '*');
      })
      .catch(() => {
        es.postMessage({ type: 'PREAUTH', token: null }, '*');
      });
      break;

    case 'IDENTITY_STARTED':
      // (Optional) Pre-fill identity fields. Both the classic and
      // prefill + onboarding flows use fname/lname/mobile.
      es.postMessage({
        type: 'IDENTITY',
        data: {
          fname: 'John', lname: 'Doe',
          mobile: '5551234567',
          street1: '123 Main St', street2: '',
          city: 'Atlanta', state: 'GA', zip: '30301',
          ssn: '123456789',
          dob: '01-15-1985',
          immutable: false              // true = read-only fields
        }
      }, '*');
      break;

    case 'LOGIN_SUCCESSFUL':   /* user logged in */ break;
    case 'USER_ENROLLED':      /* identity + enrollment complete */ break;
    case 'IDENTITY_FAILED':    /* user failed identity verification */ break;
    case 'SERVICE_FAILURE':    /* external service is down */ break;
  }
}
</script>
``` [See the Direct authentication endpoints →](/client-spec/direct-authentication)

