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

[local_auth] Refactor package to make use of new platform interface and native implementations #4701

Merged
merged 91 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
94c4904
Add platform interface for local_auth plugin to prepare for federated…
BeMacized Jan 26, 2022
c2b28d2
Add iOS implementation for local_auth_platform_interface
BeMacized Jan 26, 2022
7b510a9
Add Android implementation for local_auth_platform_interface
BeMacized Jan 26, 2022
57c6bfa
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Jan 26, 2022
0b425bb
Refactor app facing plugin to make use of new platform interface and …
BeMacized Jan 26, 2022
414d74b
Fix format
BeMacized Jan 26, 2022
c35fd92
Fix analysis issues
BeMacized Jan 26, 2022
2c6a9a9
Fix format
BeMacized Jan 26, 2022
cebd846
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Jan 26, 2022
7f94624
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Jan 26, 2022
378af3c
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Jan 26, 2022
3ebe894
Fix analysis warnings
BeMacized Jan 26, 2022
deea66c
Fix analysis warnings
BeMacized Jan 26, 2022
0bbc91b
Merge branch 'local_auth/federation_android' into local_auth/federati…
BeMacized Jan 26, 2022
7b63b80
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Jan 26, 2022
bd35a9f
Move local_auth plugin into a subfolder in preparation for federation…
BeMacized Jan 27, 2022
e10bbb8
Process PR Feedback
BeMacized Jan 27, 2022
86f7ac5
Merge branch 'local_auth/federation_initial_move' into local_auth/fed…
BeMacized Jan 27, 2022
164abaa
Merge remote-tracking branch 'upstream/master' into local_auth/federa…
BeMacized Jan 27, 2022
c3d5a1b
Fix typo in file name
BeMacized Jan 27, 2022
6f1150e
Merge remote-tracking branch 'upstream/master' into local_auth/federa…
BeMacized Jan 27, 2022
24556fa
Add iOS implementation of platform interface
BeMacized Jan 27, 2022
f7d2d85
Merge remote-tracking branch 'upstream/master' into local_auth/federa…
BeMacized Jan 27, 2022
cdf2cfe
Add Android implementation of platform interface
BeMacized Jan 27, 2022
41843c9
Adjust to changes in platform interface
BeMacized Jan 27, 2022
af311cc
Adjust to changes in platform interface
BeMacized Jan 27, 2022
4266130
Added missing implements field in pubspec
BeMacized Jan 27, 2022
ddf0ba4
Added missing implements field in pubspec
BeMacized Jan 27, 2022
24765b2
Update doc in default method channel platform
BeMacized Jan 31, 2022
81ba7e8
Implement PR feedback
BeMacized Jan 31, 2022
f4e643f
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
7de1528
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
8633ca9
Move string to iOS package
BeMacized Feb 7, 2022
a371a87
Move string to Android package
BeMacized Feb 7, 2022
c4086e8
Remove auth strings from platform interface
BeMacized Feb 7, 2022
c7a662f
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
1a25f79
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
475fd89
Change interface for handing platform specific messages
BeMacized Feb 7, 2022
9700b09
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
37cf40f
Implement platform interface changes
BeMacized Feb 7, 2022
c0a867e
Change interface for handing platform specific messages
BeMacized Feb 7, 2022
0e43314
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
af77551
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
939d3b3
Implement platform interface changes
BeMacized Feb 7, 2022
fae0fda
Merge branch 'local_auth/federation_android' into local_auth/federati…
BeMacized Feb 7, 2022
1972470
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Feb 7, 2022
6c7d7b6
Fix unit test
BeMacized Feb 7, 2022
441509e
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Feb 7, 2022
25bb0ca
Add equality for IOSAuthMessages
BeMacized Feb 7, 2022
61bd127
Add equality for AndroidAuthMessages
BeMacized Feb 7, 2022
c2fa958
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Feb 7, 2022
71e160f
Merge branch 'local_auth/federation_android' into local_auth/federati…
BeMacized Feb 7, 2022
083689f
Add equality for AuthenticationOptions
BeMacized Feb 7, 2022
eaa9e69
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
71480ab
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
e0ed674
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 7, 2022
bed6110
Fix unit tests
BeMacized Feb 7, 2022
ae34800
Format
BeMacized Feb 7, 2022
f1cd43d
Format
BeMacized Feb 7, 2022
3242479
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Feb 7, 2022
be2f1e0
Merge branch 'local_auth/federation_android' into local_auth/federati…
BeMacized Feb 7, 2022
bf20040
Add unit test for requestAuthentication. Refactored now deprecated me…
BeMacized Feb 7, 2022
7c94323
Add current implementation for canCheckBiometrics
BeMacized Feb 7, 2022
3b1915b
Add current implementation for canCheckBiometrics
BeMacized Feb 7, 2022
4f0ec1e
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Feb 7, 2022
279209e
Merge branch 'local_auth/federation_android' into local_auth/federati…
BeMacized Feb 7, 2022
92ec8bc
Process PR feedback
BeMacized Feb 11, 2022
afd11f3
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 11, 2022
2652857
Adjust to platform interface changes
BeMacized Feb 11, 2022
2af808b
Merge branch 'local_auth/federation_interface' into local_auth/federa…
BeMacized Feb 11, 2022
63c6d6f
Adjust to platform interface changes
BeMacized Feb 11, 2022
6d205e5
Adjust to platform interface changes
BeMacized Feb 11, 2022
50b1492
Merge branch 'local_auth/federation_android' into local_auth/federati…
BeMacized Feb 11, 2022
b228ad9
Merge branch 'local_auth/federation_ios' into local_auth/federation_app
BeMacized Feb 11, 2022
dc80c17
Adjust to platform interface changes
BeMacized Feb 11, 2022
b499c48
Merge branch 'master' into local_auth/federation_android
BeMacized Feb 14, 2022
116c795
Update platform interface dependency
BeMacized Feb 14, 2022
7c97e48
Fixed order of keys in pubspec
BeMacized Feb 14, 2022
6a49858
Merge branch 'main' into local_auth/federation_android
BeMacized Mar 10, 2022
222253f
Implement PR feedback (from iOS PR)
BeMacized Mar 10, 2022
21c3dc6
Merge branch 'local_auth/federation_android' into local_auth/federati…
BeMacized Mar 11, 2022
c9d10a6
Update PR with changes from PRs for native functionality
BeMacized Mar 11, 2022
3a2db46
Update PR to use newly merged changes from earlier PRs.
BeMacized Apr 12, 2022
267c4a8
Revert changes to project.pbxproj
BeMacized Apr 12, 2022
1a6d9ed
Add missing dev dependency
BeMacized Apr 12, 2022
6188c99
Add missing license header
BeMacized Apr 12, 2022
7103054
Process PR feedback. Removed deprecated methods.
BeMacized Apr 13, 2022
1d47b0f
Update dependency version
BeMacized Apr 14, 2022
546fd6d
Fix analysis issue
BeMacized Apr 14, 2022
c0813d9
Merge remote-tracking branch 'upstream/master' into local_auth/federa…
BeMacized Apr 14, 2022
ae420e6
Process PR feedback
BeMacized Apr 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/local_auth/local_auth/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ Aleksandr Yurkovskiy <[email protected]>
Anton Borries <[email protected]>
Alex Li <[email protected]>
Rahul Raj <[email protected]>
Bodhi Mulders <[email protected]>
39 changes: 37 additions & 2 deletions packages/local_auth/local_auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
## NEXT
## 2.0.0

* Migrates plugin to federated architecture.
* Adds OS version support information to README.
* Switches over to default method implementation in new platform interface.
* BREAKING CHANGE: Deprecated method `authenticateWithBiometrics` has been removed.
Use `authenticate` instead.
* BREAKING CHANGE: Enum `BiometricType` has been expanded with options for `strong` and `weak`,
and applications should be updated to handle these accordingly.
* BREAKING CHANGE: Parameters of `authenticate` have been changed.

Example:
```dart
// Old way of calling `authenticate`.
Future<bool> authenticate(
localizedReason: 'localized reason',
useErrorDialogs: true,
stickyAuth: false,
androidAuthStrings: const AndroidAuthMessages(),
iOSAuthStrings: const IOSAuthMessages(),
sensitiveTransaction: true,
biometricOnly: false,
);
// New way of calling `authenticate`.
Future<bool> authenticate(
localizedReason: 'localized reason',
authMessages: const <AuthMessages>[
IOSAuthMessages(),
AndroidAuthMessages()
],
options: const AuthenticationOptions(
useErrorDialogs: true,
stickyAuth: false,
sensitiveTransaction: true,
biometricOnly: false,
),
);
```



## 1.1.11

Expand Down
16 changes: 11 additions & 5 deletions packages/local_auth/local_auth/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ class _MyAppState extends State<MyApp> {
_authorized = 'Authenticating';
});
authenticated = await auth.authenticate(
localizedReason: 'Let OS determine authentication method',
localizedReason: 'Let OS determine authentication method',
options: const AuthenticationOptions(
useErrorDialogs: true,
stickyAuth: true);
stickyAuth: true,
),
);
setState(() {
_isAuthenticating = false;
});
Expand Down Expand Up @@ -109,11 +112,14 @@ class _MyAppState extends State<MyApp> {
_authorized = 'Authenticating';
});
authenticated = await auth.authenticate(
localizedReason:
'Scan your fingerprint (or face or whatever) to authenticate',
localizedReason:
'Scan your fingerprint (or face or whatever) to authenticate',
options: const AuthenticationOptions(
useErrorDialogs: true,
stickyAuth: true,
biometricOnly: true);
biometricOnly: true,
),
);
setState(() {
_isAuthenticating = false;
_authorized = 'Authenticating';
Expand Down
164 changes: 0 additions & 164 deletions packages/local_auth/local_auth/lib/auth_strings.dart

This file was deleted.

146 changes: 5 additions & 141 deletions packages/local_auth/local_auth/lib/local_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,144 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This is a temporary ignore to allow us to land a new set of linter rules in a
// series of manageable patches instead of one gigantic PR. It disables some of
// the new lints that are already failing on this plugin, for this plugin. It
// should be deleted and the failing lints addressed as soon as possible.
// ignore_for_file: public_member_api_docs

import 'dart:async';

import 'package:flutter/foundation.dart' show visibleForTesting;
import 'package:flutter/services.dart';
import 'package:local_auth_platform_interface/local_auth_platform_interface.dart';
import 'package:platform/platform.dart';
import 'auth_strings.dart';

export 'package:local_auth_platform_interface/types/biometric_type.dart';

Platform _platform = const LocalPlatform();

@visibleForTesting
void setMockPathProviderPlatform(Platform platform) {
_platform = platform;
}

/// A Flutter plugin for authenticating the user identity locally.
class LocalAuthentication {
/// The `authenticateWithBiometrics` method has been deprecated.
/// Use `authenticate` with `biometricOnly: true` instead.
@Deprecated('Use `authenticate` with `biometricOnly: true` instead')
Future<bool> authenticateWithBiometrics({
required String localizedReason,
bool useErrorDialogs = true,
bool stickyAuth = false,
AndroidAuthMessages androidAuthStrings = const AndroidAuthMessages(),
IOSAuthMessages iOSAuthStrings = const IOSAuthMessages(),
bool sensitiveTransaction = true,
}) =>
LocalAuthPlatform.instance.authenticate(
localizedReason: localizedReason,
authMessages: <AuthMessages>[iOSAuthStrings, androidAuthStrings],
options: AuthenticationOptions(
useErrorDialogs: useErrorDialogs,
stickyAuth: stickyAuth,
sensitiveTransaction: sensitiveTransaction,
biometricOnly: true,
),
);

/// Authenticates the user with biometrics available on the device while also
/// allowing the user to use device authentication - pin, pattern, passcode.
///
/// Returns true, if the user successfully authenticated, false otherwise.
///
/// [localizedReason] is the message to show to user while prompting them
/// for authentication. This is typically along the lines of: 'Please scan
/// your finger to access MyApp.'. This must not be empty.
///
/// [useErrorDialogs] = true means the system will attempt to handle user
/// fixable issues encountered while authenticating. For instance, if
/// fingerprint reader exists on the phone but there's no fingerprint
/// registered, the plugin will attempt to take the user to settings to add
/// one. Anything that is not user fixable, such as no biometric sensor on
/// device, will be returned as a [PlatformException].
///
/// [stickyAuth] is used when the application goes into background for any
/// reason while the authentication is in progress. Due to security reasons,
/// the authentication has to be stopped at that time. If stickyAuth is set
/// to true, authentication resumes when the app is resumed. If it is set to
/// false (default), then as soon as app is paused a failure message is sent
/// back to Dart and it is up to the client app to restart authentication or
/// do something else.
///
/// Construct [AndroidAuthStrings] and [IOSAuthStrings] if you want to
/// customize messages in the dialogs.
///
/// Setting [sensitiveTransaction] to true enables platform specific
/// precautions. For instance, on face unlock, Android opens a confirmation
/// dialog after the face is recognized to make sure the user meant to unlock
/// their phone.
///
/// Setting [biometricOnly] to true prevents authenticates from using non-biometric
/// local authentication such as pin, passcode, and passcode.
///
/// Throws an [PlatformException] if there were technical problems with local
/// authentication (e.g. lack of relevant hardware). This might throw
/// [PlatformException] with error code [otherOperatingSystem] on the iOS
/// simulator.
Future<bool> authenticate({
required String localizedReason,
bool useErrorDialogs = true,
bool stickyAuth = false,
AndroidAuthMessages androidAuthStrings = const AndroidAuthMessages(),
IOSAuthMessages iOSAuthStrings = const IOSAuthMessages(),
bool sensitiveTransaction = true,
bool biometricOnly = false,
}) {
return LocalAuthPlatform.instance.authenticate(
localizedReason: localizedReason,
authMessages: <AuthMessages>[iOSAuthStrings, androidAuthStrings],
options: AuthenticationOptions(
useErrorDialogs: useErrorDialogs,
stickyAuth: stickyAuth,
sensitiveTransaction: sensitiveTransaction,
biometricOnly: biometricOnly,
),
);
}

/// Returns true if auth was cancelled successfully.
/// This api only works for Android.
/// Returns false if there was some error or no auth in progress.
///
/// Returns [Future] bool true or false:
Future<bool> stopAuthentication() async {
if (_platform.isAndroid) {
return LocalAuthPlatform.instance.stopAuthentication();
}
return true;
}

/// Returns true if device is capable of checking biometrics
///
/// Returns a [Future] bool true or false:
Future<bool> get canCheckBiometrics =>
LocalAuthPlatform.instance.deviceSupportsBiometrics();

/// Returns true if device is capable of checking biometrics or is able to
/// fail over to device credentials.
///
/// Returns a [Future] bool true or false:
Future<bool> isDeviceSupported() async =>
LocalAuthPlatform.instance.isDeviceSupported();

/// Returns a list of enrolled biometrics
///
/// Returns a [Future] List<BiometricType> with the following possibilities:
/// - BiometricType.face
/// - BiometricType.fingerprint
/// - BiometricType.iris (not yet implemented)
Future<List<BiometricType>> getAvailableBiometrics() =>
LocalAuthPlatform.instance.getEnrolledBiometrics();
}
export 'package:local_auth/src/local_auth.dart' show LocalAuthentication;
export 'package:local_auth_platform_interface/types/auth_options.dart'
show AuthenticationOptions;
export 'package:local_auth_platform_interface/types/biometric_type.dart'
show BiometricType;
Loading