This page is for admins who make Buttons. The last part is also for the developers of the Target.

An Interface button has two modes. **Builder** opens the Interface view that you build in Interface Builder.
**Direct iframe** opens your own web page, the Target, in a window over Pipedrive. On each press, OneClick adds an
encrypted token to the Target URL. The Target decrypts the token with the key of the Button. The token tells the
Target which Pipedrive user pressed the Button, and it carries the headers of the Button.

## How a Direct iframe press works

1. A Pipedrive user clicks the Interface button in the Panel or in the Floating window.
2. A window opens over Pipedrive and shows a loading indicator.
3. OneClick checks the user and makes a new token on the OneClick server. The key of the Button encrypts the token.
4. The window opens the Target URL with the token and the values in
   [What OneClick adds to the Target URL](#what-oneclick-adds-to-the-target-url).
5. The Target decrypts the token and then shows its content.

If OneClick cannot make the token, the window shows **The Target was not opened** and a message. OneClick never
opens the Target without the token. See [Messages in the window](#messages-in-the-window).

OneClick keeps no Button log of a Direct iframe press.

## Set up Direct iframe mode

1. Open the Interface button in the Button editor. To make a new Interface button, do steps 1 to 5 of
   [Make an Interface button](/docs/buttons/interface-button#make-an-interface-button).
2. In the **Button** section, click **Direct iframe** under **Interface**. The menu shows the **Token** section.
3. Type the **Target URL**.
4. Type the **Button text**.
5. Click **Token** in the menu.
6. Copy the key from **Key** and give it to the developer of the Target.
7. Change **Query parameter name** and **Token lifetime (seconds)** if necessary.
8. Click **Save**.

The Target must send the header `Content-Security-Policy: frame-ancestors https://*.pipedrive.com`. Without it, the
browser does not show the Target in the window.

## The Button section

In Direct iframe mode, the **Button** section has these settings:

- **Interface** selects the mode: **Builder** or **Direct iframe**. The text under it tells what a press opens.
- **Target URL** is the address of the Target. It must be an absolute `https:` URL, for example
  `https://your-app.example/path`. The URL is static: it has no values from Pipedrive fields.
- **Interface width** and **Interface height** set the size of the window, as in Builder mode. See
  [The settings of an Interface button](/docs/buttons/interface-button#the-settings-of-an-interface-button).
- **Button text** and **Description (optional)** are the same as in Builder mode.

![The Button section of a new Interface button with Interface set to Direct iframe, the Target URL and the help texts](https://res.cloudinary.com/zimple/image/upload/f_auto,q_auto/oneclick-docs/buttons/interface-button/sections/direct-iframe/button-section.png)

Direct iframe mode has no **Open interface builder** button. The Button list also does not show the icon
**Open interface builder** for this Button. The list shows the label **Direct iframe** next to the Button.

An Interface view that you built for the Button stays. The section then shows **Your built interface is kept. Switch
back to Builder to use it again.** When you switch back to Builder, OneClick keeps the Target URL and the key.

## What OneClick adds to the Target URL

On each press, OneClick adds these query parameters to the Target URL:

| Parameter        | Value                                                                                              |
| ---------------- | -------------------------------------------------------------------------------------------------- |
| `resource`       | The type of the record, for example `deal`.                                                        |
| `resource_id`    | The ID of the record. Two or more IDs have commas between them.                                    |
| `domain_id`      | The ID of the Button.                                                                              |
| `event_id`       | A new ID for each press.                                                                           |
| `id`             | The ID of the window in Pipedrive. The Target uses it with the Pipedrive SDK to resize the window. |
| `oneclick_token` | The token. **Query parameter name** sets the name of this parameter.                               |

If the Target URL already has a query parameter with one of these names, OneClick replaces it. The other query
parameters and the fragment of the URL stay.

A Button in the Floating window belongs to no record. OneClick then does not add `resource` and `resource_id`, and
the token does not contain them. The Target must work without them. See
[A Floating window Button gets no Pipedrive record](/docs/buttons#a-floating-window-button-gets-no-pipedrive-record).

## The Token section

The **Token** section shows only in Direct iframe mode.

![The Token section of a new Interface button with the hidden key, Generate a new key, Query parameter name and Token lifetime (seconds)](https://res.cloudinary.com/zimple/image/upload/f_auto,q_auto/oneclick-docs/buttons/interface-button/sections/direct-iframe/token-section.png)

| Setting                      | Default          | Rules                                                                                  |
| ---------------------------- | ---------------- | -------------------------------------------------------------------------------------- |
| **Key**                      | A new random key | A 256-bit key in Base64URL text. Passwords are not accepted.                           |
| **Query parameter name**     | `oneclick_token` | Starts with a letter. Letters, digits, hyphens and underscores. 64 characters or less. |
| **Token lifetime (seconds)** | 60               | From 15 to 86400 seconds.                                                              |

The query parameter name cannot be `resource`, `resource_id`, `domain_id`, `event_id` or `id`. OneClick already sends
these parameters.

### The key

When you select **Direct iframe** for a Button without a key, OneClick makes a new key. You can also paste a 256-bit
Base64URL key of your own. A key of 32 bytes is 43 characters long, or 44 characters with the `=` padding at the end.

After you make or paste a key, the section shows **Copy this key to the Target now. After you save, only you can
reveal it again.** OneClick encrypts the key and never sends it to the browser of a user. When you open the saved
Button again, the field hides the key:

- The admin who made the key can click **Reveal** to show it again.
- For other admins, the key stays hidden. The section tells who made the key. Other admins can still replace it.

**Generate a new key** replaces the key. After you save, tokens with the old key fail. Give the new key to the Target
at the same time.

### A Button without a key

A Button transfer does not copy the key. The Button then has no key:

- The Button list shows the label **No key** next to the Button.
- The **Token** section shows **This Button has no key.** and the button **Generate a key**.
- A press shows an error and does not open the Target.

Click **Generate a key**, give the key to the Target and click **Save**.

## Headers in the token

When the **Headers** section is on, the token contains the name and the value of each header of the Button. This
includes the values of confidential headers. Only the Target can read them, because only the Target has the key. The
token does not contain the headers `X-oc-user-id`, `X-oc-company-id` and `X-oc-event-id`.

For the Headers section, see [Headers](/docs/buttons/workflow-button/sections/headers).

### Confidential headers and the key

The admin who has the key can read each header value in the token. Thus OneClick lets only the creator of the key add
confidential headers to an Interface button in Direct iframe mode:

- In Direct iframe mode, only the creator of the key can turn on **Confidential** for a header. For other admins, the
  switch shows **Only the creator of the Direct iframe key can add a confidential header**.
- The key of a deleted user counts as the key of another admin.

A confidential header that another admin added locks some settings for you:

- You cannot select **Direct iframe**. A tooltip shows **You cannot switch to Direct iframe, as this button contains
  confidential headers added by users other than you**.
- You cannot change the **Target URL**. The field shows **You cannot edit the URL, as this button contains
  confidential headers added by users other than you**.
- You cannot replace the key. The section shows **You cannot replace the key, as this button contains confidential
  headers added by users other than you**.

You can always switch back to **Builder**.

When you select **Direct iframe**, the Button can have your own confidential headers and a key of another admin.
OneClick then makes a new key and shows **A new key was generated. Update it in your Target.** Give the new key to the
Target.

## Copies and transfers

- A copy of the Button in the same Pipedrive company keeps the key and its creator.
- A [Button transfer](/docs/buttons/transfer-a-button) to another Pipedrive company does not copy the key. The
  mode, the Target URL, the query parameter name and the token lifetime stay. OneClick shows **Transferred. The Direct iframe
  key is not transferred. An admin of the target Organization must generate a new key.** An admin of the target
  company must then [generate a key](#a-button-without-a-key).
- A copy from the Partner Portal also does not copy the key. See
  [What a copy leaves behind](/docs/partner-portal/buttons/what-a-copy-leaves-behind).

## Messages in the window

When OneClick cannot open the Target, the window shows **The Target was not opened** and one of these messages. Click
**Close** to close the window.

| Message                                                                                                                                                     | Cause                                                                                       |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| **This Button cannot open its Target. The Button has no key. An admin must generate a new key in OneClick Settings before the Button can open its Target.** | The Button has no key. [Generate a key](#a-button-without-a-key).                           |
| **This Button cannot open its Target. OneClick did not find the Button in your Organization.**                                                              | The Button is not in your company, for example after an admin deleted it. Reload Pipedrive. |
| **This Button cannot open its Target. The Button is no longer a Direct iframe Button.**                                                                     | An admin switched the Button back to Builder. Reload Pipedrive and press the Button again.  |
| **This Button cannot open its Target. Pipedrive did not confirm your user status.**                                                                         | OneClick could not get the user status from Pipedrive. Press the Button again.              |
| **This Button cannot open its Target. OneClick could not encrypt the token.**                                                                               | OneClick could not make the token. Ask an admin to check the Target URL and the key.        |
| **This Button cannot open its Target. Close this window and press the Button again.**                                                                       | Another error. Press the Button again.                                                      |

## Decrypt the token on the Target

The token is a [JSON Web Encryption](https://datatracker.ietf.org/doc/html/rfc7516) (JWE) in the compact form, with
the algorithm `dir` and the encryption `A256GCM`. Many JWT libraries cannot decrypt a JWE, for example
`jsonwebtoken`. To decrypt the token, the Target does these steps:

1. Read the token from the query parameter.
2. Decode the Base64URL key into its 32 bytes. Use these bytes as the key, not the text of the key.
3. Decrypt the token with AES-256-GCM. Accept only the algorithm `dir` and the encryption `A256GCM`.
4. Make sure that the time in `exp` is not in the past.
5. Make sure that `aud` is the origin of the Target URL.
6. Use the claims, for example to find the Pipedrive user.

The token has these claims:

| Claim           | Type    | Value                                                                                       |
| --------------- | ------- | ------------------------------------------------------------------------------------------- |
| `company_id`    | number  | The ID of the Pipedrive company.                                                            |
| `user_id`       | number  | The ID of the Pipedrive user who clicked the Button.                                        |
| `is_user_admin` | boolean | `true` if the user is a Pipedrive admin.                                                    |
| `domain_id`     | string  | The ID of the Button.                                                                       |
| `event_id`      | string  | A new ID for each press.                                                                    |
| `aud`           | string  | The origin of the Target URL, for example `https://your-app.example`.                       |
| `headers`       | object  | The name and the value of each header of the Button. Empty when the Headers section is off. |
| `resource`      | string  | The type of the record. Not in a token of a Floating window Button.                         |
| `resource_id`   | string  | The ID of the record. Not in a token of a Floating window Button.                           |
| `iat`           | number  | The time when OneClick made the token, in seconds since 1970.                               |
| `exp`           | number  | The time when the token expires, in seconds since 1970.                                     |

`resource` and `resource_id` have the same values as the query parameters. The browser of the user tells them to
OneClick, and OneClick does not check them. A user can get a token for each record ID. Do not use them for access
control. To find a change to the URL after the press, compare them with the query parameters.

OneClick makes a new token for each press, but it does not prevent a second use of a token. If the Target must
accept a token only one time, it must keep a list of the used `event_id` values until the tokens expire.

The `is_user_admin` value is never more than five minutes old: OneClick checks the admin status with Pipedrive again
when the stored status is older.

The token stays valid only for the token lifetime. OneClick does not refresh it. After the Target decrypts the token,
the Target starts its own session for the user.

The token stays in the browser history and in the access logs of the Target after it expires. A person who gets the
key later can read the header values in these tokens. Keep the key secret, and keep the token lifetime short.

For an example in Node.js, see
[Decrypt a Direct iframe token](/docs/using-oneclick-with/nodejs/decrypt-a-direct-iframe-token).
