Skip to main content

Entrust Soft Token

Entrust Identity is a mobile app that provides a secure, convenient way to authenticate to your applications. It is available for iOS and Android devices.

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 Entrust Soft Token authentication, users must register and activate their Entrust Identity app in your IDaaS tenant.

Authentication

Entrust Soft Token Code

To authenticate a user with Entrust Soft Token, see the following code example:

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 = "TOKEN";

UserChallengeParameters challengeParms = new UserChallengeParameters()
.applicationId(APPLICATION_ID)
.userId(userId);

AuthenticatedResponse challengeResponse = authApi.userChallengeUsingPOST(authType, challengeParms);

System.out.println("Soft Token ID: " + String.join(", ", challengeResponse.getTokenDetails()));
System.out.print("Enter the code from your entrust Identity app:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String response = br.readLine();

UserAuthenticateParameters authParms = new UserAuthenticateParameters()
.applicationId(APPLICATION_ID)
.response(response);

try {
AuthenticatedResponse authResponse = authApi.userAuthenticateUsingPOST(authType, authParms, challengeResponse.getToken());
if (Boolean.TRUE.equals(authResponse.getAuthenticationCompleted())) {
System.out.println("Authentication successful!");
}
} catch (Exception e) {
System.out.println("Authentication failed: " + e.getMessage());
}
}
}

Push Notification

To authenticate a user with Entrust Soft Token using a push notification, see the following code example:

package com.entrust.idaas.userAuthenticate;

import com.entrustdatacard.intellitrust.auth.ApiClient;
import com.entrustdatacard.intellitrust.auth.api.AuthenticationApi;
import com.entrustdatacard.intellitrust.auth.model.*;

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 = "TOKENPUSH";

UserChallengeParameters challengeParms = new UserChallengeParameters()
.applicationId(APPLICATION_ID)
.userId(userId);

AuthenticatedResponse challengeResponse = authApi.userChallengeUsingPOST(authType, challengeParms);

UserAuthenticateParameters authParms = new UserAuthenticateParameters()
.applicationId(APPLICATION_ID);

int maxWait = 60;
int checkInterval = 5;

for (int i = 0; i < maxWait/checkInterval; i += 1) {
AuthenticatedResponse authResponse = authApi.userAuthenticateUsingPOST(authType, authParms, challengeResponse.getToken());
if (authResponse.getStatus() == AuthenticatedResponse.StatusEnum.CONFIRM) {
System.out.println("Authentication successful");
break;
} else if (authResponse.getStatus() == AuthenticatedResponse.StatusEnum.CONCERN || authResponse.getStatus() == AuthenticatedResponse.StatusEnum.CANCEL) {
System.out.println("Authentication failed with status: " + authResponse.getStatus());
break;
} else {
System.out.println("Waiting for user to confirm push notification " + (i+1) + "/" + maxWait/checkInterval);
Thread.sleep(checkInterval * 1000);
}
}
}
}

Push Notification with Mutual Challenge

To authenticate a user with Entrust Soft Token using a push notification with mutual challenge, you need to first enable mutual challenge in your IDaaS tenant. See the help documentation for more information. After the mutual challenge is configured, see the following code example to authenticate a user with Entrust Soft Token using a push notification with mutual challenge:

package com.entrust.idaas.userAuthenticate;

import com.entrustdatacard.intellitrust.auth.ApiClient;
import com.entrustdatacard.intellitrust.auth.api.AuthenticationApi;
import com.entrustdatacard.intellitrust.auth.model.*;

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 = "TOKENPUSH";

UserChallengeParameters challengeParms = new UserChallengeParameters()
.applicationId(APPLICATION_ID)
.userId(userId)
.tokenPushMutualChallengeEnabled(true);

AuthenticatedResponse challengeResponse = authApi.userChallengeUsingPOST(authType, challengeParms);

System.out.println("Select or enter the following challenge on your device:");
System.out.println("============Mutual Challenge============");
System.out.println(challengeResponse.getTokenPushMutualChallenge());
System.out.println("========================================");

UserAuthenticateParameters authParms = new UserAuthenticateParameters()
.applicationId(APPLICATION_ID);

int maxWait = 60;
int checkInterval = 5;

for (int i = 0; i < maxWait/checkInterval; i += 1) {
AuthenticatedResponse authResponse = authApi.userAuthenticateUsingPOST(authType, authParms, challengeResponse.getToken());
if (authResponse.getStatus() == AuthenticatedResponse.StatusEnum.CONFIRM) {
System.out.println("Authentication successful");
break;
} else if (authResponse.getStatus() == AuthenticatedResponse.StatusEnum.CONCERN || authResponse.getStatus() == AuthenticatedResponse.StatusEnum.CANCEL) {
System.out.println("Authentication failed with status: " + authResponse.getStatus());
break;
} else {
System.out.println("Waiting for user to confirm push notification " + (i+1) + "/" + maxWait/checkInterval);
Thread.sleep(checkInterval * 1000);
}
}
}
}