Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 67 additions & 0 deletions packages/local_auth/local_auth_platform_interface/AUTHORS
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]>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

* Initial release.
25 changes: 25 additions & 0 deletions packages/local_auth/local_auth_platform_interface/LICENSE
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 packages/local_auth/local_auth_platform_interface/README.md
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
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;
}

@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;
}
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.
///
/// 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.
///
/// 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)
/// - 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.');
}
}
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;
}
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;
}
Loading