Skip to main content

Two Factor Auth - Enable

Endpoint

/i/two-factor-auth?method=enable

Overview

Enables 2FA for the authenticated user after validating a 6-digit auth code against the provided secret token.

Authentication

Countly API supports three authentication methods:

  1. api_key=YOUR_API_KEY
  2. auth_token=YOUR_AUTH_TOKEN
  3. countly-token: YOUR_AUTH_TOKEN

Permissions

Requires authenticated user context.

Request Parameters

ParameterTypeRequiredDescription
methodStringYesMust be enable.
api_keyStringYes (or use auth_token)API key for authentication.
auth_tokenStringNoAuth token as query parameter or countly-token header.
secret_tokenStringYesSecret used for TOTP verification.
auth_codeStringYes6-digit TOTP code. Must match ^\d{6}$.

Response

Success Response

{
"result": "Enabled 2FA for user"
}

Response Fields

FieldTypeDescription
resultStringResult message.

Error Responses

  • 400
{
"result": "Invalid 2FA code"
}
  • 401
{
"result": "Failed to authenticate"
}
  • 500
{
"result": "Error during verification"
}

Behavior/Processing

  • Validates code format first (6 digits).
  • Verifies TOTP with otplib.
  • Stores encrypted secret and sets two_factor_auth.enabled=true.
  • Emits system log action: two_factor_auth_enabled.

Database Collections

CollectionUsed forData touched by this endpoint
countly.membersUser account settingsUpdates two_factor_auth.enabled and encrypted two_factor_auth.secret_token.
countly.systemlogsAudit trailReceives two_factor_auth_enabled action.

Examples

Enable 2FA

/i/two-factor-auth?api_key=YOUR_API_KEY&method=enable&secret_token=JBSWY3DPEHPK3PXP&auth_code=123456

Last Updated

2026-03-05