summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/android.json3
-rw-r--r--plugins/cordova-plugin-touchid/README.md58
-rw-r--r--plugins/cordova-plugin-touchid/package.json39
-rw-r--r--plugins/cordova-plugin-touchid/plugin.xml25
-rw-r--r--plugins/cordova-plugin-touchid/src/ios/TouchID.h13
-rw-r--r--plugins/cordova-plugin-touchid/src/ios/TouchID.m79
-rw-r--r--plugins/cordova-plugin-touchid/www/touchid.js19
-rw-r--r--plugins/fetch.json9
-rw-r--r--plugins/ios.json19
-rw-r--r--www/js/PortalLoginCtrl.js32
10 files changed, 291 insertions, 5 deletions
diff --git a/plugins/android.json b/plugins/android.json
index c51ce331..0b1dc6b5 100644
--- a/plugins/android.json
+++ b/plugins/android.json
@@ -124,6 +124,9 @@
},
"uk.co.whiteoctober.cordova.appversion": {
"PACKAGE_NAME": "com.pliablepixels.zmninja"
+ },
+ "cordova-plugin-touchid": {
+ "PACKAGE_NAME": "com.pliablepixels.zmninja"
}
},
"dependent_plugins": {}
diff --git a/plugins/cordova-plugin-touchid/README.md b/plugins/cordova-plugin-touchid/README.md
new file mode 100644
index 00000000..2001972a
--- /dev/null
+++ b/plugins/cordova-plugin-touchid/README.md
@@ -0,0 +1,58 @@
+## Touch ID Plugin for Apache Cordova
+
+Cordova Plugin to leverage the iOS local authentication framework to allow in-app user authentication using Touch ID.
+
+**Important:** You must target a real device when building. If you target the simulator, the build will fail.
+
+## 1 step install
+
+#### Latest published version on npm (with Cordova CLI >= 5.0.0)
+
+```
+cordova plugin add cordova-plugin-touchid
+```
+
+#### Latest version from GitHub
+
+```
+cordova plugin add https://github.com/leecrossley/cordova-plugin-touchid.git
+```
+
+## Usage
+
+You **do not** need to reference any JavaScript, the Cordova plugin architecture will add a touchid object to your root automatically when you build.
+
+Ensure you use the plugin after your deviceready event has been fired.
+
+### Authenticate
+
+Pass the following arguments to the `authenticate()` function, to prompt the user to authenticate via TouchID:
+
+1. Success callback (called on successful authentication)
+2. Failure callback (called on error or if authentication fails)
+3. Localised text explaining why the app needs authentication*
+
+```
+touchid.authenticate(successCallback, failureCallback, text);
+```
+
+*NOTE: The localised text you present to the user should provide a clear reason for why you are requesting they authenticate themselves, and what action you will be taking based on that authentication.
+
+### Check support
+
+Although the `authenticate()` function will return an error if the user is unable to authenticate via Touch ID, you may wish to check support without prompting the user to authenticate. This can be done by passing following arguments to the `checkSupport()` function:
+
+1. Success callback (called if authentication is possible)
+2. Not supported callback (called if policy can not be evaluated, with error message)
+
+```
+touchid.checkSupport(successCallback, notSupportedCallback);
+```
+
+## Platforms
+
+iOS 8+
+
+## License
+
+[MIT License](http://ilee.mit-license.org)
diff --git a/plugins/cordova-plugin-touchid/package.json b/plugins/cordova-plugin-touchid/package.json
new file mode 100644
index 00000000..3b6a77c5
--- /dev/null
+++ b/plugins/cordova-plugin-touchid/package.json
@@ -0,0 +1,39 @@
+{
+ "name": "cordova-plugin-touchid",
+ "version": "0.3.0",
+ "author": "Lee Crossley <leee@hotmail.co.uk> (http://ilee.co.uk/)",
+ "description": "Cordova Plugin to leverage the iOS local authentication framework to allow in-app user authentication using Touch ID.",
+ "cordova": {
+ "id": "cordova-plugin-touchid",
+ "platforms": [
+ "ios"
+ ]
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/leecrossley/cordova-plugin-touchid.git"
+ },
+ "keywords": [
+ "cordova",
+ "touch id",
+ "touchid",
+ "authentication",
+ "fingerprint",
+ "id",
+ "login",
+ "passcode",
+ "ecosystem:cordova",
+ "cordova-ios"
+ ],
+ "engines": [
+ {
+ "name": "cordova",
+ "version": ">=3.0.0"
+ }
+ ],
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/leecrossley/cordova-plugin-touchid/issues"
+ },
+ "homepage": "https://github.com/leecrossley/cordova-plugin-touchid#readme"
+}
diff --git a/plugins/cordova-plugin-touchid/plugin.xml b/plugins/cordova-plugin-touchid/plugin.xml
new file mode 100644
index 00000000..1331453d
--- /dev/null
+++ b/plugins/cordova-plugin-touchid/plugin.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-touchid" version="0.3.0">
+ <name>Touch ID</name>
+ <author>Lee Crossley (http://ilee.co.uk/)</author>
+ <description>Cordova Plugin to leverage the iOS local authentication framework to allow in-app user authentication using Touch ID.</description>
+ <keywords>cordova, touch id, touchid, authentication, fingerprint, id, login, passcode</keywords>
+ <license>MIT</license>
+ <engines>
+ <engine name="cordova" version=">=3.0.0" />
+ </engines>
+ <js-module src="www/touchid.js" name="TouchID">
+ <clobbers target="touchid" />
+ </js-module>
+ <platform name="ios">
+ <config-file target="config.xml" parent="/*">
+ <feature name="TouchID">
+ <param name="ios-package" value="TouchID" />
+ </feature>
+ </config-file>
+ <header-file src="src/ios/TouchID.h" />
+ <source-file src="src/ios/TouchID.m" />
+ <framework src="LocalAuthentication.framework" />
+ <framework src="Security.framework" />
+ </platform>
+</plugin>
diff --git a/plugins/cordova-plugin-touchid/src/ios/TouchID.h b/plugins/cordova-plugin-touchid/src/ios/TouchID.h
new file mode 100644
index 00000000..d971a080
--- /dev/null
+++ b/plugins/cordova-plugin-touchid/src/ios/TouchID.h
@@ -0,0 +1,13 @@
+//
+// TouchID.h
+// Copyright (c) 2014 Lee Crossley - http://ilee.co.uk
+//
+
+#import <Cordova/CDVPlugin.h>
+
+@interface TouchID : CDVPlugin
+
+- (void) authenticate:(CDVInvokedUrlCommand*)command;
+- (void) checkSupport:(CDVInvokedUrlCommand*)command;
+
+@end
diff --git a/plugins/cordova-plugin-touchid/src/ios/TouchID.m b/plugins/cordova-plugin-touchid/src/ios/TouchID.m
new file mode 100644
index 00000000..0d39f7e2
--- /dev/null
+++ b/plugins/cordova-plugin-touchid/src/ios/TouchID.m
@@ -0,0 +1,79 @@
+//
+// TouchID.m
+// Copyright (c) 2014 Lee Crossley - http://ilee.co.uk
+//
+
+#import "TouchID.h"
+
+#import <LocalAuthentication/LocalAuthentication.h>
+
+@implementation TouchID
+
+- (void) authenticate:(CDVInvokedUrlCommand*)command;
+{
+ NSString *text = [command.arguments objectAtIndex:0];
+
+ __block CDVPluginResult* pluginResult = nil;
+
+ if (NSClassFromString(@"LAContext") != nil)
+ {
+ LAContext *laContext = [[LAContext alloc] init];
+ NSError *authError = nil;
+
+ if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
+ {
+ [laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:text reply:^(BOOL success, NSError *error)
+ {
+ if (success)
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
+ }
+
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }];
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[authError localizedDescription]];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+ }
+}
+
+- (void) checkSupport:(CDVInvokedUrlCommand*)command;
+{
+
+ __block CDVPluginResult* pluginResult = nil;
+
+ if (NSClassFromString(@"LAContext") != nil)
+ {
+ LAContext *laContext = [[LAContext alloc] init];
+ NSError *authError = nil;
+
+ if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError])
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[authError localizedDescription]];
+ }
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
+ }
+
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+@end
diff --git a/plugins/cordova-plugin-touchid/www/touchid.js b/plugins/cordova-plugin-touchid/www/touchid.js
new file mode 100644
index 00000000..020d5f89
--- /dev/null
+++ b/plugins/cordova-plugin-touchid/www/touchid.js
@@ -0,0 +1,19 @@
+
+var exec = require("cordova/exec");
+
+var TouchID = function () {
+ this.name = "TouchID";
+};
+
+TouchID.prototype.authenticate = function (successCallback, errorCallback, text) {
+ if (!text) {
+ text = "Please authenticate via TouchID to proceed";
+ }
+ exec(successCallback, errorCallback, "TouchID", "authenticate", [text]);
+};
+
+TouchID.prototype.checkSupport = function (successCallback, errorCallback) {
+ exec(successCallback, errorCallback, "TouchID", "checkSupport");
+};
+
+module.exports = new TouchID();
diff --git a/plugins/fetch.json b/plugins/fetch.json
index 748a4c08..3bf1f5f1 100644
--- a/plugins/fetch.json
+++ b/plugins/fetch.json
@@ -129,5 +129,14 @@
},
"is_top_level": true,
"variables": {}
+ },
+ "cordova-plugin-touchid": {
+ "source": {
+ "type": "git",
+ "url": "https://github.com/leecrossley/cordova-plugin-touchid.git",
+ "subdir": "."
+ },
+ "is_top_level": true,
+ "variables": {}
}
} \ No newline at end of file
diff --git a/plugins/ios.json b/plugins/ios.json
index 56f3a34e..62fd20e8 100644
--- a/plugins/ios.json
+++ b/plugins/ios.json
@@ -63,6 +63,10 @@
{
"xml": "<feature name=\"AppVersion\"><param name=\"ios-package\" value=\"AppVersion\" /></feature>",
"count": 1
+ },
+ {
+ "xml": "<feature name=\"TouchID\"><param name=\"ios-package\" value=\"TouchID\" /></feature>",
+ "count": 1
}
]
}
@@ -92,6 +96,18 @@
"xml": true,
"count": 1
}
+ ],
+ "LocalAuthentication.framework": [
+ {
+ "xml": false,
+ "count": 1
+ }
+ ],
+ "Security.framework": [
+ {
+ "xml": false,
+ "count": 1
+ }
]
}
}
@@ -142,6 +158,9 @@
},
"uk.co.whiteoctober.cordova.appversion": {
"PACKAGE_NAME": "com.pliablepixels.zmninja"
+ },
+ "cordova-plugin-touchid": {
+ "PACKAGE_NAME": "com.pliablepixels.zmninja"
}
},
"dependent_plugins": {}
diff --git a/www/js/PortalLoginCtrl.js b/www/js/PortalLoginCtrl.js
index 2a557623..cb498844 100644
--- a/www/js/PortalLoginCtrl.js
+++ b/www/js/PortalLoginCtrl.js
@@ -3,7 +3,7 @@
/*This is for the loop closure I am using in line 143 */
/* jslint browser: true*/
/* global vis,cordova,StatusBar,angular,console,moment */
-angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionicPlatform', '$scope', 'zm', 'ZMDataModel', '$ionicSideMenuDelegate', '$rootScope', '$http', '$q', '$state', '$ionicLoading', '$ionicPopover', '$ionicScrollDelegate', '$ionicModal', '$timeout', 'zmAutoLogin', '$ionicHistory', function ($ionicPlatform, $scope, zm, ZMDataModel, $ionicSideMenuDelegate, $rootScope, $http, $q, $state, $ionicLoading, $ionicPopover, $ionicScrollDelegate, $ionicModal, $timeout, zmAutoLogin, $ionicHistory) {
+angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionicPlatform', '$scope', 'zm', 'ZMDataModel', '$ionicSideMenuDelegate', '$rootScope', '$http', '$q', '$state', '$ionicLoading', '$ionicPopover', '$ionicScrollDelegate', '$ionicModal', '$timeout', 'zmAutoLogin', '$ionicHistory', '$cordovaTouchID', function ($ionicPlatform, $scope, zm, ZMDataModel, $ionicSideMenuDelegate, $rootScope, $http, $q, $state, $ionicLoading, $ionicPopover, $ionicScrollDelegate, $ionicModal, $timeout, zmAutoLogin, $ionicHistory, $cordovaTouchID) {
//-------------------------------------------------------------------------------
@@ -20,7 +20,12 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic
// unlock app if PIN is correct
//-------------------------------------------------------------------------------
$scope.unlock = function () {
- ZMDataModel.zmDebug("Trying to unlock PIN");
+ unlock();
+ };
+
+ function unlock()
+ {
+ ZMDataModel.zmDebug("Trying to unlock PIN");
if ($scope.pindata.pin == loginData.pinCode) {
ZMDataModel.zmDebug("PIN code entered is correct");
$rootScope.rand = Math.floor((Math.random() * 100000) + 1);
@@ -53,8 +58,7 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic
element.removeClass("animated shake");
});
}
- };
-
+ }
//-------------------------------------------------------------------------------
// Controller Main
@@ -76,8 +80,26 @@ angular.module('zmApp.controllers').controller('zmApp.PortalLoginCtrl', ['$ionic
if (ZMDataModel.isLoggedIn()) {
ZMDataModel.zmLog("User credentials are provided");
+
+ // You can login either via touch ID or typing in your code
+ $cordovaTouchID.checkSupport()
+ .then(function () {
+ // success, TouchID supported
+ $cordovaTouchID.authenticate("")
+ .then(function() {
+ ZMDataModel.zmLog("Touch Success");
+ $scope.pindata.pin = loginData.pinCode;
+ unlock();
- if (loginData.usePin) {
+ },
+ function () {
+ ZMDataModel.zmLog("Touch Failed");
+ });
+ }, function (error) {
+ ZMDataModel.zmLog("TouchID not supported");
+ });
+
+ if (loginData.usePin ) {
$scope.pinPrompt = true;