Skip to content

Sync Time ​

Returns the server's current timestamp and the TOTP configuration, so the device can detect clock drift. Because a code is only valid for 15 seconds, a device clock a minute out will fail every validation.

Endpoint ​

http
POST /api/v1/saas-sotp/sync-time
Content-Type: application/json
json
{
  "partner_id": "{{partner_id}}",
  "partner_key": "{{partner_key}}",
  "token": "{{token}}",
  "app_id": "{{app_id}}",
  "client_timestamp": "1672204839",
  "period": 15,
  "otp": "123456",
  "previous_otp": "654321"
}

Parameters:

ParamTypeRequiredDefaultDescription
partner_idstringYes—The partner id.
partner_keystringYes—The partner key.
tokenstringYes—The registration token generated by Register.
periodintYes—The number of seconds an OTP stays valid.
app_idstringNo—The app id, used for tracking.
client_timestampintNo—The client's current timestamp.
otpstringNo—The current smart OTP.
previous_otpstringNo—The OTP from the previous time block.

Supplying otp and previous_otp lets the server work out how far the device clock has drifted, by finding which time block the codes actually belong to.

Returns: SyncTimeResponse

Sample Request ​

bash
curl --location --request POST '<BASE_URL>/saas-sotp/sync-time' \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --data-raw '{
    "partner_id": "{{partner_id}}",
    "partner_key": "{{partner_key}}",
    "token": "{{token}}",
    "app_id": "{{app_id}}",
    "client_timestamp": "1672204839",
    "period": 15,
    "otp": "123456",
    "previous_otp": "654321"
  }'

Response ​

json
{
  "success": true,
  "code": 1,
  "message": "Success",
  "data": {
    "timestamp": "1666756646",
    "period": 15,
    "algorithm": "HmacSHA512",
    "length": 6,
    "type": "totp",
    "issuer": "SOTP"
  }
}
FieldTypeDescription
successboolRequest status.
codeintThe status code — 1 on success.
messagestringThe status or error message.
data.timestampintThe server timestamp.
data.periodintThe number of seconds an OTP stays valid.
data.algorithmstringThe HMAC algorithm — HmacSHA512.
data.lengthintThe number of digits in an OTP code.
data.typestringThe type of soft OTP — totp.
data.issuerstringThe issuer that generated the OTP.

Errors ​

CodeDescription
103Thông tin Partner không chính xác — Partner details are incorrect.
129Token không hợp lệ — Invalid token.
190108Tài khoản chưa hoạt động — Account not activated.
190301Period không chính xác — Incorrect period.
190303Client time không chính xác — Incorrect client time.

190303 is the drift signal: the device clock is too far from the server's. Apply the returned timestamp as an offset rather than asking the user to fix their clock.

Next Steps ​

  • Validate OTP — retry validation once the clock is reconciled
  • Activate — where the same TOTP configuration is first issued

Developers