One Time Password
One time password (OTP) is a password that is valid for only one login session or transaction, on a computer system or other digital device. It is also known as a one-time PIN or dynamic password. You can configure the OTP delivery method in the admin portal. It can be delivered through email, SMS or voice call.
caution
This sample is for demonstration purposes only. It is not intended for production use. In production, you should use a secure method to store the application id.
Prerequisites
To enable OTP authentication, users must have a valid email address or mobile number.
Authentication
To authenticate a user with OTP, see the following sample code.
- Java
- CSharp
- Python
package com.entrust.idaas.userAuthenticate;
import com.entrustdatacard.intellitrust.auth.ApiClient;
import com.entrustdatacard.intellitrust.auth.api.AuthenticationApi;
import com.entrustdatacard.intellitrust.auth.model.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class UserAuthenticate {
private static final String APPLICATION_ID = "YOUR_APPLICATION_ID";
private static final String HOST_NAME = "YOUR_HOST_NAME";
public static void main(String args[]) throws Exception {
ApiClient apiClient = new ApiClient();
apiClient.setBasePath(HOST_NAME);
AuthenticationApi authApi = new AuthenticationApi(apiClient);
String userId = "exampleUser"
String authType = "OTP";
UserChallengeParameters userChallengeParameters = new UserChallengeParameters()
.applicationId(APPLICATION_ID)
.userId(userId)
.otpDeliveryType(UserChallengeParameters.OtpDeliveryTypeEnum.EMAIL);
AuthenticatedResponse challengeResponse = authApi.userChallengeUsingPOST(authType, userChallengeParameters);
System.out.print("Enter response: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String response = br.readLine();
UserAuthenticateParameters userAuthenticateParameters = new UserAuthenticateParameters()
.applicationId(APPLICATION_ID)
.response(response);
try {
AuthenticatedResponse authenticatedResponse = authApi.userAuthenticateUsingPOST(authType, userAuthenticateParameters, challengeResponse.getToken()); if (Boolean.TRUE.equals(authenticatedResponse.getAuthenticationCompleted())) {
System.out.println("Authentication successful");
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("Authentication failed");
}
}
}
using com.entrustdatacard.intellitrust.auth.api;
using com.entrustdatacard.intellitrust.auth.Client;
using com.entrustdatacard.intellitrust.auth.model;
namespace Sample
{
internal class AuthApiSample
{
private static readonly string HOST_NAME = "YOUR_HOST_NAME";
private static readonly string APPLICATION_ID = "YOUR_APPLICATION_ID";
public static void Main()
{
Configuration configuration = new Configuration();
configuration.BasePath = HOST_NAME;
var authApi = new AuthenticationApi(configuration);
string userId = "exampleUser";
string authType = "OTP";
var userChallengeParameters = new UserChallengeParameters(applicationId: APPLICATION_ID, userId: userId, otpDeliveryType: UserChallengeParameters.OtpDeliveryTypeEnum.EMAIL);
var challengeResponse = authApi.UserChallengeUsingPOST(authType, userChallengeParameters);
Console.Write("Enter response: ");
var response = Console.ReadLine();
var userAuthenticateParameters =
new UserAuthenticateParameters(applicationId: APPLICATION_ID, response: response);
try
{
var authenticatedResponse = authApi.UserAuthenticateUsingPOST(authType, userAuthenticateParameters, challengeResponse.Token);
if (authenticatedResponse.AuthenticationCompleted == true)
{
Console.WriteLine("Authentication successful");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Authentication failed");
}
}
}
from IntelliTrust_Python_Authentication import ApiClient, Configuration
import IntelliTrust_Python_Authentication.api as apis
import IntelliTrust_Python_Authentication.models as models
import IntelliTrust_Python_Authentication.exceptions as exceptions
conf = Configuration(host="YOUR_HOST_NAME")
with ApiClient(configuration=conf) as api_client:
auth_api = apis.AuthenticationApi(api_client)
application_id = "YOUR_APPLICATION_ID"
user_id = "exampleUser"
challenge_parms = models.UserChallengeParameters(
application_id=application_id,
user_id=user_id,
otp_delivery_type='EMAIL'
)
challenge_response = auth_api.user_challenge_using_post("OTP", challenge_parms)
response = input("Enter response: ")
auth_parms = models.UserAuthenticateParameters(
application_id=application_id,
response=response
)
try:
auth_response = auth_api.user_authenticate_using_post("OTP", auth_parms, challenge_response.token)
if auth_response.authentication_completed:
print("Authentication succeeded")
print("Auth token: ", auth_response.token)
except exceptions.ForbiddenException as e:
print("Authentication failed: {}".format(e))