diff --git a/packages/local_auth/local_auth_darwin/CHANGELOG.md b/packages/local_auth/local_auth_darwin/CHANGELOG.md index 78c17dbc4c9..77a7294ce3c 100644 --- a/packages/local_auth/local_auth_darwin/CHANGELOG.md +++ b/packages/local_auth/local_auth_darwin/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.4.4 + +* Add `stopAuthentication` implementation. + ## 1.4.3 * Handles when biometry hardware is available but permissions have been denied for the app. diff --git a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/FLALocalAuthPlugin.m b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/FLALocalAuthPlugin.m index 33bd25df70e..b1c498213b1 100644 --- a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/FLALocalAuthPlugin.m +++ b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/FLALocalAuthPlugin.m @@ -242,6 +242,9 @@ @interface FLALocalAuthPlugin () /// The Flutter view provider. @property(nonatomic, strong) NSObject *viewProvider; + +/// The auth context to cancel. +@property(nonatomic, strong, nullable) LAContext *currentContext; @end @implementation FLALocalAuthPlugin @@ -278,6 +281,7 @@ - (void)authenticateWithOptions:(nonnull FLADAuthOptions *)options completion:(nonnull void (^)(FLADAuthResultDetails *_Nullable, FlutterError *_Nullable))completion { id context = [self.authContextFactory createAuthContext]; + self.currentContext = context; NSError *authError = nil; self.lastCallState = nil; context.localizedFallbackTitle = strings.localizedFallbackTitle; @@ -350,6 +354,16 @@ - (nullable NSNumber *)deviceCanSupportBiometricsWithError: return biometrics; } +- (nullable NSNumber *)stopAuthenticationWithError: + (FlutterError *_Nullable __autoreleasing *_Nonnull)error { + if (self.currentContext == NULL) { + return @NO; + } + [self.currentContext invalidate]; + + return @YES; +} + - (nullable NSNumber *)isDeviceSupportedWithError: (FlutterError *_Nullable __autoreleasing *_Nonnull)error { id context = [self.authContextFactory createAuthContext]; diff --git a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/include/local_auth_darwin/messages.g.h b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/include/local_auth_darwin/messages.g.h index 3e64f6e9e0a..ee6e32e7f43 100644 --- a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/include/local_auth_darwin/messages.g.h +++ b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/include/local_auth_darwin/messages.g.h @@ -113,6 +113,13 @@ NSObject *FLADGetMessagesCodec(void); /// @return `nil` only when `error != nil`. - (nullable NSArray *)getEnrolledBiometricsWithError: (FlutterError *_Nullable *_Nonnull)error; +/// Cancels any in-progress authentication. +/// +/// Returns true only if authentication was in progress, and was successfully +/// cancelled. +/// +/// @return `nil` only when `error != nil`. +- (nullable NSNumber *)stopAuthenticationWithError:(FlutterError *_Nullable *_Nonnull)error; /// Attempts to authenticate the user with the provided [options], and using /// [strings] for any UI. - (void)authenticateWithOptions:(FLADAuthOptions *)options diff --git a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/messages.g.m b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/messages.g.m index b43fcf138b7..c9c939280fb 100644 --- a/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/messages.g.m +++ b/packages/local_auth/local_auth_darwin/darwin/local_auth_darwin/Sources/local_auth_darwin/messages.g.m @@ -1,7 +1,7 @@ // 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. -// Autogenerated from Pigeon (v22.4.0), do not edit directly. +// Autogenerated from Pigeon (v22.7.2), do not edit directly. // See also: https://pub.dev/packages/pigeon #import "./include/local_auth_darwin/messages.g.h" @@ -329,6 +329,32 @@ void SetUpFLADLocalAuthApiWithSuffix(id binaryMessenger, [channel setMessageHandler:nil]; } } + /// Cancels any in-progress authentication. + /// + /// Returns true only if authentication was in progress, and was successfully + /// cancelled. + { + FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc] + initWithName:[NSString stringWithFormat:@"%@%@", + @"dev.flutter.pigeon.local_auth_darwin." + @"LocalAuthApi.stopAuthentication", + messageChannelSuffix] + binaryMessenger:binaryMessenger + codec:FLADGetMessagesCodec()]; + if (api) { + NSCAssert( + [api respondsToSelector:@selector(stopAuthenticationWithError:)], + @"FLADLocalAuthApi api (%@) doesn't respond to @selector(stopAuthenticationWithError:)", + api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + NSNumber *output = [api stopAuthenticationWithError:&error]; + callback(wrapResult(output, error)); + }]; + } else { + [channel setMessageHandler:nil]; + } + } /// Attempts to authenticate the user with the provided [options], and using /// [strings] for any UI. { diff --git a/packages/local_auth/local_auth_darwin/lib/local_auth_darwin.dart b/packages/local_auth/local_auth_darwin/lib/local_auth_darwin.dart index 935d274efa6..53339e9f5ba 100644 --- a/packages/local_auth/local_auth_darwin/lib/local_auth_darwin.dart +++ b/packages/local_auth/local_auth_darwin/lib/local_auth_darwin.dart @@ -99,9 +99,8 @@ class LocalAuthDarwin extends LocalAuthPlatform { @override Future isDeviceSupported() async => _api.isDeviceSupported(); - /// Always returns false as this method is not supported on iOS or macOS. @override - Future stopAuthentication() async => false; + Future stopAuthentication() async => _api.stopAuthentication(); AuthStrings _pigeonStringsFromiOSAuthMessages( String localizedReason, Iterable messagesList) { diff --git a/packages/local_auth/local_auth_darwin/lib/src/messages.g.dart b/packages/local_auth/local_auth_darwin/lib/src/messages.g.dart index 51b921c1540..f08af4a82ee 100644 --- a/packages/local_auth/local_auth_darwin/lib/src/messages.g.dart +++ b/packages/local_auth/local_auth_darwin/lib/src/messages.g.dart @@ -1,7 +1,7 @@ // 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. -// Autogenerated from Pigeon (v22.4.0), do not edit directly. +// Autogenerated from Pigeon (v22.7.2), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers @@ -311,6 +311,39 @@ class LocalAuthApi { } } + /// Cancels any in-progress authentication. + /// + /// Returns true only if authentication was in progress, and was successfully + /// cancelled. + Future stopAuthentication() async { + final String pigeonVar_channelName = + 'dev.flutter.pigeon.local_auth_darwin.LocalAuthApi.stopAuthentication$pigeonVar_messageChannelSuffix'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; + } + } + /// Attempts to authenticate the user with the provided [options], and using /// [strings] for any UI. Future authenticate( diff --git a/packages/local_auth/local_auth_darwin/pigeons/messages.dart b/packages/local_auth/local_auth_darwin/pigeons/messages.dart index 17aad093a06..808a480f99f 100644 --- a/packages/local_auth/local_auth_darwin/pigeons/messages.dart +++ b/packages/local_auth/local_auth_darwin/pigeons/messages.dart @@ -101,6 +101,12 @@ abstract class LocalAuthApi { /// without additional setup. List getEnrolledBiometrics(); + /// Cancels any in-progress authentication. + /// + /// Returns true only if authentication was in progress, and was successfully + /// cancelled. + bool stopAuthentication(); + /// Attempts to authenticate the user with the provided [options], and using /// [strings] for any UI. @async diff --git a/packages/local_auth/local_auth_darwin/test/local_auth_darwin_test.dart b/packages/local_auth/local_auth_darwin/test/local_auth_darwin_test.dart index 756205f1b68..1e96991490d 100644 --- a/packages/local_auth/local_auth_darwin/test/local_auth_darwin_test.dart +++ b/packages/local_auth/local_auth_darwin/test/local_auth_darwin_test.dart @@ -53,7 +53,13 @@ void main() { }); group('stopAuthentication', () { - test('always returns false', () async { + test('handles true', () async { + when(api.stopAuthentication()).thenAnswer((_) async => true); + expect(await plugin.stopAuthentication(), true); + }); + + test('handles false', () async { + when(api.stopAuthentication()).thenAnswer((_) async => false); expect(await plugin.stopAuthentication(), false); }); });