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] Windows support. #4806
Merged
Merged
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7ccd968
[local_auth] Windows support.
azchohfi 3906da5
Merge branch 'main' into local_auth_windows
azchohfi 70c341d
Merge branch 'main' into local_auth_windows
azchohfi c492f89
Merge branch 'main' into local_auth_windows
azchohfi c997ad8
Handling biometricOnly parameter.
azchohfi 9cf0a1a
Merge branch 'main' into local_auth_windows
azchohfi 975ca8d
Fixed readme
azchohfi 3fcbca7
[local_auth] Fix version and readme.
azchohfi 34afbf5
Merge branch 'main' into local_auth_windows
azchohfi 835f5cc
[local_auth] Small fixes.
azchohfi 9eaba3c
Small fix.
azchohfi 22ec14c
Fixed tests.
azchohfi 9349aab
Added local_auth_windows tests.
azchohfi 1032693
PR Feedback.
azchohfi 1659e49
Merge branch 'local_auth_windows' of https://github.com/azchohfi/plug…
azchohfi 8c7a87b
Fixed tests.
azchohfi bf47529
Added more tests.
azchohfi 8143983
Revert changes in local_auth.
azchohfi bcf105b
Merge branch 'main' into local_auth_windows
azchohfi a4f02f4
Merge branch 'main' into local_auth_windows
azchohfi 7449a5c
Merge branch 'main' into local_auth_windows
azchohfi fb26c93
Merge branch 'main' into local_auth_windows
azchohfi e9ab4ef
[local_auth_windows] Fixed authors list.
azchohfi 30f0958
[local_auth_windows] Fixed changelog.
azchohfi 97e1ee9
[local_auth_windows] PR feedback.
azchohfi 40aa9a2
Merge branch 'main' into local_auth_windows
azchohfi 6813b7b
Fixed build
azchohfi 47823c6
Fixed format.
azchohfi 45ceb6e
Merge branch 'main' into local_auth_windows
azchohfi 271a49e
Applied more PR feedback.
azchohfi e1e24a6
Added C++ comments.
azchohfi cabc43e
Small doc fixes.
azchohfi 34a58de
Merge branch 'main' into local_auth_windows
azchohfi 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,7 @@ | ||
# 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. | ||
Alexandre Zollinger Chohfi <alzollin@microsoft.com> |
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 of Windows support. |
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. |
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,11 @@ | ||
# local\_auth\_windows | ||
|
||
The Windows implementation of [`local_auth`][1]. | ||
|
||
## Usage | ||
|
||
This package is [endorsed][2], which means you can simply use `local_auth` | ||
normally. This package will be automatically included in your app when you do. | ||
|
||
[1]: https://pub.dev/packages/local_auth | ||
[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin |
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,46 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/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,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: c860cba910319332564e1e9d470a17074c1f2dfd | ||
channel: stable | ||
|
||
project_type: app |
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,8 @@ | ||
# local_auth_example | ||
|
||
Demonstrates how to use the local_auth plugin. | ||
|
||
## Getting Started | ||
|
||
For help getting started with Flutter, view our online | ||
[documentation](https://flutter.dev/). |
19 changes: 19 additions & 0 deletions
19
packages/local_auth/local_auth_windows/example/integration_test/local_auth_test.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,19 @@ | ||
// 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_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import 'package:local_auth_windows/local_auth_windows.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
testWidgets('canCheckBiometrics', (WidgetTester tester) async { | ||
expect( | ||
LocalAuthWindows().getEnrolledBiometrics(), | ||
completion(isList), | ||
); | ||
}); | ||
} |
241 changes: 241 additions & 0 deletions
241
packages/local_auth/local_auth_windows/example/lib/main.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,241 @@ | ||
// 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. | ||
|
||
// ignore_for_file: public_member_api_docs | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:local_auth_platform_interface/local_auth_platform_interface.dart'; | ||
import 'package:local_auth_windows/local_auth_windows.dart'; | ||
|
||
void main() { | ||
runApp(const MyApp()); | ||
} | ||
|
||
class MyApp extends StatefulWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<MyApp> createState() => _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
_SupportState _supportState = _SupportState.unknown; | ||
bool? _deviceSupportsBiometrics; | ||
List<BiometricType>? _enrolledBiometrics; | ||
String _authorized = 'Not Authorized'; | ||
bool _isAuthenticating = false; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
LocalAuthPlatform.instance.isDeviceSupported().then( | ||
(bool isSupported) => setState(() => _supportState = isSupported | ||
? _SupportState.supported | ||
: _SupportState.unsupported), | ||
); | ||
cbracken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
Future<void> _checkBiometrics() async { | ||
late bool deviceSupportsBiometrics; | ||
try { | ||
deviceSupportsBiometrics = | ||
await LocalAuthPlatform.instance.deviceSupportsBiometrics(); | ||
} on PlatformException catch (e) { | ||
deviceSupportsBiometrics = false; | ||
print(e); | ||
} | ||
if (!mounted) { | ||
return; | ||
} | ||
|
||
setState(() { | ||
_deviceSupportsBiometrics = deviceSupportsBiometrics; | ||
}); | ||
} | ||
|
||
Future<void> _getEnrolledBiometrics() async { | ||
late List<BiometricType> availableBiometrics; | ||
try { | ||
availableBiometrics = | ||
await LocalAuthPlatform.instance.getEnrolledBiometrics(); | ||
} on PlatformException catch (e) { | ||
availableBiometrics = <BiometricType>[]; | ||
print(e); | ||
} | ||
if (!mounted) { | ||
return; | ||
} | ||
|
||
setState(() { | ||
_enrolledBiometrics = availableBiometrics; | ||
}); | ||
} | ||
|
||
Future<void> _authenticate() async { | ||
bool authenticated = false; | ||
try { | ||
setState(() { | ||
_isAuthenticating = true; | ||
_authorized = 'Authenticating'; | ||
}); | ||
authenticated = await LocalAuthPlatform.instance.authenticate( | ||
localizedReason: 'Let OS determine authentication method', | ||
authMessages: <AuthMessages>[const WindowsAuthMessages()], | ||
options: const AuthenticationOptions( | ||
useErrorDialogs: true, | ||
stickyAuth: true, | ||
), | ||
); | ||
setState(() { | ||
_isAuthenticating = false; | ||
}); | ||
} on PlatformException catch (e) { | ||
print(e); | ||
setState(() { | ||
_isAuthenticating = false; | ||
_authorized = 'Error - ${e.message}'; | ||
}); | ||
return; | ||
} | ||
if (!mounted) { | ||
return; | ||
} | ||
|
||
setState( | ||
() => _authorized = authenticated ? 'Authorized' : 'Not Authorized'); | ||
cbracken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
Future<void> _authenticateWithBiometrics() async { | ||
bool authenticated = false; | ||
try { | ||
setState(() { | ||
_isAuthenticating = true; | ||
_authorized = 'Authenticating'; | ||
}); | ||
authenticated = await LocalAuthPlatform.instance.authenticate( | ||
localizedReason: | ||
'Scan your fingerprint (or face or whatever) to authenticate', | ||
authMessages: <AuthMessages>[const WindowsAuthMessages()], | ||
options: const AuthenticationOptions( | ||
useErrorDialogs: true, | ||
stickyAuth: true, | ||
biometricOnly: true, | ||
), | ||
); | ||
setState(() { | ||
_isAuthenticating = false; | ||
_authorized = 'Authenticating'; | ||
}); | ||
} on PlatformException catch (e) { | ||
print(e); | ||
setState(() { | ||
_isAuthenticating = false; | ||
_authorized = 'Error - ${e.message}'; | ||
}); | ||
return; | ||
} | ||
if (!mounted) { | ||
return; | ||
} | ||
|
||
final String message = authenticated ? 'Authorized' : 'Not Authorized'; | ||
setState(() { | ||
_authorized = message; | ||
}); | ||
} | ||
|
||
Future<void> _cancelAuthentication() async { | ||
await LocalAuthPlatform.instance.stopAuthentication(); | ||
setState(() => _isAuthenticating = false); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Plugin example app'), | ||
), | ||
body: ListView( | ||
padding: const EdgeInsets.only(top: 30), | ||
children: <Widget>[ | ||
Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
if (_supportState == _SupportState.unknown) | ||
const CircularProgressIndicator() | ||
else if (_supportState == _SupportState.supported) | ||
const Text('This device is supported') | ||
else | ||
const Text('This device is not supported'), | ||
cbracken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const Divider(height: 100), | ||
Text( | ||
'Device supports biometrics: $_deviceSupportsBiometrics\n'), | ||
ElevatedButton( | ||
onPressed: _checkBiometrics, | ||
child: const Text('Check biometrics'), | ||
), | ||
const Divider(height: 100), | ||
Text('Enrolled biometrics: $_enrolledBiometrics\n'), | ||
ElevatedButton( | ||
onPressed: _getEnrolledBiometrics, | ||
child: const Text('Get enrolled biometrics'), | ||
), | ||
const Divider(height: 100), | ||
Text('Current State: $_authorized\n'), | ||
if (_isAuthenticating) | ||
ElevatedButton( | ||
onPressed: _cancelAuthentication, | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: const <Widget>[ | ||
Text('Cancel Authentication'), | ||
Icon(Icons.cancel), | ||
], | ||
), | ||
) | ||
else | ||
Column( | ||
children: <Widget>[ | ||
ElevatedButton( | ||
onPressed: _authenticate, | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: const <Widget>[ | ||
Text('Authenticate'), | ||
Icon(Icons.perm_device_information), | ||
], | ||
), | ||
), | ||
ElevatedButton( | ||
onPressed: _authenticateWithBiometrics, | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: <Widget>[ | ||
Text(_isAuthenticating | ||
? 'Cancel' | ||
: 'Authenticate: biometrics only'), | ||
const Icon(Icons.fingerprint), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
enum _SupportState { | ||
unknown, | ||
supported, | ||
unsupported, | ||
} |
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.