Get your free beta license ↗
API operation · auth group
POST

/auth/login/second-factor

First published 3 Oct 20260.1.0Unchanged since publication

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

Who may call it
Anyone (no token needed)
Token
none
Answers200 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

Run as root on the server

Request body

JSON ·SecondFactorLogin· 3 fields
challengestring, up to 64 charactersRequired
codestring, up to 16 characters
Six-digit code displayed by the authenticator app.
recovery_codestring, up to 40 characters
Single-use recovery code that can be supplied in place of code. Using it consumes it.

Example

See the API overview for how to set $API and $TOKEN.
Request
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

19 errors, each a status and a sentence
400A <kind> token needs the client's address
400A plugin's token names its scopes
400A session is opened by a panel user: name one with --actor
400A session opened for a user is a session
400Invalid <what>: expected a non-negative integer
400Invalid IPv4 address
400Invalid IPv6 address
400Invalid id
400Invalid label: 1 to 64 printable ASCII characters
400Invalid user agent: 1 to 255 printable ASCII characters
400Invalid username: 2 to 32 lowercase letters, digits or underscores, starting with a letter
400Username '<value>' is reserved
401Challenge expired; sign in again
401Invalid code
403<opener.name> may not open the panel of <owner>
403Only a customer's panel is opened: <owner> is an administrator
403User '<owner>' is suspended
404Token <id> not found
404User '
Generated from release 0.2.35 (current) · the API’s own descriptionThis entry has been unchanged since it was first published in release 0.1.0 on 3 Oct 2026.
urbestack.com/docs/api/post-auth-login-second-factor/