Aerogear Guides Tutorials to help get you off and running.

AeroGear Cordova OTP

Before we start please install Apache Cordova CLI, which is the command line tool to build, deploy and manage Cordova-based applications.

Read about how OTP works on this AeroGear OTP guide


To create One Time Passwords in your cordova application first create a new project and install the plugin.

cordova create <app name>
cd <app name>
cordova platform add android
cordova platform add ios
cordova plugin add

There is one function that will do the entire following:

  1. If there is no secret stored it will fire up the barcode reader to scan the secret
  2. Once scanned the secret is stored
  3. Generate a OTP from the stored secret
var totp = new AeroGear.Totp();
totp.generate(function(result) { /* result is the otp */ );

If you don’t want to use the barcode scanner then there are also separate functions to perform all of the above

var totp = new AeroGear.Totp();
totp.scanSecret(function(secret) { /* secret the scanned secret */ })

/* retrieve and store the secret on the device */
totp.readSecret(function(secret) { /* secret the read secret */ })

// initialize OTP
var generator = new AeroGear.Totp(secret);
// generate token
generator.generateOTP(function(result) { /* result the generated otp */ });