onTOTPGenerated
š© onTOTPGenerated Event
onTOTPGenerated Eventš§ Purpose
The onTOTPGenerated event is emitted by the Ditto ID SDK after a TOTP has been successfully generated using the generateTOTP(userID) API.
This event provides the application with the one-time password and its validity duration.
š§¾ Event Payload
| Field | Type | Description |
|---|---|---|
userID | String | The Ditto ID user ID for whom the TOTP was generated |
TOTP | String | The 6-digit time-based one-time password |
expiryTimeInSec | Integer | Number of seconds before the TOTP expires |
error | Object | Contains error codes and messages, if any |
ā
Example Payload
{
"userID": "john.doe",
"TOTP": "758192",
"expiryTimeInSec": 30,
"error": {
"longErrorCode": 0,
"shortErrorCode": 0,
"errorString": "Success"
}
}šØ Error Object Fields
| Field | Type | Description |
|---|---|---|
longErrorCode | Number | 0 on success; non-zero on failure |
shortErrorCode | Number | Specific error subtype if applicable |
errorString | String | Text description of the result |
š¤ Developer Actions
- Use
TOTPandexpiryTimeInSecto display OTP and countdown timer - Check
error.longErrorCodeto handle success or failure
š» Code Snippets
š§Ŗ React Native
Pseudocode
let onTOTPGeneratedSubscription = rdnaEventRegistery.addListener(
'onTOTPGenerated',
this.onTOTPGenerated.bind(this)
);Response Data
Contains: userName, TOTP, expiryTimeInSec, error
Sample Response
Not Applicable for React Native
š¦ Flutter
Pseudocode
rdnaClient.on(RdnaClient.onTOTPGenerated, onTOTPGenerated);
void onTOTPGenerated(RDNATotpGeneratedStatus response) {
print("User: ${response.userID}");
print("TOTP: ${response.TOTP}");
print("Expires in: ${response.expiryTimeInSec} seconds");
}Response Data
Returns RDNATotpGeneratedStatus object with fields: userName, TOTP, expiryTimeInSec, error
Sample Response
ā
Provided in sample above.
š Cordova
Pseudocode
document.addEventListener('onTOTPGenerated', this.onTOTPGenerated.bind(this), false);Response Data
Contains: userName, TOTP, expiryTimeInSec, error
Sample Response
Not Applicable for Cordova
š Native iOS
Pseudocode
(void)onTOTPGenerated:(NSString *)userName
TOTP:(NSString *)TOTP
expiryTimeInSec:(int)expiryTimeInSec
error:(RDNAError *)error;Response Data Parameters
userName: User for whom TOTP is generatedTOTP: Generated OTPexpiryTimeInSec: Time in seconds before expiryerror:RDNAErrorobject
Sample Response
Not Applicable for Native iOS
š¤ Native Android
Pseudocode
void onTOTPGenerated(String username, String TOTP, int expiryTimeInSec, RDNAError error)Response Data Parameters
username: Ditto ID User IDTOTP: Generated OTPexpiryTimeInSec: Time in seconds before TOTP expireserror: RDNAError object with status
Sample Response
Not Applicable for Native Android
Updated 10 months ago
