> ## Documentation Index
> Fetch the complete documentation index at: https://docs.asteroid.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Two-factor sign-in

> How a workflow gets sign-in codes: an authenticator setup key, the profile's email inbox, or a person.

## Pick a method

| Method | Supported | How |
| - | - | - |
| **Authenticator app** | Yes. Recommended. | Store the setup key on the secret. The workflow generates the codes. |
| **Email code** | Yes, Startup plan and above. | Forward the code to the profile's email inbox. An agent node reads it. |
| **SMS or phone call** | Not directly. | Forward texts to the profile's email inbox, switch to an authenticator app, or a person enters the code during the run. |
| **Push approval** | No. | A person approves on their phone during the run. |

Use a login made for the workflow, such as a service account.

## Authenticator app

**1. Get the setup key**

Turn on two-factor with an authenticator app on the portal. Copy the setup key. If the site shows only a QR code, take a screenshot of it.

**2. Store it on the secret**

On the **Secrets** tab of the **Logins** page, add a TOTP seed field to the portal's username and password secret. Paste the setup key or an `otpauth://totp/` link, or upload the QR code screenshot. Check that the live code matches your authenticator app.

**3. Use it**

An agent node generates codes with the Generate TOTP skill. A script uses `asteroid.generateTotp`.

```javascript theme={null}
const asteroid = require('asteroid');

module.exports = async ({ page }) => {
  await page.fill('#otp', asteroid.generateTotp('##MY_PORTAL.TOTP_SEED##'));
};
```

> [!WARNING]
>
> Keep your own copy of the setup key. A TOTP seed is write-only.

Generate the code right before you submit it. See [Two-factor codes](https://docs.asteroid.ai/concepts/scripting-runtime.md#two-factor-codes).

To collect a setup key from the account owner, send a request from the **Requests** tab of the **Logins** page. Requests need the Startup plan or above. See [Collect secrets in your own app](https://docs.asteroid.ai/integrate/collect-credentials.md).

## Email codes

In the mailbox that receives the codes, add a forwarding rule that sends them to the profile's inbox, `{prefix}@agentmail.asteroid.ai`. An agent node reads the code with `get_mail`. Scripts cannot read mail. Needs the Startup plan or above. See [Email inbox](https://docs.asteroid.ai/concepts/emails.md).

## SMS, push and other methods

To forward SMS codes to the profile's email inbox, use a third-party tool, such as an Apple Shortcut. The workflow then reads them as email codes.

Otherwise, a person enters the code, or approves the push, while the run waits.

* **Agent node:** turn on **Ask User Questions**. The run pauses with `paused_by_agent`. Reply on the execution page, or with `POST /executions/{id}/user-messages`. See [Ask user question](https://docs.asteroid.ai/concepts/node-capabilities.md#ask-user-question).
* **Script:** ask with `waitForReply`. Answer on the execution page, with `asteroid execution answer`, or with `POST /executions/{id}/answers`. See [Ask a question](https://docs.asteroid.ai/concepts/scripting-runtime.md#ask-a-question).

To be told when a run waits, send `EXECUTION_PAUSED` to a webhook or Slack. See [Webhooks and Slack](https://docs.asteroid.ai/operate/webhooks-and-slack.md).

> [!WARNING]
>
> An unanswered agent question ends the run at the workflow's timeout. An unanswered script question throws `ReplyTimeoutError`. For unattended runs, use an authenticator app.

For another two-factor setup, [contact support](https://docs.asteroid.ai/support-security/support.md).

## Fewer codes

Reuse the session so runs sign in less often. Set **Auth strategy** in the environment's **Auth** step.

| Auth strategy | What it does |
| - | - |
| **Save sign-in** | Each execution saves its session for the next. Browser only. |
| **Warm cache** | A sign-in workflow refreshes the session on a timer. Browser only. |
| **Warm pool** | Keeps signed-in environments ready. Use it when speed matters or sign-in is slow. |

See [Warm cache](https://docs.asteroid.ai/concepts/environments.md#warm-cache) and [Warm pool](https://docs.asteroid.ai/concepts/environments.md#warm-pool).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.