search cancel

VIP CDK: Android Authentication Code Snippets

book

Article ID: 150720

calendar_today

Updated On:

Products

VIP Software Development Kit

Issue/Introduction

 

Resolution

Saving a Credential

The following code snippet illustrates how to save the newly created credential into the Symantec Vault for future Security Code retrieval.

// Get the credential object and adds the credential object to an ArrayList of credential interface.

// Saves the data on the mobile device

ArrayList<CredentialInterface> credentialArray = new ArrayList<credentialInterface>();

if (credObject != null) {

     Vault repository = new Vault(activityContext);

     try {

           credentialArray.add((CredentialAuthSigning) credObject);

           status = repository.storeCredential(credentialArray);

     } catch (MVIPException exception) {

           // Catch and handle exception

     }

}

This sample code performs the following functions:

  1. Gets the credentialAuthSigning object and adds it to an ArrayList of credentialInterface.
  2. Saves the data in the Symantec Vault on the device.

Note: If you are not using the Vault interface provided by Symantec, you must reconstruct the Credential object to the JSON format using the toJSON API and then store it in your vault.

 

 

Restoring a Credential

The following code snippet illustrates how to restore a credential from the Symantec Vault in preparation to retrieve a Security Code used for authentication:

// restore values from storage.

 

Vault vault = new Vault(activityContext);

String credentialID = null

ArrayList<CredentialInterface> mCredentials = null;

try {

     mCredential = vault.retrieveCredential(credentialId);

} catch (MVIPException exception) {

// Catch and handle exception

}

Note: The call to retrieveCredential with credentialId returns an ArrayList that contains the credential with given credentialId. In case the credentialId is passed as null to the retrieveCredential method, then an ArrayList of all credential stored in the vault will be returned.

 

 

Generating a Security Code

The following code snippet illustrates how to retrieve a Security Code used for authentication:

String code=null;

try {

     code = mCredentials.get(0).getSecurityCode(context);

}

catch (MVIPException exception) {

     // catch and handle exception

}

 

This sample code performs the following functions:

  1. Retrieves the serialized, encrypted credential object that was saved previously.
  2. Calls getSecurityCode on the first element in the ArrayList returned from the retrieveCredential method. This call obtains the next sequential security code from the credential.

Note: If you are not using the Vault interface provided by Symantec, you must reconstruct the Credential object from the JSON stored in the vault (non-Symantec) using the Credential’s constructor and then call the getSecurityCode method on the Credential object.