Skip to content

Start authenticator setup

POST
/v1/auth/2fa/totp/setup
curl --request POST \
--url https://api.emite.cr/v1/auth/2fa/totp/setup \
--header 'Content-Type: application/json' \
--data '{ "password": "example" }'

Starts TOTP enrollment: generates a secret, stored encrypted and unconfirmed, and returns what an authenticator app needs: the otpauth:// URI (otpauthUrl), the same as a QR code (qrCodeDataUrl, a PNG data URL) and the key for manual entry (manualKey). Requires the current password. Nothing is protected until POST /v1/auth/2fa/totp/confirm confirms it with a code; calling again replaces the unconfirmed secret. 409 TWO_FACTOR_ALREADY_ENABLED when the authenticator is already active (move it to another device with POST /v1/auth/2fa/totp/replace); 403 TWO_FACTOR_DEMO_FORBIDDEN in the demo.

Media typeapplication/json
object
password
required

The current password of the account: every change to the second factor asks for it again. A wrong one answers 400 INVALID_CURRENT_PASSWORD.

string
Examplegenerated
{
"password": "example"
}

What an authenticator app needs to add the account.

Media typeapplication/json
object
otpauthUrl
required

The otpauth:// URI an authenticator app reads (RFC 6238 TOTP: SHA-1, 6 digits, 30-second step), labelled with the account email and issued by EmiteCR. It carries the secret: show it only to the person, and never store it.

string
qrCodeDataUrl
required

The same URI as a QR code: a PNG data URL, 256 pixels wide, usable directly as the src of an <img>.

string
manualKey
required

The secret in base32, in groups of four separated by spaces: for typing it into the app when the QR cannot be scanned.

string
Example
{
"otpauthUrl": "otpauth://totp/EmiteCR:ventas%40emite.cr?secret=JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP&issuer=EmiteCR",
"qrCodeDataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA…",
"manualKey": "JBSW Y3DP EHPK 3PXP JBSW Y3DP EHPK 3PXP"
}