Skip to content

Commit 7398db8

Browse files
authored
Local authentication plugin (flutter#151)
* Initial commit of local_auth * Make it work with example app. * Analyzer and formatter fixes * Fix review comments
1 parent 4e5aa43 commit 7398db8

File tree

82 files changed

+2404
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2404
-0
lines changed

packages/local_auth/.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.atom/
3+
.idea
4+
.packages
5+
.pub/
6+
build/
7+
ios/.generated/
8+
packages
9+
pubspec.lock

packages/local_auth/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.0.1] - 6/21/2017
2+
3+
* Initial release of local authentication plugin.

packages/local_auth/LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/local_auth/README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# local_auth
2+
3+
This Flutter plugin provides means to perform local, on-device authentication of
4+
the user.
5+
6+
This means referring to biometric authentication on iOS (Touch ID or lock code)
7+
and the fingerprint APIs on Android (introduced in Android 6.0).
8+
9+
## Usage in Dart
10+
11+
Import the relevant file:
12+
13+
```dart
14+
import 'package:local_auth/local_auth.dart';
15+
```
16+
17+
We have default dialogs with an 'OK' button to show authentication error
18+
messages for the following 2 cases:
19+
20+
1. Passcode/PIN/Pattern Not Set. The user has not yet configured a passcode on
21+
iOS or PIN/pattern on Android.
22+
2. Touch ID/Fingerprint Not Enrolled. The user has not enrolled any
23+
fingerprints on the device.
24+
25+
Which means, if there's no fingerprint on the user's device, a dialog with
26+
instructions will pop up to let the user set up fingerprint. If the user clicks
27+
'OK' button, it will return 'false'.
28+
29+
Use the exported APIs to trigger local authentication with default dialogs:
30+
31+
```dart
32+
LocalAuthentication localAuth = new LocalAuthentication();
33+
bool didAuthenticate =
34+
await localAuth.authenticateWithBiometrics(
35+
localizedReason: 'Please authenticate to show account balance');
36+
```
37+
38+
If you don't want to use the default dialogs, call this API with
39+
'useErrorDialogs = false'. In this case, it will throw the error message back
40+
and you need to handle them in your dart code:
41+
42+
```dart
43+
bool didAuthenticate =
44+
await localAuth.authenticateWithBiometrics(
45+
localizedReason: 'Please authenticate to show account balance',
46+
useErrorDialogs: false);
47+
```
48+
49+
You can use our default dialog messages, or you can use your own messages by
50+
passing in IOSAuthMessages and AndroidAuthMessages:
51+
52+
```dart
53+
import 'package:local_auth/auth_strings.dart';
54+
55+
const iosStrings = const IOSAuthMessages(
56+
cancelButton: 'cancel',
57+
goToSettingsButton: 'settings',
58+
goToSettingsDescription: 'Please set up your Touch ID.',
59+
lockOut: 'Please reenable your Touch ID');
60+
await localAuth.authenticateWithBiometrics(
61+
localizedReason: 'Please authenticate to show account balance',
62+
useErrorDialogs: false,
63+
iOSAuthStrings: iosStrings);
64+
65+
```
66+
67+
### Exceptions
68+
69+
There are 4 types of exceptions: PasscodeNotSet, NotEnrolled, NotAvailable and
70+
OtherOperatingSystem. They are wrapped in LocalAuthenticationError class. You can
71+
catch the exception and handle them by different types. For example:
72+
73+
```dart
74+
import 'package:flutter/services.dart';
75+
import 'package:local_auth/error_codes.dart' as auth_error;
76+
77+
try {
78+
bool didAuthenticate = await local_auth.authenticateWithBiometrics(
79+
localizedReason: 'Please authenticate to show account balance');
80+
} on PlatformException catch (e) {
81+
if (e.code == auth_error.notAvailable) {
82+
// Handle this exception here.
83+
}
84+
}
85+
```
86+
87+
## Android integration
88+
89+
Update your project's `AndroidManifest.xml` file to include the
90+
`USE_FINGERPRINT` permissions:
91+
92+
```
93+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
94+
package="com.example.app">
95+
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
96+
<manifest>
97+
```
98+
99+
## Getting Started
100+
101+
For help getting started with Flutter, view our online
102+
[documentation](http://flutter.io/).
103+
104+
For help on editing plugin code, view the [documentation](https://flutter.io/platform-plugins/#edit-code).
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
10+
/gradle
11+
/gradlew
12+
/gradlew.bat
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
group 'io.flutter.plugins.localauth'
2+
version '1.0-SNAPSHOT'
3+
4+
buildscript {
5+
repositories {
6+
jcenter()
7+
}
8+
9+
dependencies {
10+
classpath 'com.android.tools.build:gradle:2.3.0'
11+
}
12+
}
13+
14+
allprojects {
15+
repositories {
16+
jcenter()
17+
maven {
18+
url "https://maven.google.com"
19+
}
20+
}
21+
}
22+
23+
apply plugin: 'com.android.library'
24+
25+
android {
26+
compileSdkVersion 25
27+
buildToolsVersion '25.0.3'
28+
29+
defaultConfig {
30+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
31+
}
32+
lintOptions {
33+
disable 'InvalidPackage'
34+
}
35+
}
36+
37+
dependencies {
38+
compile "com.android.support:support-v4:25.0.0"
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx1536M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'local_auth'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="io.flutter.plugins.localauth"
3+
android:versionCode="1"
4+
android:versionName="0.0.1">
5+
6+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25" />
7+
</manifest>

0 commit comments

Comments
 (0)