Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit b2f5465

Browse files
authored
[local_auth] Refactor package to make use of new platform interface and native implementations (#4701)
1 parent b76f3f5 commit b2f5465

File tree

9 files changed

+142
-358
lines changed

9 files changed

+142
-358
lines changed

packages/local_auth/local_auth/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <[email protected]>
6464
Anton Borries <[email protected]>
6565
6666
Rahul Raj <[email protected]>
67+
Bodhi Mulders <[email protected]>

packages/local_auth/local_auth/CHANGELOG.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1-
## NEXT
1+
## 2.0.0
22

3+
* Migrates plugin to federated architecture.
34
* Adds OS version support information to README.
4-
* Switches over to default method implementation in new platform interface.
5+
* BREAKING CHANGE: Deprecated method `authenticateWithBiometrics` has been removed.
6+
Use `authenticate` instead.
7+
* BREAKING CHANGE: Enum `BiometricType` has been expanded with options for `strong` and `weak`,
8+
and applications should be updated to handle these accordingly.
9+
* BREAKING CHANGE: Parameters of `authenticate` have been changed.
10+
11+
Example:
12+
```dart
13+
// Old way of calling `authenticate`.
14+
Future<bool> authenticate(
15+
localizedReason: 'localized reason',
16+
useErrorDialogs: true,
17+
stickyAuth: false,
18+
androidAuthStrings: const AndroidAuthMessages(),
19+
iOSAuthStrings: const IOSAuthMessages(),
20+
sensitiveTransaction: true,
21+
biometricOnly: false,
22+
);
23+
// New way of calling `authenticate`.
24+
Future<bool> authenticate(
25+
localizedReason: 'localized reason',
26+
authMessages: const <AuthMessages>[
27+
IOSAuthMessages(),
28+
AndroidAuthMessages()
29+
],
30+
options: const AuthenticationOptions(
31+
useErrorDialogs: true,
32+
stickyAuth: false,
33+
sensitiveTransaction: true,
34+
biometricOnly: false,
35+
),
36+
);
37+
```
38+
39+
540

641
## 1.1.11
742

packages/local_auth/local_auth/example/lib/main.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ class _MyAppState extends State<MyApp> {
7979
_authorized = 'Authenticating';
8080
});
8181
authenticated = await auth.authenticate(
82-
localizedReason: 'Let OS determine authentication method',
82+
localizedReason: 'Let OS determine authentication method',
83+
options: const AuthenticationOptions(
8384
useErrorDialogs: true,
84-
stickyAuth: true);
85+
stickyAuth: true,
86+
),
87+
);
8588
setState(() {
8689
_isAuthenticating = false;
8790
});
@@ -109,11 +112,14 @@ class _MyAppState extends State<MyApp> {
109112
_authorized = 'Authenticating';
110113
});
111114
authenticated = await auth.authenticate(
112-
localizedReason:
113-
'Scan your fingerprint (or face or whatever) to authenticate',
115+
localizedReason:
116+
'Scan your fingerprint (or face or whatever) to authenticate',
117+
options: const AuthenticationOptions(
114118
useErrorDialogs: true,
115119
stickyAuth: true,
116-
biometricOnly: true);
120+
biometricOnly: true,
121+
),
122+
);
117123
setState(() {
118124
_isAuthenticating = false;
119125
_authorized = 'Authenticating';

packages/local_auth/local_auth/lib/auth_strings.dart

Lines changed: 0 additions & 164 deletions
This file was deleted.

packages/local_auth/local_auth/lib/local_auth.dart

Lines changed: 5 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -2,144 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

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

Comments
 (0)