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

# Enable two-factor authentication

> Turns on two-factor authentication with the secret from `POST /v1/two-fa/config` and a current code from your authenticator app. Returns 8 single-use recovery codes; store them safely, they aren't shown again. Your account must be verified.



## OpenAPI

````yaml /spec/platform-auth.yaml post /v1/two-fa
openapi: 3.0.1
info:
  title: Authentication & Account
  version: 1.0.0
  description: >-
    Log in, issue API tokens, change or reset your password, set up two-factor
    authentication, verify your email address and phone number, and manage your
    account profile and billing contact details.
servers:
  - url: https://api.liara.ir
security:
  - bearerAuth: []
tags:
  - name: Login
    description: Exchange your credentials or a one-time code for an API token.
  - name: Registration
    description: Create a new account.
  - name: Password
    description: Change your password while logged in, or reset a forgotten one.
  - name: API Tokens
    description: Issue additional API tokens for your account.
  - name: Account
    description: Read and update your profile and billing contact details.
  - name: Two-Factor Authentication
    description: Set up and manage authenticator-app (TOTP) two-factor authentication.
  - name: Verification
    description: Verify, or change, your account's email address and phone number.
paths:
  /v1/two-fa:
    post:
      tags:
        - Two-Factor Authentication
      summary: Enable two-factor authentication
      description: >-
        Turns on two-factor authentication with the secret from `POST
        /v1/two-fa/config` and a current code from your authenticator app.
        Returns 8 single-use recovery codes; store them safely, they aren't
        shown again. Your account must be verified.
      operationId: enableTwoFA
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - secretCode
                - token
              properties:
                secretCode:
                  type: string
                  description: The `secretCode` from `POST /v1/two-fa/config`.
                token:
                  type: string
                  minLength: 6
                  maxLength: 6
                  description: Current 6-digit code from your authenticator app.
            example:
              secretCode: <base32-secret>
              token: '123456'
      responses:
        '200':
          description: Two-factor authentication is on.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RecoveryCodesResponse'
              example:
                recoveryCodes:
                  - A1B2C3D4E5
                  - F6A7B8C9D0
                  - ...
        '400':
          description: >-
            The body is invalid, `token` isn't numeric (`invalid_token`), or the
            code is wrong or two-factor authentication is already enabled
            (`enable_two_fa_failed`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 400
                error: Bad Request
                message: Enable TwoFA failed.
                data:
                  code: enable_two_fa_failed
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/AccountVerificationRequired'
components:
  schemas:
    RecoveryCodesResponse:
      type: object
      properties:
        recoveryCodes:
          type: array
          description: 8 single-use recovery codes, 10 characters each.
          items:
            type: string
    Error:
      type: object
      description: Standard error body.
      properties:
        statusCode:
          type: integer
        error:
          type: string
          description: HTTP status text.
        message:
          type: string
          description: What went wrong.
        data:
          type: object
          nullable: true
          description: >-
            Extra details. When present, `code` is a stable, machine-readable
            error code.
          properties:
            code:
              type: string
    AuthError:
      type: object
      description: Error body returned when the API token is rejected.
      properties:
        error:
          type: string
  responses:
    Unauthorized:
      description: The API token is missing, invalid or expired.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AuthError'
          example:
            error: Unauthorized.
    AccountVerificationRequired:
      description: >-
        Your account isn't verified yet. Set your full name and verify your
        email address, phone number and national code first.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 403
            error: Forbidden
            message: You must verify your account, first.
            data:
              code: account_verification_required
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send your API token as `Authorization: Bearer <api-token>`. Tokens
        expire (30 days by default) and stop working when you change or reset
        your password.

````

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