forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Local authentication plugin (flutter#151)
* Initial commit of local_auth * Make it work with example app. * Analyzer and formatter fixes * Fix review comments
- Loading branch information
Showing
82 changed files
with
2,404 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.DS_Store | ||
.atom/ | ||
.idea | ||
.packages | ||
.pub/ | ||
build/ | ||
ios/.generated/ | ||
packages | ||
pubspec.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## [0.0.1] - 6/21/2017 | ||
|
||
* Initial release of local authentication plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are | ||
// met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// * Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following disclaimer | ||
// in the documentation and/or other materials provided with the | ||
// distribution. | ||
// * Neither the name of Google Inc. nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# local_auth | ||
|
||
This Flutter plugin provides means to perform local, on-device authentication of | ||
the user. | ||
|
||
This means referring to biometric authentication on iOS (Touch ID or lock code) | ||
and the fingerprint APIs on Android (introduced in Android 6.0). | ||
|
||
## Usage in Dart | ||
|
||
Import the relevant file: | ||
|
||
```dart | ||
import 'package:local_auth/local_auth.dart'; | ||
``` | ||
|
||
We have default dialogs with an 'OK' button to show authentication error | ||
messages for the following 2 cases: | ||
|
||
1. Passcode/PIN/Pattern Not Set. The user has not yet configured a passcode on | ||
iOS or PIN/pattern on Android. | ||
2. Touch ID/Fingerprint Not Enrolled. The user has not enrolled any | ||
fingerprints on the device. | ||
|
||
Which means, if there's no fingerprint on the user's device, a dialog with | ||
instructions will pop up to let the user set up fingerprint. If the user clicks | ||
'OK' button, it will return 'false'. | ||
|
||
Use the exported APIs to trigger local authentication with default dialogs: | ||
|
||
```dart | ||
LocalAuthentication localAuth = new LocalAuthentication(); | ||
bool didAuthenticate = | ||
await localAuth.authenticateWithBiometrics( | ||
localizedReason: 'Please authenticate to show account balance'); | ||
``` | ||
|
||
If you don't want to use the default dialogs, call this API with | ||
'useErrorDialogs = false'. In this case, it will throw the error message back | ||
and you need to handle them in your dart code: | ||
|
||
```dart | ||
bool didAuthenticate = | ||
await localAuth.authenticateWithBiometrics( | ||
localizedReason: 'Please authenticate to show account balance', | ||
useErrorDialogs: false); | ||
``` | ||
|
||
You can use our default dialog messages, or you can use your own messages by | ||
passing in IOSAuthMessages and AndroidAuthMessages: | ||
|
||
```dart | ||
import 'package:local_auth/auth_strings.dart'; | ||
const iosStrings = const IOSAuthMessages( | ||
cancelButton: 'cancel', | ||
goToSettingsButton: 'settings', | ||
goToSettingsDescription: 'Please set up your Touch ID.', | ||
lockOut: 'Please reenable your Touch ID'); | ||
await localAuth.authenticateWithBiometrics( | ||
localizedReason: 'Please authenticate to show account balance', | ||
useErrorDialogs: false, | ||
iOSAuthStrings: iosStrings); | ||
``` | ||
|
||
### Exceptions | ||
|
||
There are 4 types of exceptions: PasscodeNotSet, NotEnrolled, NotAvailable and | ||
OtherOperatingSystem. They are wrapped in LocalAuthenticationError class. You can | ||
catch the exception and handle them by different types. For example: | ||
|
||
```dart | ||
import 'package:flutter/services.dart'; | ||
import 'package:local_auth/error_codes.dart' as auth_error; | ||
try { | ||
bool didAuthenticate = await local_auth.authenticateWithBiometrics( | ||
localizedReason: 'Please authenticate to show account balance'); | ||
} on PlatformException catch (e) { | ||
if (e.code == auth_error.notAvailable) { | ||
// Handle this exception here. | ||
} | ||
} | ||
``` | ||
|
||
## Android integration | ||
|
||
Update your project's `AndroidManifest.xml` file to include the | ||
`USE_FINGERPRINT` permissions: | ||
|
||
``` | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.app"> | ||
<uses-permission android:name="android.permission.USE_FINGERPRINT"/> | ||
<manifest> | ||
``` | ||
|
||
## Getting Started | ||
|
||
For help getting started with Flutter, view our online | ||
[documentation](http://flutter.io/). | ||
|
||
For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
|
||
/gradle | ||
/gradlew | ||
/gradlew.bat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
group 'io.flutter.plugins.localauth' | ||
version '1.0-SNAPSHOT' | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.3.0' | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
maven { | ||
url "https://maven.google.com" | ||
} | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion '25.0.3' | ||
|
||
defaultConfig { | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
lintOptions { | ||
disable 'InvalidPackage' | ||
} | ||
} | ||
|
||
dependencies { | ||
compile "com.android.support:support-v4:25.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.jvmargs=-Xmx1536M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'local_auth' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.flutter.plugins.localauth" | ||
android:versionCode="1" | ||
android:versionName="0.0.1"> | ||
|
||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" /> | ||
</manifest> |
Oops, something went wrong.