Skip to main content

Generate MFA OTP

Generate MFA OTP code for login verification using temporary token from login.

Quick Navigation

Endpoint

POST /api/v1/auth/mfa/otp/generate

Headers

HeaderRequiredDescription
Content-TypeYesapplication/json

Request Body

{
"temporary_token": "temp_token_from_login",
"method": "email_otp"
}

Parameters

FieldTypeRequiredDescription
temporary_tokenstringYesTemporary token from login when MFA is required
methodstringYesMFA method: "email_otp" or "totp"

Validations

  • Temporary token validation
  • Token expiration check
  • User account status check
  • Session validation
  • MFA method availability check

Response

Success (200)

{
"success": true,
"data": {
"temporary_token": "new_temp_token_for_verification",
"message": "MFA OTP generated successfully"
},
"message": "MFA OTP generated successfully"
}

Error Codes

StatusCodeDescription
400INVALID_REQUESTInvalid request parameters
401INVALID_TEMPORARY_TOKENInvalid or expired temporary token
401USER_NOT_FOUNDUser not found or disabled
404SESSION_NOT_FOUNDSession not found
422VALIDATION_ERRORRequest validation failed

Data Flow

  1. Token Validation

    • Validate temporary token from Redis
    • Check token expiration
    • Extract user ID and session ID
  2. User Validation

    • Verify user exists and is not disabled
    • Check account status
  3. Session Validation

    • Verify session exists
    • Check session is valid
  4. MFA Method Processing

    • For email_otp:
      • Generate 6-digit OTP code
      • Store OTP in Redis (10 minute expiry)
      • Send OTP via email
    • For totp:
      • Prepare for TOTP verification
      • No OTP sent (user enters code from app)
  5. Token Refresh

    • Create new temporary token for verification step
    • Store challenge information in token
  6. Audit Logging

    • Log MFA OTP generation event

Features

  • Generates email OTP or prepares TOTP verification
  • Creates temporary token for verification
  • Sends email OTP automatically for email_otp method
  • Returns temporary token for verification step
  • Supports both email OTP and TOTP methods

Example

curl -X POST https://api.rivergen.com/api/v1/auth/mfa/otp/generate \
-H "Content-Type: application/json" \
-d '{
"temporary_token": "temp_token_from_login",
"method": "email_otp"
}'