|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | | -// This is a temporary ignore to allow us to land a new set of linter rules in a |
6 | | -// series of manageable patches instead of one gigantic PR. It disables some of |
7 | | -// the new lints that are already failing on this plugin, for this plugin. It |
8 | | -// should be deleted and the failing lints addressed as soon as possible. |
9 | | -// ignore_for_file: public_member_api_docs |
10 | | - |
11 | | -import 'dart:async'; |
12 | | - |
13 | | -import 'package:flutter/foundation.dart' show visibleForTesting; |
14 | | -import 'package:flutter/services.dart'; |
15 | | -import 'package:local_auth_platform_interface/local_auth_platform_interface.dart'; |
16 | | -import 'package:platform/platform.dart'; |
17 | | -import 'auth_strings.dart'; |
18 | | - |
19 | | -export 'package:local_auth_platform_interface/types/biometric_type.dart'; |
20 | | - |
21 | | -Platform _platform = const LocalPlatform(); |
22 | | - |
23 | | -@visibleForTesting |
24 | | -void setMockPathProviderPlatform(Platform platform) { |
25 | | - _platform = platform; |
26 | | -} |
27 | | - |
28 | | -/// A Flutter plugin for authenticating the user identity locally. |
29 | | -class LocalAuthentication { |
30 | | - /// The `authenticateWithBiometrics` method has been deprecated. |
31 | | - /// Use `authenticate` with `biometricOnly: true` instead. |
32 | | - @Deprecated('Use `authenticate` with `biometricOnly: true` instead') |
33 | | - Future<bool> authenticateWithBiometrics({ |
34 | | - required String localizedReason, |
35 | | - bool useErrorDialogs = true, |
36 | | - bool stickyAuth = false, |
37 | | - AndroidAuthMessages androidAuthStrings = const AndroidAuthMessages(), |
38 | | - IOSAuthMessages iOSAuthStrings = const IOSAuthMessages(), |
39 | | - bool sensitiveTransaction = true, |
40 | | - }) => |
41 | | - LocalAuthPlatform.instance.authenticate( |
42 | | - localizedReason: localizedReason, |
43 | | - authMessages: <AuthMessages>[iOSAuthStrings, androidAuthStrings], |
44 | | - options: AuthenticationOptions( |
45 | | - useErrorDialogs: useErrorDialogs, |
46 | | - stickyAuth: stickyAuth, |
47 | | - sensitiveTransaction: sensitiveTransaction, |
48 | | - biometricOnly: true, |
49 | | - ), |
50 | | - ); |
51 | | - |
52 | | - /// Authenticates the user with biometrics available on the device while also |
53 | | - /// allowing the user to use device authentication - pin, pattern, passcode. |
54 | | - /// |
55 | | - /// Returns true, if the user successfully authenticated, false otherwise. |
56 | | - /// |
57 | | - /// [localizedReason] is the message to show to user while prompting them |
58 | | - /// for authentication. This is typically along the lines of: 'Please scan |
59 | | - /// your finger to access MyApp.'. This must not be empty. |
60 | | - /// |
61 | | - /// [useErrorDialogs] = true means the system will attempt to handle user |
62 | | - /// fixable issues encountered while authenticating. For instance, if |
63 | | - /// fingerprint reader exists on the phone but there's no fingerprint |
64 | | - /// registered, the plugin will attempt to take the user to settings to add |
65 | | - /// one. Anything that is not user fixable, such as no biometric sensor on |
66 | | - /// device, will be returned as a [PlatformException]. |
67 | | - /// |
68 | | - /// [stickyAuth] is used when the application goes into background for any |
69 | | - /// reason while the authentication is in progress. Due to security reasons, |
70 | | - /// the authentication has to be stopped at that time. If stickyAuth is set |
71 | | - /// to true, authentication resumes when the app is resumed. If it is set to |
72 | | - /// false (default), then as soon as app is paused a failure message is sent |
73 | | - /// back to Dart and it is up to the client app to restart authentication or |
74 | | - /// do something else. |
75 | | - /// |
76 | | - /// Construct [AndroidAuthStrings] and [IOSAuthStrings] if you want to |
77 | | - /// customize messages in the dialogs. |
78 | | - /// |
79 | | - /// Setting [sensitiveTransaction] to true enables platform specific |
80 | | - /// precautions. For instance, on face unlock, Android opens a confirmation |
81 | | - /// dialog after the face is recognized to make sure the user meant to unlock |
82 | | - /// their phone. |
83 | | - /// |
84 | | - /// Setting [biometricOnly] to true prevents authenticates from using non-biometric |
85 | | - /// local authentication such as pin, passcode, and passcode. |
86 | | - /// |
87 | | - /// Throws an [PlatformException] if there were technical problems with local |
88 | | - /// authentication (e.g. lack of relevant hardware). This might throw |
89 | | - /// [PlatformException] with error code [otherOperatingSystem] on the iOS |
90 | | - /// simulator. |
91 | | - Future<bool> authenticate({ |
92 | | - required String localizedReason, |
93 | | - bool useErrorDialogs = true, |
94 | | - bool stickyAuth = false, |
95 | | - AndroidAuthMessages androidAuthStrings = const AndroidAuthMessages(), |
96 | | - IOSAuthMessages iOSAuthStrings = const IOSAuthMessages(), |
97 | | - bool sensitiveTransaction = true, |
98 | | - bool biometricOnly = false, |
99 | | - }) { |
100 | | - return LocalAuthPlatform.instance.authenticate( |
101 | | - localizedReason: localizedReason, |
102 | | - authMessages: <AuthMessages>[iOSAuthStrings, androidAuthStrings], |
103 | | - options: AuthenticationOptions( |
104 | | - useErrorDialogs: useErrorDialogs, |
105 | | - stickyAuth: stickyAuth, |
106 | | - sensitiveTransaction: sensitiveTransaction, |
107 | | - biometricOnly: biometricOnly, |
108 | | - ), |
109 | | - ); |
110 | | - } |
111 | | - |
112 | | - /// Returns true if auth was cancelled successfully. |
113 | | - /// This api only works for Android. |
114 | | - /// Returns false if there was some error or no auth in progress. |
115 | | - /// |
116 | | - /// Returns [Future] bool true or false: |
117 | | - Future<bool> stopAuthentication() async { |
118 | | - if (_platform.isAndroid) { |
119 | | - return LocalAuthPlatform.instance.stopAuthentication(); |
120 | | - } |
121 | | - return true; |
122 | | - } |
123 | | - |
124 | | - /// Returns true if device is capable of checking biometrics |
125 | | - /// |
126 | | - /// Returns a [Future] bool true or false: |
127 | | - Future<bool> get canCheckBiometrics => |
128 | | - LocalAuthPlatform.instance.deviceSupportsBiometrics(); |
129 | | - |
130 | | - /// Returns true if device is capable of checking biometrics or is able to |
131 | | - /// fail over to device credentials. |
132 | | - /// |
133 | | - /// Returns a [Future] bool true or false: |
134 | | - Future<bool> isDeviceSupported() async => |
135 | | - LocalAuthPlatform.instance.isDeviceSupported(); |
136 | | - |
137 | | - /// Returns a list of enrolled biometrics |
138 | | - /// |
139 | | - /// Returns a [Future] List<BiometricType> with the following possibilities: |
140 | | - /// - BiometricType.face |
141 | | - /// - BiometricType.fingerprint |
142 | | - /// - BiometricType.iris (not yet implemented) |
143 | | - Future<List<BiometricType>> getAvailableBiometrics() => |
144 | | - LocalAuthPlatform.instance.getEnrolledBiometrics(); |
145 | | -} |
| 5 | +export 'package:local_auth/src/local_auth.dart' show LocalAuthentication; |
| 6 | +export 'package:local_auth_platform_interface/types/auth_options.dart' |
| 7 | + show AuthenticationOptions; |
| 8 | +export 'package:local_auth_platform_interface/types/biometric_type.dart' |
| 9 | + show BiometricType; |
0 commit comments