This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[local_auth] Add platform interface to prepare for migration to federated architecture #4697
Merged
fluttergithubbot
merged 15 commits into
flutter:main
from
Baseflow:local_auth/federation_interface
Feb 14, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
94c4904
Add platform interface for local_auth plugin to prepare for federated…
BeMacized 414d74b
Fix format
BeMacized c35fd92
Fix analysis issues
BeMacized 2c6a9a9
Fix format
BeMacized bd35a9f
Move local_auth plugin into a subfolder in preparation for federation…
BeMacized e10bbb8
Process PR Feedback
BeMacized 86f7ac5
Merge branch 'local_auth/federation_initial_move' into local_auth/fed…
BeMacized 164abaa
Merge remote-tracking branch 'upstream/master' into local_auth/federa…
BeMacized c3d5a1b
Fix typo in file name
BeMacized 24765b2
Update doc in default method channel platform
BeMacized 81ba7e8
Implement PR feedback
BeMacized c4086e8
Remove auth strings from platform interface
BeMacized c0a867e
Change interface for handing platform specific messages
BeMacized 083689f
Add equality for AuthenticationOptions
BeMacized 92ec8bc
Process PR feedback
BeMacized File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,67 @@ | ||
| # Below is a list of people and organizations that have contributed | ||
| # to the Flutter project. Names should be added to the list like so: | ||
| # | ||
| # Name/Organization <email address> | ||
|
|
||
| Google Inc. | ||
| The Chromium Authors | ||
| German Saprykin <[email protected]> | ||
| Benjamin Sauer <[email protected]> | ||
| [email protected] | ||
| Ali Bitek <[email protected]> | ||
| Pol Batlló <[email protected]> | ||
| Anatoly Pulyaevskiy | ||
| Hayden Flinner <[email protected]> | ||
| Stefano Rodriguez <[email protected]> | ||
| Salvatore Giordano <[email protected]> | ||
| Brian Armstrong <[email protected]> | ||
| Paul DeMarco <[email protected]> | ||
| Fabricio Nogueira <[email protected]> | ||
| Simon Lightfoot <[email protected]> | ||
| Ashton Thomas <[email protected]> | ||
| Thomas Danner <[email protected]> | ||
| Diego Velásquez <[email protected]> | ||
| Hajime Nakamura <[email protected]> | ||
| Tuyển Vũ Xuân <[email protected]> | ||
| Miguel Ruivo <[email protected]> | ||
| Sarthak Verma <[email protected]> | ||
| Mike Diarmid <[email protected]> | ||
| Invertase <[email protected]> | ||
| Elliot Hesp <[email protected]> | ||
| Vince Varga <[email protected]> | ||
| Aawaz Gyawali <[email protected]> | ||
| EUI Limited <[email protected]> | ||
| Katarina Sheremet <[email protected]> | ||
| Thomas Stockx <[email protected]> | ||
| Sarbagya Dhaubanjar <[email protected]> | ||
| Ozkan Eksi <[email protected]> | ||
| Rishab Nayak <[email protected]> | ||
| ko2ic <[email protected]> | ||
| Jonathan Younger <[email protected]> | ||
| Jose Sanchez <[email protected]> | ||
| Debkanchan Samadder <[email protected]> | ||
| Audrius Karosevicius <[email protected]> | ||
| Lukasz Piliszczuk <[email protected]> | ||
| SoundReply Solutions GmbH <[email protected]> | ||
| Rafal Wachol <[email protected]> | ||
| Pau Picas <[email protected]> | ||
| Christian Weder <[email protected]> | ||
| Alexandru Tuca <[email protected]> | ||
| Christian Weder <[email protected]> | ||
| Rhodes Davis Jr. <[email protected]> | ||
| Luigi Agosti <[email protected]> | ||
| Quentin Le Guennec <[email protected]> | ||
| Koushik Ravikumar <[email protected]> | ||
| Nissim Dsilva <[email protected]> | ||
| Giancarlo Rocha <[email protected]> | ||
| Ryo Miyake <[email protected]> | ||
| Théo Champion <[email protected]> | ||
| Kazuki Yamaguchi <[email protected]> | ||
| Eitan Schwartz <[email protected]> | ||
| Chris Rutkowski <[email protected]> | ||
| Juan Alvarez <[email protected]> | ||
| Aleksandr Yurkovskiy <[email protected]> | ||
| Anton Borries <[email protected]> | ||
| Alex Li <[email protected]> | ||
| Rahul Raj <[email protected]> | ||
| Bodhi Mulders <[email protected]> |
3 changes: 3 additions & 0 deletions
3
packages/local_auth/local_auth_platform_interface/CHANGELOG.md
This file contains hidden or 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 @@ | ||
| ## 1.0.0 | ||
|
|
||
| * Initial release. |
This file contains hidden or 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,25 @@ | ||
| Copyright 2013 The Flutter 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. |
26 changes: 26 additions & 0 deletions
26
packages/local_auth/local_auth_platform_interface/README.md
This file contains hidden or 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,26 @@ | ||
| # local_auth_platform_interface | ||
|
|
||
| A common platform interface for the [`local_auth`][1] plugin. | ||
|
|
||
| This interface allows platform-specific implementations of the `local_auth` | ||
| plugin, as well as the plugin itself, to ensure they are supporting the | ||
| same interface. | ||
|
|
||
| # Usage | ||
|
|
||
| To implement a new platform-specific implementation of `local_auth`, extend | ||
| [`LocalAuthPlatform`][2] with an implementation that performs the | ||
| platform-specific behavior, and when you register your plugin, set the default | ||
| `LocalAuthPlatform` by calling | ||
| `LocalAuthPlatform.instance = MyLocalAuthPlatform()`. | ||
|
|
||
| # Note on breaking changes | ||
|
|
||
| Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
| over breaking changes for this package. | ||
|
|
||
| See https://flutter.dev/go/platform-interface-breaking-changes for a discussion | ||
| on why a less-clean interface is preferable to a breaking change. | ||
|
|
||
| [1]: ../local_auth | ||
| [2]: lib/local_auth_platform_interface.dart |
78 changes: 78 additions & 0 deletions
78
packages/local_auth/local_auth_platform_interface/lib/default_method_channel_platform.dart
This file contains hidden or 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,78 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/services.dart'; | ||
| import 'package:local_auth_platform_interface/local_auth_platform_interface.dart'; | ||
| import 'package:local_auth_platform_interface/types/auth_messages.dart'; | ||
| import 'package:local_auth_platform_interface/types/auth_options.dart'; | ||
| import 'package:local_auth_platform_interface/types/biometric_type.dart'; | ||
|
|
||
| const MethodChannel _channel = MethodChannel('plugins.flutter.io/local_auth'); | ||
|
|
||
| /// The default interface implementation acting as a placeholder for | ||
| /// the native implementation to be set. | ||
| /// | ||
| /// This implementation is not used by any of the implementations in this | ||
| /// repository, and exists only for backward compatibility with any | ||
| /// clients that were relying on internal details of the method channel | ||
| /// in the pre-federated plugin. | ||
| class DefaultLocalAuthPlatform extends LocalAuthPlatform { | ||
| @override | ||
| Future<bool> authenticate({ | ||
| required String localizedReason, | ||
| required Iterable<AuthMessages> authMessages, | ||
| AuthenticationOptions options = const AuthenticationOptions(), | ||
| }) async { | ||
| assert(localizedReason.isNotEmpty); | ||
| final Map<String, Object> args = <String, Object>{ | ||
| 'localizedReason': localizedReason, | ||
| 'useErrorDialogs': options.useErrorDialogs, | ||
| 'stickyAuth': options.stickyAuth, | ||
| 'sensitiveTransaction': options.sensitiveTransaction, | ||
| 'biometricOnly': options.biometricOnly, | ||
| }; | ||
| for (final AuthMessages messages in authMessages) { | ||
| args.addAll(messages.args); | ||
| } | ||
| return (await _channel.invokeMethod<bool>('authenticate', args)) ?? false; | ||
| } | ||
|
|
||
| @override | ||
| Future<List<BiometricType>> getEnrolledBiometrics() async { | ||
| final List<String> result = (await _channel.invokeListMethod<String>( | ||
| 'getAvailableBiometrics', | ||
| )) ?? | ||
| <String>[]; | ||
| final List<BiometricType> biometrics = <BiometricType>[]; | ||
| for (final String value in result) { | ||
| switch (value) { | ||
| case 'face': | ||
| biometrics.add(BiometricType.face); | ||
| break; | ||
| case 'fingerprint': | ||
| biometrics.add(BiometricType.fingerprint); | ||
| break; | ||
| case 'iris': | ||
| biometrics.add(BiometricType.iris); | ||
| break; | ||
| case 'undefined': | ||
| break; | ||
| } | ||
| } | ||
| return biometrics; | ||
| } | ||
|
|
||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @override | ||
| Future<bool> deviceSupportsBiometrics() async { | ||
| return (await getEnrolledBiometrics()).isNotEmpty; | ||
| } | ||
|
|
||
| @override | ||
| Future<bool> isDeviceSupported() async => | ||
| (await _channel.invokeMethod<bool>('isDeviceSupported')) ?? false; | ||
|
|
||
| @override | ||
| Future<bool> stopAuthentication() async => | ||
| await _channel.invokeMethod<bool>('stopAuthentication') ?? false; | ||
| } | ||
99 changes: 99 additions & 0 deletions
99
packages/local_auth/local_auth_platform_interface/lib/local_auth_platform_interface.dart
This file contains hidden or 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,99 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:local_auth_platform_interface/default_method_channel_platform.dart'; | ||
| import 'package:local_auth_platform_interface/types/auth_messages.dart'; | ||
| import 'package:local_auth_platform_interface/types/auth_options.dart'; | ||
| import 'package:local_auth_platform_interface/types/biometric_type.dart'; | ||
| import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
|
||
| /// The interface that implementations of local_auth must implement. | ||
| /// | ||
| /// Platform implementations should extend this class rather than implement it as `local_auth` | ||
| /// does not consider newly added methods to be breaking changes. Extending this class | ||
| /// (using `extends`) ensures that the subclass will get the default implementation, while | ||
| /// platform implementations that `implements` this interface will be broken by newly added | ||
| /// [LocalAuthPlatform] methods. | ||
| abstract class LocalAuthPlatform extends PlatformInterface { | ||
| /// Constructs a LocalAuthPlatform. | ||
| LocalAuthPlatform() : super(token: _token); | ||
|
|
||
| static final Object _token = Object(); | ||
|
|
||
| static LocalAuthPlatform _instance = DefaultLocalAuthPlatform(); | ||
|
|
||
| /// The default instance of [LocalAuthPlatform] to use. | ||
| /// | ||
| /// Defaults to [DefaultLocalAuthPlatform]. | ||
| static LocalAuthPlatform get instance => _instance; | ||
|
|
||
| /// Platform-specific implementations should set this with their own | ||
| /// platform-specific class that extends [LocalAuthPlatform] when they | ||
| /// register themselves. | ||
| static set instance(LocalAuthPlatform instance) { | ||
| PlatformInterface.verifyToken(instance, _token); | ||
| _instance = instance; | ||
| } | ||
|
|
||
| /// 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. | ||
| /// | ||
| /// Provide [authMessages] if you want to | ||
| /// customize messages in the dialogs. | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// | ||
| /// Provide [options] for configuring further authentication related options. | ||
| /// | ||
| /// Throws a [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, | ||
| required Iterable<AuthMessages> authMessages, | ||
| AuthenticationOptions options = const AuthenticationOptions(), | ||
| }) async { | ||
| throw UnimplementedError('authenticate() has not been implemented.'); | ||
| } | ||
|
|
||
| /// Returns true if the device is capable of checking biometrics. | ||
BeMacized marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// | ||
| /// This will return true even if there are no biometrics currently enrolled. | ||
| Future<bool> deviceSupportsBiometrics() async { | ||
| throw UnimplementedError('canCheckBiometrics() has not been implemented.'); | ||
| } | ||
|
|
||
| /// Returns a list of enrolled biometrics. | ||
| /// | ||
| /// Possible values include: | ||
| /// - BiometricType.face | ||
| /// - BiometricType.fingerprint | ||
| /// - BiometricType.iris (not yet implemented) | ||
BeMacized marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// - BiometricType.strong | ||
| /// - BiometricType.weak | ||
| Future<List<BiometricType>> getEnrolledBiometrics() async { | ||
| throw UnimplementedError( | ||
| 'getAvailableBiometrics() has not been implemented.'); | ||
| } | ||
|
|
||
| /// Returns true if device is capable of checking biometrics or is able to | ||
| /// fail over to device credentials. | ||
| Future<bool> isDeviceSupported() async { | ||
| throw UnimplementedError('isDeviceSupported() has not been implemented.'); | ||
| } | ||
|
|
||
| /// Cancels any authentication currently in progress. | ||
| /// | ||
| /// Returns true if auth was cancelled successfully. | ||
| /// Returns false if there was no authentication in progress, | ||
| /// or an error occurred. | ||
| Future<bool> stopAuthentication() async { | ||
| throw UnimplementedError('stopAuthentication() has not been implemented.'); | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
packages/local_auth/local_auth_platform_interface/lib/types/auth_messages.dart
This file contains hidden or 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 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// Abstract class for storing platform specific strings. | ||
| abstract class AuthMessages { | ||
| /// Constructs an instance of [AuthMessages]. | ||
| const AuthMessages(); | ||
|
|
||
| /// Returns all platform-specific messages as a map. | ||
| Map<String, String> get args; | ||
| } |
60 changes: 60 additions & 0 deletions
60
packages/local_auth/local_auth_platform_interface/lib/types/auth_options.dart
This file contains hidden or 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,60 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
| /// Options wrapper for [LocalAuthPlatform.authenticate] parameters. | ||
| @immutable | ||
| class AuthenticationOptions { | ||
| /// Constructs a new instance. | ||
| const AuthenticationOptions({ | ||
| this.useErrorDialogs = true, | ||
| this.stickyAuth = false, | ||
| this.sensitiveTransaction = true, | ||
| this.biometricOnly = false, | ||
| }); | ||
|
|
||
| /// Whether the system will attempt to handle user-fixable issues encountered | ||
| /// while authenticating. For instance, if a fingerprint reader exists on the | ||
| /// device but there's no fingerprint registered, the plugin might attempt to | ||
| /// take the user to settings to add one. Anything that is not user fixable, | ||
| /// such as no biometric sensor on device, will still result in | ||
| /// a [PlatformException]. | ||
| final bool useErrorDialogs; | ||
|
|
||
| /// 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. | ||
| final bool stickyAuth; | ||
|
|
||
| /// Whether platform specific precautions are enabled. For instance, on face | ||
| /// unlock, Android opens a confirmation dialog after the face is recognized | ||
| /// to make sure the user meant to unlock their device. | ||
| final bool sensitiveTransaction; | ||
|
|
||
| /// Prevent authentications from using non-biometric local authentication | ||
| /// such as pin, passcode, or pattern. | ||
| final bool biometricOnly; | ||
|
|
||
| @override | ||
| bool operator ==(Object other) => | ||
| identical(this, other) || | ||
| other is AuthenticationOptions && | ||
| runtimeType == other.runtimeType && | ||
| useErrorDialogs == other.useErrorDialogs && | ||
| stickyAuth == other.stickyAuth && | ||
| sensitiveTransaction == other.sensitiveTransaction && | ||
| biometricOnly == other.biometricOnly; | ||
|
|
||
| @override | ||
| int get hashCode => | ||
| useErrorDialogs.hashCode ^ | ||
| stickyAuth.hashCode ^ | ||
| sensitiveTransaction.hashCode ^ | ||
| biometricOnly.hashCode; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.