Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
naoufal authored Dec 3, 2017
2 parents 020f6c3 + 217a6a8 commit 9dcab28
Show file tree
Hide file tree
Showing 53 changed files with 16,244 additions and 942 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![npm downloads](https://img.shields.io/npm/dm/react-native-touch-id.svg?style=flat-square)](https://www.npmjs.com/package/react-native-touch-id)
[![Code Climate](https://img.shields.io/codeclimate/github/naoufal/react-native-touch-id.svg?style=flat-square)](https://codeclimate.com/github/naoufal/react-native-touch-id)

React Native Touch ID is a [React Native](http://facebook.github.io/react-native/) library for authenticating users with Touch ID on both iOS and Android (experimental).
React Native Touch ID is a [React Native](http://facebook.github.io/react-native/) library for authenticating users with biometric authentication methods like Face ID and Touch ID on both iOS and Android (experimental).

![react-native-touch-id](https://cloud.githubusercontent.com/assets/1627824/7975919/2c69a776-0a42-11e5-9773-3ea1c7dd79f3.gif)

Expand All @@ -32,7 +32,7 @@ Due to the rapid changes being made in the React Native ecosystem, we are not of

## Usage
### Linking the Library
In order to use Touch ID, you must first link the library to your project. There's excellent documentation on how to do this in the [React Native Docs](http://facebook.github.io/react-native/docs/linking-libraries-ios.html#content).
In order to use Biometric Authentication, you must first link the library to your project. There's excellent documentation on how to do this in the [React Native Docs](http://facebook.github.io/react-native/docs/linking-libraries-ios.html#content).

Or use the built-in command:
```shell
Expand All @@ -47,7 +47,7 @@ On Android you can customize the title and color of the pop-up by passing in the

Error handling is also different between the platforms, with iOS currently providing much more descriptive error codes.

### Requesting Touch ID Authentication
### Requesting Face ID/Touch ID Authentication
Once you've linked the library, you'll want to make it available to your app by requiring it:

```js
Expand All @@ -58,7 +58,7 @@ or
import TouchID from 'react-native-touch-id'
```

Requesting Touch ID authentication is as simple as calling:
Requesting Face ID/Touch ID Authentication is as simple as calling:
```js
TouchID.authenticate('to demo this react-native component', optionalConfigObject)
.then(success => {
Expand All @@ -69,8 +69,9 @@ TouchID.authenticate('to demo this react-native component', optionalConfigObject
});
```


## Example
Using Touch ID in your app will usually look like this:
Using Face ID/Touch ID in your app will usually look like this:
```js
import React from "react"
var TouchID = require('react-native-touch-id');
Expand Down Expand Up @@ -104,7 +105,7 @@ class YourComponent extends React.Component {

## Methods
### authenticate(reason, config)
Attempts to authenticate with Touch ID.
Attempts to authenticate with Face ID/Touch ID.
Returns a `Promise` object.

__Arguments__
Expand All @@ -130,15 +131,19 @@ TouchID.authenticate('to demo this react-native component', optionalConfigObject
```

### isSupported()
Verifies that Touch ID is supported.
Returns a `Promise` object.
Verify's that Touch ID is supported.
Returns a `Promise` that resolves to a `String` of `FaceID` or `TouchID` .

__Examples__
```js
TouchID.isSupported()
.then(supported => {
.then(biometryType => {
// Success code
console.log('TouchID is supported.');
if (biometryType === 'FaceID') {
console.log('FaceID is supported.');
} else {
console.log('TouchID is supported.');
}
})
.catch(error => {
// Failure code
Expand All @@ -147,7 +152,7 @@ TouchID.isSupported()
```

## Errors
There are various reasons why authenticating with Touch ID may fail. Whenever calling Touch ID authentication fails, `TouchID.authenticate` will return an error code representing the reason.
There are various reasons why biomentric authentication may fail. When it does fails, `TouchID.authenticate` will return an error code representing the reason.

Below is a list of error codes that can be returned **on iOS**:

Expand Down
3 changes: 2 additions & 1 deletion TouchID.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <React/RCTBridgeModule.h>
#import <LocalAuthentication/LocalAuthentication.h>

@interface TouchID : NSObject <RCTBridgeModule>

- (NSString *_Nonnull)getBiometryType:(LAContext *_Nonnull)context;
@end
4 changes: 2 additions & 2 deletions TouchID.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const ERRORS = require('./data/errors');
export default {
isSupported() {
return new Promise((resolve, reject) => {
NativeTouchID.isSupported(error => {
NativeTouchID.isSupported((error, biometryType) => {
if (error) {
return reject(createError(error.message));
}

resolve(true);
resolve(biometryType);
});
});
},
Expand Down
41 changes: 25 additions & 16 deletions TouchID.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import "TouchID.h"
#import <React/RCTUtils.h>
#import <LocalAuthentication/LocalAuthentication.h>

@implementation TouchID

Expand All @@ -10,9 +9,9 @@ @implementation TouchID
{
LAContext *context = [[LAContext alloc] init];
NSError *error;

if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
callback(@[[NSNull null], @true]);
callback(@[[NSNull null], [self getBiometryType:context]]);
// Device does not support TouchID
} else {
callback(@[RCTMakeError(@"RCTTouchIDNotSupported", nil, nil)]);
Expand All @@ -21,11 +20,11 @@ @implementation TouchID
}

RCT_EXPORT_METHOD(authenticate: (NSString *)reason
callback: (RCTResponseSenderBlock)callback)
callback: (RCTResponseSenderBlock)callback)
{
LAContext *context = [[LAContext alloc] init];
NSError *error;

// Device has TouchID
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
// Attempt Authentification
Expand All @@ -36,55 +35,65 @@ @implementation TouchID
// Failed Authentication
if (error) {
NSString *errorReason;

switch (error.code) {
case LAErrorAuthenticationFailed:
errorReason = @"LAErrorAuthenticationFailed";
break;

case LAErrorUserCancel:
errorReason = @"LAErrorUserCancel";
break;

case LAErrorUserFallback:
errorReason = @"LAErrorUserFallback";
break;

case LAErrorSystemCancel:
errorReason = @"LAErrorSystemCancel";
break;

case LAErrorPasscodeNotSet:
errorReason = @"LAErrorPasscodeNotSet";
break;

case LAErrorTouchIDNotAvailable:
errorReason = @"LAErrorTouchIDNotAvailable";
break;

case LAErrorTouchIDNotEnrolled:
errorReason = @"LAErrorTouchIDNotEnrolled";
break;

default:
errorReason = @"RCTTouchIDUnknownError";
break;
}

NSLog(@"Authentication failed: %@", errorReason);
callback(@[RCTMakeError(errorReason, nil, nil)]);
return;
}

// Authenticated Successfully
callback(@[[NSNull null], @"Authenticat with Touch ID."]);
}];

// Device does not support TouchID
} else {
callback(@[RCTMakeError(@"RCTTouchIDNotSupported", nil, nil)]);
return;
}
}

- (NSString *)getBiometryType:(LAContext *)context
{
if (@available(iOS 11, *)) {
return context.biometryType == LABiometryTypeFaceID ? @"FaceID" : @"TouchID";
}

return @"TouchID";
}

@end

3 changes: 3 additions & 0 deletions examples/BiometricAuthExample/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react-native"]
}
6 changes: 6 additions & 0 deletions examples/BiometricAuthExample/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
48 changes: 48 additions & 0 deletions examples/BiometricAuthExample/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*

; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js

; Ignore polyfills
.*/Libraries/polyfills/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/

[options]
emoji=true

module.system=haste

munge_underscores=true

module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState
suppress_type=$FixMe

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

unsafe.enable_getters_and_setters=true

[version]
^0.56.0
1 change: 1 addition & 0 deletions examples/BiometricAuthExample/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
53 changes: 53 additions & 0 deletions examples/BiometricAuthExample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
1 change: 1 addition & 0 deletions examples/BiometricAuthExample/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 9dcab28

Please sign in to comment.