Skip to content
Closed
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
4 changes: 4 additions & 0 deletions packages/local_auth/local_auth_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ @interface FLALocalAuthPlugin ()

/// The Flutter view provider.
@property(nonatomic, strong) NSObject<FLAViewProvider> *viewProvider;

/// The auth context to cancel.
@property(nonatomic, strong, nullable) LAContext *currentContext;
@end

@implementation FLALocalAuthPlugin
Expand Down Expand Up @@ -278,6 +281,7 @@ - (void)authenticateWithOptions:(nonnull FLADAuthOptions *)options
completion:(nonnull void (^)(FLADAuthResultDetails *_Nullable,
FlutterError *_Nullable))completion {
id<FLADAuthContext> context = [self.authContextFactory createAuthContext];
self.currentContext = context;
NSError *authError = nil;
self.lastCallState = nil;
context.localizedFallbackTitle = strings.localizedFallbackTitle;
Expand Down Expand Up @@ -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<FLADAuthContext> context = [self.authContextFactory createAuthContext];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ NSObject<FlutterMessageCodec> *FLADGetMessagesCodec(void);
/// @return `nil` only when `error != nil`.
- (nullable NSArray<FLADAuthBiometricBox *> *)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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -329,6 +329,32 @@ void SetUpFLADLocalAuthApiWithSuffix(id<FlutterBinaryMessenger> 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.
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ class LocalAuthDarwin extends LocalAuthPlatform {
@override
Future<bool> isDeviceSupported() async => _api.isDeviceSupported();

/// Always returns false as this method is not supported on iOS or macOS.
@override
Future<bool> stopAuthentication() async => false;
Future<bool> stopAuthentication() async => _api.stopAuthentication();

AuthStrings _pigeonStringsFromiOSAuthMessages(
String localizedReason, Iterable<AuthMessages> messagesList) {
Expand Down
35 changes: 34 additions & 1 deletion packages/local_auth/local_auth_darwin/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -311,6 +311,39 @@ class LocalAuthApi {
}
}

/// Cancels any in-progress authentication.
///
/// Returns true only if authentication was in progress, and was successfully
/// cancelled.
Future<bool> stopAuthentication() async {
final String pigeonVar_channelName =
'dev.flutter.pigeon.local_auth_darwin.LocalAuthApi.stopAuthentication$pigeonVar_messageChannelSuffix';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_channel.send(null) as List<Object?>?;
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<AuthResultDetails> authenticate(
Expand Down
6 changes: 6 additions & 0 deletions packages/local_auth/local_auth_darwin/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ abstract class LocalAuthApi {
/// without additional setup.
List<AuthBiometric> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down