summaryrefslogtreecommitdiff
path: root/plugins/cordova-plugin-touchid
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/cordova-plugin-touchid')
-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
6 files changed, 233 insertions, 0 deletions
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();