diff options
| author | Arjun Roychowdhury <pliablepixels@gmail.com> | 2015-09-17 16:28:48 -0400 |
|---|---|---|
| committer | Arjun Roychowdhury <pliablepixels@gmail.com> | 2015-09-17 16:28:48 -0400 |
| commit | df19b39f1d8a4440b9c83fd297ea7d7748ca7cc9 (patch) | |
| tree | 9fac88b6f4e1177e179478ef9e9164f8405785f5 /plugins | |
| parent | 016b7e1190568149793f62fc6c1f268d46c06c49 (diff) | |
TouchID support now added for PIN
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/android.json | 3 | ||||
| -rw-r--r-- | plugins/cordova-plugin-touchid/README.md | 58 | ||||
| -rw-r--r-- | plugins/cordova-plugin-touchid/package.json | 39 | ||||
| -rw-r--r-- | plugins/cordova-plugin-touchid/plugin.xml | 25 | ||||
| -rw-r--r-- | plugins/cordova-plugin-touchid/src/ios/TouchID.h | 13 | ||||
| -rw-r--r-- | plugins/cordova-plugin-touchid/src/ios/TouchID.m | 79 | ||||
| -rw-r--r-- | plugins/cordova-plugin-touchid/www/touchid.js | 19 | ||||
| -rw-r--r-- | plugins/fetch.json | 9 | ||||
| -rw-r--r-- | plugins/ios.json | 19 |
9 files changed, 264 insertions, 0 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": {} |
