# POST /auth/login/second-factor

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the auth group.

Complete sign-in with an authenticator app code or a recovery code

- Who may call it: anyone (no token needed)
- Answers: 200 OK

Submit the challenge from POST /auth/login with code for an authenticator app code or recovery_code for a recovery code. If both are supplied, UrbeStack uses recovery_code. The selected code must contain 1 to 40 characters drawn from word characters, spaces, and hyphens.

The challenge is valid for this step only and expires after two minutes or on the fifth wrong code. It must be submitted from the IP address that started sign-in. Presenting it from another IP address invalidates it. A successful request consumes the challenge and any recovery code used, then returns token, expires_at, and user. The session is bound to that same IP address. UrbeStack records up to 255 characters from User-Agent for the session list when the client sends it.

A blocked client IP address or an invalid code returns 401. An invalid or expired challenge, a challenge for an inactive account, or a fifth wrong code also returns 401 and directs the client to restart at POST /auth/login. A request that passes the login policy check but lacks a client IP address returns 500. Wrong codes count as failed sign-ins for both ban rules and the login policy. Ten wrong codes flag the client IP address just as ten wrong passwords do.

## As a command

- [urbestack-login-second-factor](https://urbestack.com/docs/commands/urbestack-login-second-factor.md): Verifies the second factor for a login and opens a session when the code is accepted.

## Request body

JSON, the type [SecondFactorLogin](https://urbestack.com/docs/api/types/SecondFactorLogin.md).

- `challenge` (string, up to 64 characters, required)
- `code` (string, up to 16 characters): Six-digit code displayed by the authenticator app.
- `recovery_code` (string, up to 40 characters): Single-use recovery code that can be supplied in place of code. Using it consumes it.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/auth/login/second-factor" \
  -H "Content-Type: application/json" \
  -d '{
    "challenge": "text",
    "code": "text",
    "recovery_code": "text"
  }'
```

Response, 200 OK:

```
{
  "challenge": "text",
  "enrol_second_factor": true,
  "expires_at": "2026-09-16T10:15:00Z",
  "second_factor": true,
  "token": "ub_9f3c2a7e1b5d4082a6c1e7f0",
  "user": {
    "backups": true,
    "bandwidth_bytes": 1,
    "bandwidth_cut": true,
    "bandwidth_cut_at": "text",
    "bandwidth_limit_bytes": 1,
    "created_at": "2026-09-09T10:15:00Z",
    "customers": 1,
    "disk_limit_bytes": 1,
    "email": "alice@example.com",
    "home": "text",
    "id": 1,
    "move_state": "leaving",
    "name": "alice",
    "owner": "text",
    "owner_id": 1,
    "package": "basic",
    "package_backups": true,
    "package_id": 1,
    "package_shell": true,
    "role": "user",
    "second_factor": true,
    "shell": true,
    "status": "active",
    "system_password": true,
    "uid": 1
  }
}
```

## Errors

- 400: A <kind> token needs the client's address
- 400: A plugin's token names its scopes
- 400: A session is opened by a panel user: name one with --actor
- 400: A session opened for a user is a session
- 400: Invalid <what>: expected a non-negative integer
- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid id
- 400: Invalid label: 1 to 64 printable ASCII characters
- 400: Invalid user agent: 1 to 255 printable ASCII characters
- 400: Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
- 400: Username '<value>' is reserved
- 401: Challenge expired; sign in again
- 401: Invalid code
- 403: <opener.name> may not open the panel of <owner>
- 403: Only a customer's panel is opened: <owner> is an administrator
- 403: User '<owner>' is suspended
- 404: Token <id> not found
- 404: User '
