Consumer Authentication

/

API reference

/

One-time passcodes (OTP)

/

Authenticate

Authenticate one-time passcode

POSThttps://test.stytch.com/v1/otps/authenticate

Authenticate a User given a method_id (the associated email_id or phone_id) and a code. This endpoint verifies that the code is valid, hasn't expired or been previously used, and any optional security settings such as IP match or user agent match are satisfied. A given method_id may only have a single active OTP code at any given time, if a User requests another OTP code before the first one has expired, the first one will be invalidated.


Body parameters


method_id*string

code*string

optionsobject

attributesobject

session_custom_claimsmap<string, any>

session_duration_minutesint

session_jwtstring

session_tokenstring

Response fields


status_codeint

request_idstring

method_idstring

user_idstring

userobject

email_idstring

session_tokenstring

session_jwtstring

sessionobject

reset_sessionsboolean
curl --request POST \
  --url https://test.stytch.com/v1/otps/authenticate \
  -u 'PROJECT_ID:SECRET' \
  -H 'Content-Type: application/json' \
  -d '{
    "method_id": "phone-number-test-d5a3b680-e8a3-40c0-b815-ab79986666d0",
    "code": "123456"
  }'

RESPONSE

200
{
  "status_code": 200,
  "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
  "user_id": "user-test-16d9ba61-97a1-4ba4-9720-b03761dc50c6",
  "user": {...},
  "method_id": "phone-number-test-d5a3b680-e8a3-40c0-b815-ab79986666d0",
  "reset_sessions": false,
  "session_jwt": "",
  "session_token": "",
  "session": null
}

Common Error Types