Skip to content

[local_auth] Rename iOS classes #6108

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

Merged
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
5 changes: 5 additions & 0 deletions packages/local_auth/local_auth_darwin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.2.1

* 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)
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

#import "messages.g.h"

@interface FLTLocalAuthPlugin : NSObject <FlutterPlugin, FLALocalAuthApi>
@interface FLALocalAuthPlugin : NSObject <FlutterPlugin, FLADLocalAuthApi>
@end
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// 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 "FLTLocalAuthPlugin.h"
#import "FLTLocalAuthPlugin_Test.h"
#import "FLALocalAuthPlugin.h"
#import "FLALocalAuthPlugin_Test.h"

#import <LocalAuthentication/LocalAuthentication.h>

typedef void (^FLAAuthCompletion)(FLAAuthResultDetails *_Nullable, FlutterError *_Nullable);
typedef void (^FLADAuthCompletion)(FLADAuthResultDetails *_Nullable, FlutterError *_Nullable);

/**
* A default context factory that wraps standard LAContext allocation.
*/
@interface FLADefaultAuthContextFactory : NSObject <FLAAuthContextFactory>
@interface FLADefaultAuthContextFactory : NSObject <FLADAuthContextFactory>
@end

@implementation FLADefaultAuthContextFactory
Expand All @@ -26,18 +26,18 @@ - (LAContext *)createAuthContext {
* A data container for sticky auth state.
*/
@interface FLAStickyAuthState : NSObject
@property(nonatomic, strong, nonnull) FLAAuthOptions *options;
@property(nonatomic, strong, nonnull) FLAAuthStrings *strings;
@property(nonatomic, copy, nonnull) FLAAuthCompletion resultHandler;
- (instancetype)initWithOptions:(nonnull FLAAuthOptions *)options
strings:(nonnull FLAAuthStrings *)strings
resultHandler:(nonnull FLAAuthCompletion)resultHandler;
@property(nonatomic, strong, nonnull) FLADAuthOptions *options;
@property(nonatomic, strong, nonnull) FLADAuthStrings *strings;
@property(nonatomic, copy, nonnull) FLADAuthCompletion resultHandler;
- (instancetype)initWithOptions:(nonnull FLADAuthOptions *)options
strings:(nonnull FLADAuthStrings *)strings
resultHandler:(nonnull FLADAuthCompletion)resultHandler;
@end

@implementation FLAStickyAuthState
- (instancetype)initWithOptions:(nonnull FLAAuthOptions *)options
strings:(nonnull FLAAuthStrings *)strings
resultHandler:(nonnull FLAAuthCompletion)resultHandler {
- (instancetype)initWithOptions:(nonnull FLADAuthOptions *)options
strings:(nonnull FLADAuthStrings *)strings
resultHandler:(nonnull FLADAuthCompletion)resultHandler {
self = [super init];
if (self) {
_options = options;
Expand All @@ -50,36 +50,36 @@ - (instancetype)initWithOptions:(nonnull FLAAuthOptions *)options

#pragma mark -

@interface FLTLocalAuthPlugin ()
@interface FLALocalAuthPlugin ()
@property(nonatomic, strong, nullable) FLAStickyAuthState *lastCallState;
@property(nonatomic, strong) NSObject<FLAAuthContextFactory> *authContextFactory;
@property(nonatomic, strong) NSObject<FLADAuthContextFactory> *authContextFactory;
@end

@implementation FLTLocalAuthPlugin
@implementation FLALocalAuthPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FLTLocalAuthPlugin *instance = [[FLTLocalAuthPlugin alloc] init];
FLALocalAuthPlugin *instance = [[FLALocalAuthPlugin alloc] init];
[registrar addApplicationDelegate:instance];
SetUpFLALocalAuthApi([registrar messenger], instance);
SetUpFLADLocalAuthApi([registrar messenger], instance);
}

- (instancetype)init {
return [self initWithContextFactory:[[FLADefaultAuthContextFactory alloc] init]];
}

- (instancetype)initWithContextFactory:(NSObject<FLAAuthContextFactory> *)factory {
- (instancetype)initWithContextFactory:(NSObject<FLADAuthContextFactory> *)factory {
self = [super init];
if (self) {
_authContextFactory = factory;
}
return self;
}

#pragma mark FLALocalAuthApi
#pragma mark FLADLocalAuthApi

- (void)authenticateWithOptions:(nonnull FLAAuthOptions *)options
strings:(nonnull FLAAuthStrings *)strings
completion:(nonnull void (^)(FLAAuthResultDetails *_Nullable,
- (void)authenticateWithOptions:(nonnull FLADAuthOptions *)options
strings:(nonnull FLADAuthStrings *)strings
completion:(nonnull void (^)(FLADAuthResultDetails *_Nullable,
FlutterError *_Nullable))completion {
LAContext *context = [self.authContextFactory createAuthContext];
NSError *authError = nil;
Expand Down Expand Up @@ -126,18 +126,19 @@ - (nullable NSNumber *)deviceCanSupportBiometricsWithError:
return @NO;
}

- (nullable NSArray<FLAAuthBiometricWrapper *> *)getEnrolledBiometricsWithError:
- (nullable NSArray<FLADAuthBiometricWrapper *> *)getEnrolledBiometricsWithError:
(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
LAContext *context = [self.authContextFactory createAuthContext];
NSError *authError = nil;
NSMutableArray<FLAAuthBiometricWrapper *> *biometrics = [[NSMutableArray alloc] init];
NSMutableArray<FLADAuthBiometricWrapper *> *biometrics = [[NSMutableArray alloc] init];
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
error:&authError]) {
if (authError == nil) {
if (context.biometryType == LABiometryTypeFaceID) {
[biometrics addObject:[FLAAuthBiometricWrapper makeWithValue:FLAAuthBiometricFace]];
[biometrics addObject:[FLADAuthBiometricWrapper makeWithValue:FLADAuthBiometricFace]];
} else if (context.biometryType == LABiometryTypeTouchID) {
[biometrics addObject:[FLAAuthBiometricWrapper makeWithValue:FLAAuthBiometricFingerprint]];
[biometrics
addObject:[FLADAuthBiometricWrapper makeWithValue:FLADAuthBiometricFingerprint]];
}
}
}
Expand All @@ -155,7 +156,7 @@ - (nullable NSNumber *)isDeviceSupportedWithError:
- (void)showAlertWithMessage:(NSString *)message
dismissButtonTitle:(NSString *)dismissButtonTitle
openSettingsButtonTitle:(NSString *)openSettingsButtonTitle
completion:(FLAAuthCompletion)completion {
completion:(FLADAuthCompletion)completion {
UIAlertController *alert =
[UIAlertController alertControllerWithTitle:@""
message:message
Expand Down Expand Up @@ -189,9 +190,9 @@ - (void)showAlertWithMessage:(NSString *)message

- (void)handleAuthReplyWithSuccess:(BOOL)success
error:(NSError *)error
options:(FLAAuthOptions *)options
strings:(FLAAuthStrings *)strings
completion:(nonnull FLAAuthCompletion)completion {
options:(FLADAuthOptions *)options
strings:(FLADAuthStrings *)strings
completion:(nonnull FLADAuthCompletion)completion {
NSAssert([NSThread isMainThread], @"Response handling must be done on the main thread.");
if (success) {
[self handleSucceeded:YES withCompletion:completion];
Expand Down Expand Up @@ -219,19 +220,19 @@ - (void)handleAuthReplyWithSuccess:(BOOL)success
}
}

- (void)handleSucceeded:(BOOL)succeeded withCompletion:(nonnull FLAAuthCompletion)completion {
completion(
[FLAAuthResultDetails makeWithResult:(succeeded ? FLAAuthResultSuccess : FLAAuthResultFailure)
errorMessage:nil
errorDetails:nil],
nil);
- (void)handleSucceeded:(BOOL)succeeded withCompletion:(nonnull FLADAuthCompletion)completion {
completion([FLADAuthResultDetails
makeWithResult:(succeeded ? FLADAuthResultSuccess : FLADAuthResultFailure)
errorMessage:nil
errorDetails:nil],
nil);
}

- (void)handleError:(NSError *)authError
withOptions:(FLAAuthOptions *)options
strings:(FLAAuthStrings *)strings
completion:(nonnull FLAAuthCompletion)completion {
FLAAuthResult result = FLAAuthResultErrorNotAvailable;
withOptions:(FLADAuthOptions *)options
strings:(FLADAuthStrings *)strings
completion:(nonnull FLADAuthCompletion)completion {
FLADAuthResult result = FLADAuthResultErrorNotAvailable;
switch (authError.code) {
case LAErrorPasscodeNotSet:
case LAErrorBiometryNotEnrolled:
Expand All @@ -242,8 +243,8 @@ - (void)handleError:(NSError *)authError
completion:completion];
return;
}
result = authError.code == LAErrorPasscodeNotSet ? FLAAuthResultErrorPasscodeNotSet
: FLAAuthResultErrorNotEnrolled;
result = authError.code == LAErrorPasscodeNotSet ? FLADAuthResultErrorPasscodeNotSet
: FLADAuthResultErrorNotEnrolled;
break;
case LAErrorBiometryLockout:
[self showAlertWithMessage:strings.lockOut
Expand All @@ -252,9 +253,9 @@ - (void)handleError:(NSError *)authError
completion:completion];
return;
}
completion([FLAAuthResultDetails makeWithResult:result
errorMessage:authError.localizedDescription
errorDetails:authError.domain],
completion([FLADAuthResultDetails makeWithResult:result
errorMessage:authError.localizedDescription
errorDetails:authError.domain],
nil);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
/**
* Protocol for a source of LAContext instances. Used to allow context injection in unit tests.
*/
@protocol FLAAuthContextFactory <NSObject>
@protocol FLADAuthContextFactory <NSObject>
- (LAContext *)createAuthContext;
@end

@interface FLTLocalAuthPlugin ()
@interface FLALocalAuthPlugin ()
/**
* Returns an instance that uses the given factory to create LAContexts.
*/
- (instancetype)initWithContextFactory:(NSObject<FLAAuthContextFactory> *)factory
- (instancetype)initWithContextFactory:(NSObject<FLADAuthContextFactory> *)factory
NS_DESIGNATED_INITIALIZER;
@end
76 changes: 38 additions & 38 deletions packages/local_auth/local_auth_darwin/darwin/Classes/messages.g.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,46 @@
NS_ASSUME_NONNULL_BEGIN

/// Possible outcomes of an authentication attempt.
typedef NS_ENUM(NSUInteger, FLAAuthResult) {
typedef NS_ENUM(NSUInteger, FLADAuthResult) {
/// The user authenticated successfully.
FLAAuthResultSuccess = 0,
FLADAuthResultSuccess = 0,
/// The user failed to successfully authenticate.
FLAAuthResultFailure = 1,
FLADAuthResultFailure = 1,
/// The authentication system was not available.
FLAAuthResultErrorNotAvailable = 2,
FLADAuthResultErrorNotAvailable = 2,
/// No biometrics are enrolled.
FLAAuthResultErrorNotEnrolled = 3,
FLADAuthResultErrorNotEnrolled = 3,
/// No passcode is set.
FLAAuthResultErrorPasscodeNotSet = 4,
FLADAuthResultErrorPasscodeNotSet = 4,
};

/// Wrapper for FLAAuthResult to allow for nullability.
@interface FLAAuthResultBox : NSObject
@property(nonatomic, assign) FLAAuthResult value;
- (instancetype)initWithValue:(FLAAuthResult)value;
/// Wrapper for FLADAuthResult to allow for nullability.
@interface FLADAuthResultBox : NSObject
@property(nonatomic, assign) FLADAuthResult value;
- (instancetype)initWithValue:(FLADAuthResult)value;
@end

/// Pigeon equivalent of the subset of BiometricType used by iOS.
typedef NS_ENUM(NSUInteger, FLAAuthBiometric) {
FLAAuthBiometricFace = 0,
FLAAuthBiometricFingerprint = 1,
typedef NS_ENUM(NSUInteger, FLADAuthBiometric) {
FLADAuthBiometricFace = 0,
FLADAuthBiometricFingerprint = 1,
};

/// Wrapper for FLAAuthBiometric to allow for nullability.
@interface FLAAuthBiometricBox : NSObject
@property(nonatomic, assign) FLAAuthBiometric value;
- (instancetype)initWithValue:(FLAAuthBiometric)value;
/// Wrapper for FLADAuthBiometric to allow for nullability.
@interface FLADAuthBiometricBox : NSObject
@property(nonatomic, assign) FLADAuthBiometric value;
- (instancetype)initWithValue:(FLADAuthBiometric)value;
@end

@class FLAAuthStrings;
@class FLAAuthOptions;
@class FLAAuthResultDetails;
@class FLAAuthBiometricWrapper;
@class FLADAuthStrings;
@class FLADAuthOptions;
@class FLADAuthResultDetails;
@class FLADAuthBiometricWrapper;

/// Pigeon version of IOSAuthMessages, plus the authorization reason.
///
/// See auth_messages_ios.dart for details.
@interface FLAAuthStrings : NSObject
@interface FLADAuthStrings : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithReason:(NSString *)reason
Expand All @@ -70,7 +70,7 @@ typedef NS_ENUM(NSUInteger, FLAAuthBiometric) {
@property(nonatomic, copy, nullable) NSString *localizedFallbackTitle;
@end

@interface FLAAuthOptions : NSObject
@interface FLADAuthOptions : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithBiometricOnly:(BOOL)biometricOnly
Expand All @@ -81,31 +81,31 @@ typedef NS_ENUM(NSUInteger, FLAAuthBiometric) {
@property(nonatomic, assign) BOOL useErrorDialogs;
@end

@interface FLAAuthResultDetails : NSObject
@interface FLADAuthResultDetails : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithResult:(FLAAuthResult)result
+ (instancetype)makeWithResult:(FLADAuthResult)result
errorMessage:(nullable NSString *)errorMessage
errorDetails:(nullable NSString *)errorDetails;
/// The result of authenticating.
@property(nonatomic, assign) FLAAuthResult result;
@property(nonatomic, assign) FLADAuthResult result;
/// A system-provided error message, if any.
@property(nonatomic, copy, nullable) NSString *errorMessage;
/// System-provided error details, if any.
@property(nonatomic, copy, nullable) NSString *errorDetails;
@end

@interface FLAAuthBiometricWrapper : NSObject
@interface FLADAuthBiometricWrapper : NSObject
/// `init` unavailable to enforce nonnull fields, see the `make` class method.
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)makeWithValue:(FLAAuthBiometric)value;
@property(nonatomic, assign) FLAAuthBiometric value;
+ (instancetype)makeWithValue:(FLADAuthBiometric)value;
@property(nonatomic, assign) FLADAuthBiometric value;
@end

/// The codec used by FLALocalAuthApi.
NSObject<FlutterMessageCodec> *FLALocalAuthApiGetCodec(void);
/// The codec used by FLADLocalAuthApi.
NSObject<FlutterMessageCodec> *FLADLocalAuthApiGetCodec(void);

@protocol FLALocalAuthApi
@protocol FLADLocalAuthApi
/// Returns true if this device supports authentication.
///
/// @return `nil` only when `error != nil`.
Expand All @@ -119,17 +119,17 @@ NSObject<FlutterMessageCodec> *FLALocalAuthApiGetCodec(void);
/// without additional setup.
///
/// @return `nil` only when `error != nil`.
- (nullable NSArray<FLAAuthBiometricWrapper *> *)getEnrolledBiometricsWithError:
- (nullable NSArray<FLADAuthBiometricWrapper *> *)getEnrolledBiometricsWithError:
(FlutterError *_Nullable *_Nonnull)error;
/// Attempts to authenticate the user with the provided [options], and using
/// [strings] for any UI.
- (void)authenticateWithOptions:(FLAAuthOptions *)options
strings:(FLAAuthStrings *)strings
completion:(void (^)(FLAAuthResultDetails *_Nullable,
- (void)authenticateWithOptions:(FLADAuthOptions *)options
strings:(FLADAuthStrings *)strings
completion:(void (^)(FLADAuthResultDetails *_Nullable,
FlutterError *_Nullable))completion;
@end

extern void SetUpFLALocalAuthApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FLALocalAuthApi> *_Nullable api);
extern void SetUpFLADLocalAuthApi(id<FlutterBinaryMessenger> binaryMessenger,
NSObject<FLADLocalAuthApi> *_Nullable api);

NS_ASSUME_NONNULL_END
Loading