TouchId example


The index.html file containing JavaScript that makes use of the TouchId API functionality is listed below.

Note

The TouchID functionality is active once it has been activated in the device's system settings. Check your system settings and make sure that both Passcode and TouchID functions are active.

<!DOCTYPE html>
<html manifest="manifest.appcache">
  <head>
    <title>TouchId feature test</title>

    <script type="text/javascript">

      function printText(str) {
        var d = document.getElementById('text-box');
        d.appendChild(document.createTextNode(str));
        d.appendChild(document.createElement('br'));
        d.scrollTop = d.scrollHeight;
      }
      function clearText() {
        document.getElementById('text-box').innerHTML = "";
      }

      function testTouchId() {
        printText('Test TouchId');

        var callbacks = {
          onSuccess: function(info){
             printText("onSuccess :: evaluate TouchId: " + info);
          }
        }

        window.launchbox.TouchId.checkAvailability(callbacks);
      }

      function saveCredentials() {
        printText('Save credentials');

        var us = document.getElementById('username').value;
        var pswd = document.getElementById('password').value;

        var callbacks = {
          onSuccess: function(){
             printText("onSuccess :: Credentials saved successfully.");
          },
          onFailure: function(payload){
            printText("onFailure :: Failed to save credentials. Error code " + payload.code + ", error message: " + payload.description);
          }
        }

        var payload = {
          'identifier': document.getElementById("username").value,
          'password': document.getElementById("password").value
        };
        window.launchbox.TouchId.saveCredentials(payload, callbacks);
      }

      function getCredentials() {
        printText('Get credentials');

        var callbacks = {
          onSuccess : function(payload) {
              printText("onSuccess :: Successfully get credentials. username: " + payload.identifier + " password: " + payload.password);
          },
          onFailure: function(payload){
            printText("onFailure :: Failed to save credentials. Error code " + payload.code + ", error message: " + payload.description);
          }
        }

        window.launchbox.TouchId.getCredentials(callbacks);
      }

      function deleteCredentials() {
        printText('Delete credentials');
		
		var callbacks = {
          onSuccess : function() {
              printText("onSuccess :: Successfully delete credentials");
          },
          onFailure: function(payload){
            printText("onFailure :: Failed to save credentials. Error code " + payload.code + ", error message: " + payload.description);
          }
        }
		
        window.launchbox.TouchId.deleteCredentials(callbacks);
      } 

    </script>
  </head>
  <body>
    <header>
      <h3>AMP Hybrid Client <span>TouchId api sample usage</span>
      </h3>
    </header>
    <input type="button" onclick="testTouchId();" value="Check TouchId avability" />
    <input type="text" placeholder="username" name="username" id="username" /><br />
    <input type="text" placeholder="password" name="password" id="password" size="20" maxlength="30" />
    <input type="button" onclick="saveCredentials();" value="Save Credentials" />
    <input type="button" onclick="getCredentials()" value="Get Credentials" />
    <input type="button" onclick="deleteCredentials()" value="Delete Credentials" />
    <br />
    <input type="button" onclick="clearText()" value="Clear Output" />
    <hr/>

    <div id="text-box"></div>
  </body>
</html>

The contents of the cache manifest file called manifest.appcache for this application are listed below:

CACHE MANIFEST

CACHE:
index.html

NETWORK:
*

The webapp-descriptor.xml file for this application is defined in the following way:

<?xml version="1.0" encoding="UTF-8"?>
<webapp-descriptor xmlns="http://www.antennasoftware.com/application-hosting/web-app-descriptor/2.0">
    <version>1.0.0</version>
    <name>SamplePRPCTouchIDApi</name>
    <description>Sample PRPC TouchID example usage</description>
    <copyright>The copyright information</copyright>
    <cache-mode>cache-network</cache-mode>
    <id>com.pega.sample.TouchId</id>
</webapp-descriptor>

Related topics

Public API reference
TouchID
Legal notice | Copyright © 2015 and Confidential to Pegasystems Inc. All rights reserved. | Feedback
Advanced...