Skip to Content
Documentation

Two-factor

Authenticator app (TOTP), email codes and backup codes as a second step.

/two-factor/get-totp-uri

POST
/two-factor/get-totp-uri

Use this endpoint to get the TOTP URI

Request Body

application/json
  1. body
password?string

User password

Response Body

Successful response

application/json
  1. response
totpURI?string
Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/get-totp-uri' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "totpURI": "string"}

/two-factor/verify-totp

POST
/two-factor/verify-totp

Verify two factor TOTP

Request Body

application/json
  1. body
code*string

The otp code to verify. Eg: "012345"

trustDevice?boolean

If true, the device will be trusted for 30 days. It'll be refreshed on every sign in request within this time. Eg: true

Response Body

Successful response

application/json
  1. response
status?boolean
Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/verify-totp' \  -H 'Content-Type: application/json' \  -d '{  "code": "string"}'
Example Response
{  "status": true}

/two-factor/send-otp

POST
/two-factor/send-otp

Send two factor OTP to the user

Request Body

application/json
  1. body
trustDevice?boolean

Response Body

Successful response

application/json
  1. response
status?boolean
Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/send-otp' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "status": true}

/two-factor/verify-otp

POST
/two-factor/verify-otp

Verify two factor OTP

Request Body

application/json
  1. body
code*string

The otp code to verify. Eg: "012345"

trustDevice?boolean

Response Body

Two-factor OTP verified successfully

application/json
  1. response
token*string

Session token for the authenticated session

user*

The authenticated user object

Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/verify-otp' \  -H 'Content-Type: application/json' \  -d '{  "code": "string"}'
Example Response
{  "token": "string",  "user": {    "id": "string",    "email": "user@example.com",    "emailVerified": true,    "name": "string",    "image": "http://example.com",    "createdAt": "2019-08-24T14:15:22Z",    "updatedAt": "2019-08-24T14:15:22Z"  }}
POST
/two-factor/verify-backup-code

Verify a backup code for two-factor authentication

Request Body

application/json
  1. body
code*string

A backup code to verify. Eg: "123456"

disableSession?boolean

If true, the session cookie will not be set.

trustDevice?boolean

If true, the device will be trusted for 30 days. It'll be refreshed on every sign in request within this time. Eg: true

Response Body

Backup code verified successfully

application/json
  1. response
user*

The authenticated user object with two-factor details

session*

The current session object, included unless disableSession is true

Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/verify-backup-code' \  -H 'Content-Type: application/json' \  -d '{  "code": "string"}'
Example Response
{  "user": {    "id": "string",    "email": "user@example.com",    "emailVerified": true,    "name": "string",    "image": "http://example.com",    "twoFactorEnabled": true,    "createdAt": "2019-08-24T14:15:22Z",    "updatedAt": "2019-08-24T14:15:22Z"  },  "session": {    "token": "string",    "userId": "string",    "createdAt": "2019-08-24T14:15:22Z",    "expiresAt": "2019-08-24T14:15:22Z"  }}
POST
/two-factor/generate-backup-codes

Generate new backup codes for two-factor authentication

Request Body

application/json
  1. body
password?string

The users password.

Response Body

Backup codes generated successfully

application/json
  1. response
status*true

Indicates if the backup codes were generated successfully

Value intrue
backupCodes*array<string>

Array of generated backup codes in plain text

Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/generate-backup-codes' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "status": true,  "backupCodes": [    "string"  ]}

/two-factor/enable

POST
/two-factor/enable

Enable two factor authentication. Pass method 'totp' (default) to set up an authenticator app (returns TOTP URI and backup codes), or 'otp' to enable email/SMS-based codes immediately.

Request Body

application/json
  1. body
password?string

User password

method?string
Value in"otp""totp"
issuer?string

Custom issuer for the TOTP URI

Response Body

Successful response

application/json
  1. response
method*string

The 2FA method that was enabled.

Value in"otp""totp"
totpURI?string

TOTP URI for authenticator app setup. Only present when method is 'totp'.

backupCodes?array<string>

Recovery backup codes. Only present when method is 'totp'.

Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/enable' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "method": "otp",  "totpURI": "string",  "backupCodes": [    "string"  ]}

/two-factor/disable

POST
/two-factor/disable

Use this endpoint to disable two factor authentication.

Request Body

application/json
  1. body
password?string

User password

Response Body

Successful response

application/json
  1. response
status?boolean
Example Request
curl -X POST 'https://auth.example.com/api/auth/two-factor/disable' \  -H 'Content-Type: application/json' \  -d '{}'
Example Response
{  "status": true}