> Source: https://docs.cyberelements.io/saas/sl/Usage/Reference/SsoInjectionConfiguration/

# SSO injection configuration reference

SSO by injection fills in the login form of a web application in the user's browser, as the user would: it types the credentials into the fields, chooses the values of the lists and clicks the buttons, in a given order. What to fill in, and in which order, is described by an **injection configuration**: a JSON text that the `CyberElements SSO Configurator` browser plug-in produces from the login page, and that you paste into the application in the administration console.

This page describes every parameter of this configuration: those the plug-in writes, and those you can add by hand when the login form requires it.

| Property | Value |
|---|---|
| **Applications** | [Web](https://docs.cyberelements.io/saas/sl/Usage/Administration/AdminConsole/MainWorkPanel/Applications/StandardApplications/WebStandard/), with the SSO type **Injection** · [Isolate (Web)](https://docs.cyberelements.io/saas/sl/Usage/Administration/AdminConsole/MainWorkPanel/Applications/StandardApplications/IsolateWebStandard/) |
| **Format** | JSON |
| **Produced by** | the `CyberElements SSO Configurator` plug-in (Chromium-based browsers and Firefox), or by hand |
| **Read by** | a script of the product loaded into the pages of the application |

To install the plug-in and capture a first configuration, see [Configure SSO injection on web applications](https://docs.cyberelements.io/saas/sl/HowTo/ConfigureSSOByInjectionWithCYESSOConfigurator/).

## Where the configuration is entered

| Application | Field | Shown when |
|---|---|---|
| **Web** | **Injection settings** | **Enable SSO** is set to a mode other than **Disabled**, **SSO on classic HTML forms** is checked and **SSO type** is **Injection** |
| **Isolate (Web)** | **SSO injection configuration** | **Enable SSO** is set to a mode other than **Disabled** |

The console checks neither the syntax nor the content of the field. When the conditions above are no longer met at saving, the field is emptied.

> **A configuration that is not valid JSON**
>
> The console accepts any text, but a text that cannot be read as JSON does not have the same effect depending on the application:
>
> - **Web**: the launch is not prevented; the application opens, and nothing is filled in.
> - **Isolate (Web)**: the application does not open; the user portal displays **The specified application is no longer available for the user.**
>
> Check the syntax of a configuration edited by hand before saving it.

## Structure

The configuration is a JSON object on two levels:

- its keys are the **addresses of the pages** on which something must be filled in;
- the value of each address is an object whose keys are the **names of the entries**: one entry per element of the page to fill in, choose or click.

```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
```

A login spread over several pages whose address changes is described by several page addresses, each with its own entries.

## Page addresses

Each key is the address of a page, **without its query string** (the part that starts at `?`). The plug-in writes it in the right form: the address of the application itself, even when the page is displayed through the product.

When a page of a Web application loads, its address is compared with the keys:

- exactly as it is;
- with the default port added or removed: `:443` in `https`, `:80` in `http`;
- with the final `/` of the path added or removed.

A fragment (the part that starts at `#`) is part of the address compared when the address has no query string.

For an Isolate (Web) application, the same port and final `/` variants are added to each key before the configuration is sent to the isolated browser.

In a Web application, when the address changes without the page being reloaded (a single-page application moving to its next step, for instance), the new address is compared with the keys in the same way.

## Entry names

| Name | Role |
|---|---|
| `login` | For a Web application, its `value` is replaced at launch by the login of the session's SSO account. |
| `password` | For a Web application, its `value` is replaced at launch by the password of the session's SSO account. |
| any other name | No replacement: the `value` written in the configuration is used as it is. The plug-in names `button` the detected button, and `newitem` followed by a number the elements you add. |

> **Keep the names `login` and `password`**
>
> Credentials are attached to the entry **name**, not to the type of the field. Renamed, the entry keeps the value written in the configuration (an empty value as produced by the plug-in), and the field is filled in with it.

The SSO account is the one chosen by the SSO mode of the application (**Enabled**, **Request**, **Fixed**). No variable is replaced in the other entries.

> **A name is unique within a page**
>
> The name of an entry is a key of a JSON object: within the same page address, two entries with the same name are one too many. At launch, only the **last** one is kept, without any error: the console saves the text as it is. The element of the first entry is never processed; if its `order` differed, that number is missing from the sequence, which then stops at that step (see [How the injection runs](#how-the-injection-runs)). The plug-in always gives distinct names; a duplicate only comes from a configuration edited by hand.
>
> There is therefore a single `login` entry and a single `password` entry per page: the login cannot be typed into two fields of the same page. Each page address, on the other hand, has its own entries (see [A `login` and a `password` entry on every page](#login-and-password-on-every-page)).

### A `login` and a `password` entry on every page

Each page address of the configuration has a `login` entry **and** a `password` entry, including a page that shows only one of these fields, or neither: a page that asks only for the login, a page that asks only for the password, a confirmation page such as "Stay signed in?". When the page lacks one of these fields, add the matching entry by hand, with:

- an `id` that no element of the page carries, such as `cye-no-password-field`;
- `objectType` `input` and `tag` `input`, as for a field;
- an `order` after the last action of the page.

> **A confirmation page without a login or password field**
>
> ```
>  1
>  2
>  3
>  4
>  5
>  6
>  7
>  8
>  9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20
> 21
> 22
> 23
> 24
> 25
> 26
> 27
> 28
> 29
> 30
> 31
> ```

No element matches these entries: they fill nothing in, and the credentials are never typed on this page. Their search goes on as long as the page stays open, after its last action. For a Web application, the configuration of this page is therefore not withdrawn from the session: the page is filled in again if the user comes back to it during the same session.

> **Never leave the criteria of these entries empty**
>
> An entry whose criteria are all empty designates the first visible `<input>` of the page: the login or the password would be typed into it. This is true even after the click that leaves the page, since the next entry is searched for right away, in the page still displayed.

## Entry parameters

Each entry is an object. Its parameters fall into two groups: those used to **find** the element in the page, and those that say **what to do** with it.

### Finding the element

The element of an entry is the first element of the page, in the order of the document, that is visible and meets every criterion written. A criterion that is absent or empty (`""`) is not checked.

| Parameter | Written by the plug-in | Criterion |
|---|---|---|
| **`id`** | the `id` attribute of the element, or `""` | The `id` of the element must be equal, case included. |
| **`name`** | the `name` attribute of the element, or `""` | The `name` of the element must be equal. Empty it when the page generates the name randomly: see [Login form with random fields](https://docs.cyberelements.io/saas/sl/HowTo/ConfigureSSOByInjectionWithCYESSOConfigurator/). |
| **`type`** | the type of the element: `text`, `email`, `password`, `submit`, `button`, `select-one`… | The type of the element must be equal. Not checked on an element that has no type. |
| **`tag`** | the name of the HTML tag, in lowercase: `input`, `button`, `select`… | The tag of the element must be equal. Write it in lowercase. |
| **`selector`** | only when the element has no `id`, no `name`, no `type` and no `value` | A CSS selector that the element must match, such as `form#login div.actions > a`. It must be a valid CSS selector. |
| **`value`** | see [What to do with the element](#what-to-do-with-the-element) | A criterion in two cases only: when `type` is `button` or `submit`, the value of the element must be equal; when `objectType` is `select`, the list must hold an option with this value. |

An element is considered **hidden**, and therefore skipped, when it carries `aria-hidden="true"`, when its style is `display: none` or `visibility: hidden`, when it has no dimension, or when it has no positioned parent in the layout, the case of an element with a fixed position. The search covers the document of the page; it does not enter the shadow DOM of a web component.

> **A button found by its text**
>
> The plug-in writes in `value` the value of the element. On an `<input type="submit">`, that value is the text of the button: the entry then depends on the language of the page. Empty `value` if the application is displayed in several languages.

### What to do with the element

| Parameter | Written by the plug-in | Effect |
|---|---|---|
| **`order`** | `1`, `2`, `3`… in the order of the rows of the plug-in | The position of the entry in the sequence. A JSON number, not a string. |
| **`objectType`** | `input` for `login` and `password`, `select` for a list, `button` for anything else | The action: `button` clicks the element; `select` chooses in the list the option whose value is `value`; `input` (or any other value) types `value` into the element. |
| **`value`** | `""` for `input` entries; the value of the element for `button` entries; the chosen option for `select` entries | The text typed for an `input` entry, the value of the option chosen for a `select` entry. Not used to click. |
| **`delay`** | never | A wait, in milliseconds, between the moment the element is found and the action. Absent: no wait. The next entry waits for this action: the delays add up. |

Typing into a field reproduces the events of a keyboard input, so that the application sees the value as typed by the user. Choosing an option in a list selects it without reproducing a user's action.

> **When to add a `delay`**
>
> An element can be visible before the application is ready to process it: a button displayed before its script is attached, a field that the page empties at the end of its loading. A `delay` of a few hundred milliseconds on this entry lets the page finish.

> **At the end of a delay, the element is checked again**
>
> When the `delay` has elapsed, the element found is checked once more before the action. If it has been hidden or replaced in the page meanwhile (the page rebuilding its form, for instance), the action is skipped without any error, and the sequence moves on to the next entry. The longer the delay, the more likely this case: prefer a delay just long enough.

## Examples

### From the HTML of the page to the entries

Each value of an entry comes from the element of the page.

> **A login form and its configuration**
>
> For this login form:
>
> ```
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> ```
>
> the plug-in produces the configuration below, once the list has been added with `+` and its row dragged before the button:
>
> ```
>  1
>  2
>  3
>  4
>  5
>  6
>  7
>  8
>  9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20
> 21
> 22
> 23
> 24
> 25
> 26
> 27
> 28
> 29
> 30
> 31
> 32
> 33
> 34
> 35
> 36
> 37
> 38
> 39
> 40
> ```

| In the HTML | In the entry |
|---|---|
| `id="username"` | `"id": "username"`. Without an `id` attribute, as on the password field: `""`. |
| `name="pwd"` | `"name": "pwd"`. Without a `name` attribute, as on the button: `""`. |
| `type="email"` | `"type": "email"`. A `<select>` gives `"select-one"`; a `<button>` without a `type` attribute gives `"submit"`, the default type of a button in HTML. |
| `<option value="CORP">Corporate</option>`, chosen in the list of the row | `"value": "CORP"`: the value of the option, not its displayed text. |
| `<button …>Sign in</button>` | `"value": ""`: the text of a `<button>` is not its value. |
| `<select …>` | `"tag": "select"`, the name of the tag in lowercase. |

The row added with `+` is named `newitem` followed by a number; it is renamed `domain` here, which changes nothing for the injection (see [Entry names](#entry-names)).

> **Other buttons, other values**
>
> | In the HTML | In the entry |
> |---|---|
> | `<input type="submit" value="Sign in">` | `"type": "submit"`, `"value": "Sign in"`, `"tag": "input"`. On a `submit`, `value` is a criterion: the entry depends on the text of the button (see [A button found by its text](#finding-the-element)). |
> | `<button type="button" id="next">Next</button>` | `"id": "next"`, `"type": "button"`, `"value": ""`, `"tag": "button"`. |
> | `<a class="btn-signin" href="#">Sign in</a>` | `"id": ""`, `"type": ""`, `"tag": "a"` and a `selector` that designates this element only in the page. No `name` or `value` key: a link has neither. |
> | `<div role="button" class="submit">Sign in</div>` | `"id": ""`, `"tag": "div"` and a `selector`. No `name`, `type` or `value` key. |

### A login over two pages

The application asks for the login on a first page, then displays a second page, at another address, for the domain and the password. The configuration has two page addresses:

> **Configuration over two page addresses**
>
> ```
>  1
>  2
>  3
>  4
>  5
>  6
>  7
>  8
>  9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20
> 21
> 22
> 23
> 24
> 25
> 26
> 27
> 28
> 29
> 30
> 31
> 32
> 33
> 34
> 35
> 36
> 37
> 38
> 39
> 40
> 41
> 42
> 43
> 44
> 45
> 46
> 47
> 48
> 49
> 50
> 51
> 52
> 53
> 54
> 55
> 56
> 57
> 58
> 59
> 60
> 61
> 62
> 63
> 64
> 65
> 66
> 67
> 68
> 69
> 70
> 71
> ```

- **Each page has its own sequence**: only the entries of the page displayed are processed, so the numbering starts again at `1` on the second page. The names (`button` here) can be reused from one page to the other.
- `login` fills the field of the first page, `password` that of the second. Each page also has the other entry, with an `id` that no element carries, numbered after its last action (see [A `login` and a `password` entry on every page](#login-and-password-on-every-page)).
- `domain` chooses the option whose value is `CORP` in the list: a fixed value, the same for every user.
- The `delay` of `password` lets the page finish loading its field before typing into it.
- The connection link has no `id`, `name` or `type`: the `selector` designates it.

The plug-in captures one page at a time: open it on each page, save, and gather the page objects into one configuration, as above.

### Several steps at the same address

When the steps follow one another **without the address changing** (the next field appears in the same page), all the entries go under a single address, in the order of the steps. The search for each element waits for it to appear:

> **Four steps at the same address**
>
> ```
>  1
>  2
>  3
>  4
>  5
>  6
>  7
>  8
>  9
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20
> 21
> 22
> 23
> 24
> 25
> 26
> 27
> 28
> 29
> 30
> 31
> 32
> 33
> 34
> 35
> 36
> 37
> 38
> 39
> 40
> ```

Here `next` and `signin` designate the same button: the page reuses it from one step to the next. Two names are needed, since a name is unique within a page. The order does the rest: `password` waits for its field to appear, so `signin` is looked for only once the second step is displayed.

## How the injection runs

1. At the launch of the application, the configuration is prepared for the session. For a Web application, it is completed with the credentials and attached to the user's session; for an Isolate (Web) application, it is sent to the isolated browser together with the credentials.
2. When a page loads, its address is compared with the keys of the configuration. Without a match, nothing happens.
3. The entries of the page are processed one after the other, from the smallest `order` to the largest, by steps of one. For each entry, the page is searched for its element, every 100 ms until it appears; then the `delay` elapses, and the action is carried out. The next entry is searched for only once this action is carried out.
4. For a Web application, once the last entry of a page is processed, the configuration of this page is withdrawn from the session: the page is filled in **once per launch**. Coming back to it (after a logout, for instance) fills nothing in until the next launch of the application.

> **Numbers that follow on without a gap**
>
> The sequence moves from one `order` to the next by adding one. A missing number, or an `order` written as a string (`"2"`), stops the injection at that step. Two entries with the same `order`: only the first one, in the order of the text, is processed. After moving or deleting an entry by hand, renumber the following ones.

> **An element that never appears**
>
> The search for an element goes on as long as the page stays open. An entry whose criteria match no visible element (a renamed field, an `id` generated randomly) blocks the following entries: the fields before it are filled in, the following ones are not.

## The CyberElements SSO Configurator plug-in

The plug-in is downloaded from the [Toolbox](https://docs.cyberelements.io/saas/sl/Usage/AdminConsoleReference/Toolbox/) of the administration console. It opens in a panel on the left of the page, from its button in the toolbar of the browser or from the context menu of the page (**CyberElements SSO Configurator**).

### What it detects

At opening, the panel shows the address that will be the key of the configuration, and three rows pre-filled with the first visible element of each kind:

| Row | Element detected |
|---|---|
| `login` | a field of type `text`, `email` or `tel` |
| `password` | a field of type `password` |
| `button` | an element of type `submit` or `button`, an element whose role is `button`, or an element whose value is `Submit` |

Checkboxes, hidden fields and date, time, file, colour or range fields are never detected. When a row has no element, the panel displays **Please select login field** (or `password`, `button`) and waits for you to point at it.

This row has no bin. Saved without an element, it is not written, but it keeps its place in the numbering: the entries that follow it keep their number. When the page has no such field, save, then in the configuration renumber the entries so that the numbers follow on without a gap, and add the missing entry by hand, as described in [A `login` and a `password` entry on every page](#login-and-password-on-every-page).

### Correcting the configuration

| Control | Effect |
|---|---|
| target | points at another element of the page for this row |
| bin | deletes the row |
| drag handle | moves the row: the order of the rows is the `order` of the entries |
| `+` | adds a row for an element you point at: a list gives a `select` entry, with a list to choose the option; any other element gives a `button` entry |

Each row shows how the element will be found: `id`, otherwise `name`, otherwise `type`, otherwise the CSS selector.

### Saving

**Save Config** writes the configuration to the clipboard (**Configuration copied to clipboard**): one entry per row, numbered from `1` in the order of the panel. The value of the `login` and `password` fields is emptied; the plug-in never copies what was typed into them.

The plug-in never writes `delay`, and writes `selector` only for an element that it could not identify otherwise: add them by hand, as described in [Entry parameters](#entry-parameters).
