Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[local_auth_darwin] MacOS Support #6267

Open
wants to merge 119 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
532ed7f
Beginning of macos support
alexrabin-sentracam Mar 5, 2024
0eb64ee
Merge branch 'flutter:main' into macos-support
alexrabin-sentracam Mar 5, 2024
25ca34e
Made macos deployment target 10.15
alexrabin-sentracam Mar 5, 2024
c57ac02
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
alexrabin-sentracam Mar 5, 2024
00bd678
Separate ios and macos code
alexrabin-sentracam Mar 5, 2024
509708f
Adjusted format
alexrabin-sentracam Mar 5, 2024
fd6c539
Updated change log
alexrabin-sentracam Mar 5, 2024
44dd8c8
Removed duplicated analysis_options.yaml
Mar 5, 2024
4f68b52
Removed unnecessary widget_test in darwin
Mar 5, 2024
8646867
Added license blocks in macos example files
Mar 5, 2024
676b0eb
Changed iOSAuthMessages to DarwinAuthMessages
Mar 5, 2024
bcee2e7
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 5, 2024
4aab9d8
Added macos comment
Mar 5, 2024
1bded66
Changed macOS capitalization
Mar 5, 2024
7335837
Removed unnecessary test, added comment, and changed version number
Mar 5, 2024
849c07b
Removed prettier ignore
Mar 5, 2024
c810eb4
Reset upgrade version
Mar 5, 2024
6867b3a
Revert "Changed iOSAuthMessages to DarwinAuthMessages" and add MacOSA…
Mar 5, 2024
995f41d
Changed podspec to use ios deployment_target
Mar 5, 2024
8ab5d09
Checks if macos is 10.15 or higher before checking for faceid
Mar 5, 2024
507470e
Shows correct window for registrar
Mar 5, 2024
05b52ae
Changed wording
Mar 5, 2024
8f35101
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 5, 2024
2b0e6d6
Combined @available statements and renamed keywindow
Mar 6, 2024
c808c82
Created initWithRegistrar initializer
Mar 6, 2024
64bd0b7
Moved runner tests
Mar 6, 2024
7dab5b4
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 6, 2024
7ff9871
Fixed format issues
Mar 6, 2024
04f6a76
Revert "Moved runner tests"
Mar 6, 2024
04c8f12
Fixed tests and platform available check
Mar 6, 2024
64366dd
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 6, 2024
7babc9c
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 7, 2024
b71f172
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 7, 2024
cfabac0
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 8, 2024
5bc080e
Added macos tests
Mar 8, 2024
d794eb9
Fixed format
Mar 8, 2024
74ae648
Added info.plist key and added license heading
Mar 8, 2024
2374375
Added xml language to readme
Mar 8, 2024
f053fce
Upgraded project settings
Mar 8, 2024
04049a3
Reset example macos project
Mar 8, 2024
9be16c3
Fixed macos tests
Mar 8, 2024
ff533bc
Removed settings button on macos due to no native support from Apple …
Mar 8, 2024
783b0cc
Added @available check
Mar 8, 2024
5e9b627
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 11, 2024
1748039
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 11, 2024
ebdb5f1
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 11, 2024
b73254a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 12, 2024
c4c9f3b
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 12, 2024
6ca1476
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 18, 2024
69db0ec
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 18, 2024
a39e82a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 19, 2024
59ce98a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 19, 2024
e54c7ea
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 19, 2024
b8ca53a
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 20, 2024
018fe8f
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 20, 2024
ff38a26
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 21, 2024
e76f6bc
Addressed additional feedback
Mar 25, 2024
72b8212
Fixed plugin tests
Mar 25, 2024
113195e
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 25, 2024
7525f01
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 26, 2024
6330a9e
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 26, 2024
79ebae9
Made initWithRegistrar the designated initializer
Mar 26, 2024
0c84f2b
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
Mar 26, 2024
c84a376
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 27, 2024
5dc7c75
Merge branch 'main' into macos-support
alexrabin-sentracam Mar 29, 2024
c33ed13
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 1, 2024
186d89c
Updated messaging
Apr 1, 2024
f9e11db
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 4, 2024
c45084b
Remove gotosettingsbutton on macos and didn't make it required
Apr 4, 2024
7003142
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 9, 2024
18453dc
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 11, 2024
fc14107
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 18, 2024
5840a73
Merge branch 'flutter:main' into macos-support
alexrabin-sentracam Apr 22, 2024
ce1fa37
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 24, 2024
ad83e24
Adjusted format
Apr 24, 2024
8beb6dd
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 24, 2024
067a0c0
Added initWithContextFactoryAndRegistrar since tests failing due to m…
Apr 24, 2024
e3e89d4
Fixed mock test error
Apr 24, 2024
a9167cc
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 25, 2024
0f56ad6
Created base StubAlertFactory
Apr 25, 2024
17bd1c7
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
Apr 25, 2024
2441440
Added test to check if the alert window is using the registrar window
Apr 25, 2024
8af7ec7
Added overridemacosmessages
Apr 25, 2024
4fcbc5d
Removes default false for overrideUseMacOSAuthMessages
Apr 25, 2024
8bd0531
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 26, 2024
44e5ae3
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
51b3b02
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
6d0684f
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
ca5789f
Merge branch 'main' into macos-support
alexrabin-sentracam Apr 29, 2024
6d5a0c6
Merge branch 'main' into macos-support
alexrabin-sentracam May 7, 2024
11e6991
Merge branch 'main' into macos-support
alexrabin-sentracam May 8, 2024
316bb68
Updated method names
May 8, 2024
3728490
Fixed comment format
May 8, 2024
5b72aea
Fixed macos tests
May 8, 2024
6dd9092
Merge branch 'main' into macos-support
alexrabin-sentracam May 8, 2024
b5ea028
Merge branch 'main' into macos-support
alexrabin-sentracam May 9, 2024
dd545e5
Merge branch 'main' of https://github.com/flutter/packages into macos…
May 15, 2024
85678af
Upgraded version to 1.4.0
May 15, 2024
679854a
Removed copy property
May 15, 2024
464ae48
Checks parent window correctly and uses nsa;ert object
May 15, 2024
05bc529
Merge branch 'main' into macos-support
alexrabin-sentracam May 16, 2024
d3ce499
Merge branch 'main' into macos-support
alexrabin-sentracam May 20, 2024
57c50d3
Added nonnulll keyword
May 20, 2024
860d198
Updated format
May 20, 2024
9224412
Added nonnull
May 20, 2024
9c345f9
Added non null to create alert
May 20, 2024
71a2824
Merge branch 'main' into macos-support
alexrabin-sentracam May 20, 2024
0d420c5
Updated elif check
May 20, 2024
3415984
Merge branch 'macos-support' of https://github.com/alexrabin-sentraca…
May 20, 2024
09236d6
Added target conditionals import
May 20, 2024
b0de86c
Added declaration comments
May 20, 2024
288b04b
Merge branch 'main' into macos-support
alexrabin-sentracam May 21, 2024
23305d0
Merge remote-tracking branch 'upstream/main' into macos-support
May 29, 2024
2293ff6
Merge branch 'main' into macos-support
alexrabin-sentracam May 29, 2024
46ce252
Merge branch 'main' into macos-support
alexrabin-sentracam May 29, 2024
0f7dac8
Merge branch 'main' into macos-support
alexrabin-sentracam May 29, 2024
a91e4e9
Fixed swift tests
May 30, 2024
e5c9b97
Merge branch 'main' into macos-support
alexrabin-sentracam May 30, 2024
f90387f
Merge branch 'main' into macos-support
alexrabin-sentracam May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/local_auth/local_auth_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
## 2.0.0

- Adds MacOS Support. Requires MacOS 10.15 or higher
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved

## 1.2.2

* Adds compatibility with `intl` 0.19.0.
- Adds compatibility with `intl` 0.19.0.
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved

## 1.2.1

* Renames the Objective-C plugin classes to avoid runtime conflicts with
- Renames the Objective-C plugin classes to avoid runtime conflicts with
`local_auth_ios` in apps that have transitive dependencies on both.

## 1.2.0

* Renames the package previously published as [`local_auth_ios`](https://pub.dev/packages/local_auth_ios)
- Renames the package previously published as [`local_auth_ios`](https://pub.dev/packages/local_auth_ios)
2 changes: 1 addition & 1 deletion packages/local_auth/local_auth_darwin/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# local_auth_darwin

The iOS implementation of [`local_auth`][1].
The iOS and MacOS implementation of [`local_auth`][1].
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if TARGET_OS_OSX
#import <FlutterMacOS/FlutterMacOS.h>
#else
#import <Flutter/Flutter.h>
#endif

#import "messages.g.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ - (void)showAlertWithMessage:(NSString *)message
dismissButtonTitle:(NSString *)dismissButtonTitle
openSettingsButtonTitle:(NSString *)openSettingsButtonTitle
completion:(FLADAuthCompletion)completion {
#if TARGET_OS_OSX
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:message];
[alert addButtonWithTitle:dismissButtonTitle];
if (openSettingsButtonTitle != nil) {
[alert addButtonWithTitle:openSettingsButtonTitle];
}
[alert beginSheetModalForWindow:NSApp.keyWindow
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
completionHandler:^(NSModalResponse returnCode) {
if (returnCode == NSAlertSecondButtonReturn) {
NSURL *url = [NSURL URLWithString:@"x-apple.systempreferences:com.apple."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've marked this as resolved, but I don't see a code comment in the current version, as requested by the linked review.

More importantly though, what the link you provided appears to be describing is a reverse-engineered system that uses private keys and has a proven track record of fragility to OS updates. That means that:

  • there's no guarantee that Apple would consider this app-store compliant, and
  • it is very likely to break without warning in the future, leaving a button that doesn't actually work.

Am I misunderstanding the discussion there? If not, then this needs a different solution for macOS that is more robust even if it's not as featureful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest then in order to open the settings app? Here is another source with all the url schemes for settings: https://www.mbsplugins.de/archive/2020-04-05/MacOS_System_Preference_Links

@"preference.security?Privacy_Biometry"];
[[NSWorkspace sharedWorkspace] openURL:url];
}
[self handleSucceeded:NO withCompletion:completion];
}];
return;
#endif

#if TARGET_OS_IOS
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
UIAlertController *alert =
[UIAlertController alertControllerWithTitle:@""
message:message
Expand Down Expand Up @@ -182,6 +202,8 @@ - (void)showAlertWithMessage:(NSString *)message
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:alert
animated:YES
completion:nil];

#endif
}

- (void)handleAuthReplyWithSuccess:(BOOL)success
Expand Down Expand Up @@ -257,12 +279,14 @@ - (void)handleError:(NSError *)authError

#pragma mark - AppDelegate

#if TARGET_OS_IOS
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (self.lastCallState != nil) {
[self authenticateWithOptions:_lastCallState.options
strings:_lastCallState.strings
completion:_lastCallState.resultHandler];
}
}
#endif

@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if TARGET_OS_OSX
#import <FlutterMacOS/FlutterMacOS.h>
#else
#import <Flutter/Flutter.h>
#endif

#import <LocalAuthentication/LocalAuthentication.h>

/// Protocol for a source of LAContext instances. Used to allow context injection in unit tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ Downloaded by pub (not CocoaPods).
s.documentation_url = 'https://pub.dev/packages/local_auth_darwin'
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.ios.dependency 'Flutter'
s.osx.dependency 'FlutterMacOS'
s.platform = :ios, '12.0'
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
s.osx.deployment_target = '10.15'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.resource_bundles = {'local_auth_darwin_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
end
Expand Down
43 changes: 43 additions & 0 deletions packages/local_auth/local_auth_darwin/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# 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
.pub-cache/
.pub/
/build/

# 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
30 changes: 30 additions & 0 deletions packages/local_auth/local_auth_darwin/example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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: "41456452f29d64e8deb623a3c927524bcf9f111b"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
- platform: macos
create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1510;
LastUpgradeCheck = 1430;
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
ORGANIZATIONNAME = "The Flutter Authors";
TargetAttributes = {
3398D2CC26163948005A052F = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1510"
LastUpgradeVersion = "1430"
alexrabin-sentracam marked this conversation as resolved.
Show resolved Hide resolved
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions packages/local_auth/local_auth_darwin/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _MyAppState extends State<MyApp> {
});
authenticated = await LocalAuthPlatform.instance.authenticate(
localizedReason: 'Let OS determine authentication method',
authMessages: <AuthMessages>[const IOSAuthMessages()],
authMessages: <AuthMessages>[const DarwinAuthMessages()],
options: const AuthenticationOptions(
stickyAuth: true,
),
Expand Down Expand Up @@ -118,7 +118,7 @@ class _MyAppState extends State<MyApp> {
authenticated = await LocalAuthPlatform.instance.authenticate(
localizedReason:
'Scan your fingerprint (or face or whatever) to authenticate',
authMessages: <AuthMessages>[const IOSAuthMessages()],
authMessages: <AuthMessages>[const DarwinAuthMessages()],
options: const AuthenticationOptions(
stickyAuth: true,
biometricOnly: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Flutter-related
**/Flutter/ephemeral/
**/Pods/

# Xcode-related
**/dgph
**/xcuserdata/
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
43 changes: 43 additions & 0 deletions packages/local_auth/local_auth_darwin/example/macos/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
platform :osx, '10.15'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_macos_build_settings(target)
end
end