generateTOTP

📘 generateTOTP(userID) API

🧭 Purpose

The generateTOTP API initiates the generation of a Time-Based One-Time Password (TOTP) for a specified REL-ID user. It enables both online and offline authentication flows by generating a short-lived OTP code securely on the device.


🧩 Parameters

NameTypeRequiredDescription
userIDStringREL-ID user identifier for whom TOTP is generated

🚦 Trigger Flow

  1. App calls generateTOTP(userID)
  2. SDK checks:
    • If LDA (biometric/PIN) or password validation is needed
  3. If required, SDK emits getTOTPPassword event
  4. App collects and sends password using setTOTPPassword(password)
  5. SDK emits onTOTPGenerated with TOTP code and expiry

📤 Related Events

  • Triggered only if password-based authentication is required before generating TOTP.
  • App must prompt user for password and respond with setTOTPPassword(password).

  • Emitted after successful TOTP generation.
  • Payload includes the generated code, expiry time, and any error info.

✅ Example Payload

{
  "userID": "john.doe",
  "TOTP": "758192",
  "expiryTimeInSec": 30,
  "error": {
    "longErrorCode": 0,
    "shortErrorCode": 0,
    "errorString": "Success"
  }
}

🚨 Error Handling

The onTOTPGenerated event payload includes an error field which should be checked for:

Error CodeMeaningDeveloper Action
0SuccessProceed with displaying TOTP

📝 Notes

  • TOTP can be generated offline as well, using cached credentials and a device-stored secret.
  • Always display a countdown to indicate the time until TOTP expiry.
  • If TOTP expires, simply call generateTOTP(userID) again to refresh.

💻 Code Snippets


React Native
RdnaClient.generateTOTP(userID, (syncResponse) => {
  console.log("TOTP Response:", syncResponse);
});

Flutter
com.uniken.rdnaplugin.RdnaClient.generateTOTP("<userID>");

Cordova
com.uniken.rdnaplugin.RdnaClient.generateTOTP(
  successCallback,
  errorCallback,
  ["<userID>"]
);

Native iOS (Objective-C)
RDNAError *error = [rdnaClient generateTOTP:@"<userName>"];
if (error == nil) {
  // Handle success
}

Native Android (Java)
RDNA.RDNAError error = RDNA.generateTOTP("john.doe");
if (error == null) {
  // Handle success
}