Skip to content

Commit d69b4a1

Browse files
committed
feat(auth): TOTP support for macOS
1 parent 08ecc50 commit d69b4a1

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/FLTFirebaseAuthPlugin.m

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ @interface FLTFirebaseAuthPlugin ()
101101
@end
102102

103103
@implementation FLTFirebaseAuthPlugin {
104-
#if TARGET_OS_IPHONE
105104
// Map an id to a MultiFactorSession object.
106105
NSMutableDictionary<NSString *, FIRMultiFactorSession *> *_multiFactorSessionMap;
107106

@@ -114,8 +113,6 @@ @implementation FLTFirebaseAuthPlugin {
114113
// Map an id to a MultiFactorResolver object.
115114
NSMutableDictionary<NSString *, FIRTOTPSecret *> *_multiFactorTotpSecretMap;
116115

117-
#endif
118-
119116
NSObject<FlutterBinaryMessenger> *_binaryMessenger;
120117
NSMutableDictionary<NSString *, FlutterEventChannel *> *_eventChannels;
121118
NSMutableDictionary<NSString *, NSObject<FlutterStreamHandler> *> *_streamHandlers;
@@ -133,13 +130,10 @@ - (instancetype)init:(NSObject<FlutterBinaryMessenger> *)messenger {
133130
_eventChannels = [NSMutableDictionary dictionary];
134131
_streamHandlers = [NSMutableDictionary dictionary];
135132

136-
#if TARGET_OS_IPHONE
137133
_multiFactorSessionMap = [NSMutableDictionary dictionary];
138134
_multiFactorResolverMap = [NSMutableDictionary dictionary];
139135
_multiFactorAssertionMap = [NSMutableDictionary dictionary];
140136
_multiFactorTotpSecretMap = [NSMutableDictionary dictionary];
141-
142-
#endif
143137
}
144138
return self;
145139
}
@@ -164,11 +158,11 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
164158
[registrar addApplicationDelegate:instance];
165159
SetUpFirebaseAuthHostApi(registrar.messenger, instance);
166160
SetUpFirebaseAuthUserHostApi(registrar.messenger, instance);
161+
#endif
167162
SetUpMultiFactorUserHostApi(registrar.messenger, instance);
168163
SetUpMultiFactoResolverHostApi(registrar.messenger, instance);
169164
SetUpMultiFactorTotpHostApi(registrar.messenger, instance);
170165
SetUpMultiFactorTotpSecretHostApi(registrar.messenger, instance);
171-
#endif
172166
}
173167

174168
+ (FlutterError *)convertToFlutterError:(NSError *)error {
@@ -841,13 +835,11 @@ - (void)ensureAPNSTokenSetting {
841835
#endif
842836
}
843837

844-
#if !TARGET_OS_OSX
845838
- (FIRMultiFactor *)getAppMultiFactorFromPigeon:(nonnull AuthPigeonFirebaseApp *)app {
846839
FIRAuth *auth = [self getFIRAuthFromAppNameFromPigeon:app];
847840
FIRUser *currentUser = auth.currentUser;
848841
return currentUser.multiFactor;
849842
}
850-
#endif
851843

852844
- (nonnull ASPresentationAnchor)presentationAnchorForAuthorizationController:
853845
(nonnull ASAuthorizationController *)controller API_AVAILABLE(macos(10.15), ios(13.0)) {
@@ -887,6 +879,8 @@ - (void)enrollPhoneApp:(nonnull AuthPigeonFirebaseApp *)app
887879
}];
888880
}
889881

882+
#endif
883+
890884
- (void)getEnrolledFactorsApp:(nonnull AuthPigeonFirebaseApp *)app
891885
completion:(nonnull void (^)(NSArray<PigeonMultiFactorInfo *> *_Nullable,
892886
FlutterError *_Nullable))completion {
@@ -965,6 +959,8 @@ - (void)enrollTotpApp:(nonnull AuthPigeonFirebaseApp *)app
965959
}];
966960
}
967961

962+
#if TARGET_OS_IPHONE
963+
968964
- (void)resolveSignInResolverId:(nonnull NSString *)resolverId
969965
assertion:(nullable PigeonPhoneMultiFactorAssertion *)assertion
970966
totpAssertionId:(nullable NSString *)totpAssertionId
@@ -1005,6 +1001,8 @@ - (void)resolveSignInResolverId:(nonnull NSString *)resolverId
10051001
}];
10061002
}
10071003

1004+
#endif
1005+
10081006
- (void)generateSecretSessionId:(nonnull NSString *)sessionId
10091007
completion:(nonnull void (^)(PigeonTotpSecret *_Nullable,
10101008
FlutterError *_Nullable))completion {
@@ -1071,8 +1069,6 @@ - (void)openInOtpAppSecretKey:(nonnull NSString *)secretKey
10711069
completion(nil);
10721070
}
10731071

1074-
#endif
1075-
10761072
- (void)applyActionCodeApp:(nonnull AuthPigeonFirebaseApp *)app
10771073
code:(nonnull NSString *)code
10781074
completion:(nonnull void (^)(FlutterError *_Nullable))completion {

packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/PigeonParser.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,13 @@ + (PigeonAdditionalUserInfo *)getPigeonAdditionalUserInfo:(nonnull FIRAdditional
8282
profile:userInfo.profile];
8383
}
8484

85-
#if TARGET_OS_IPHONE
8685
+ (PigeonTotpSecret *)getPigeonTotpSecret:(FIRTOTPSecret *)secret {
8786
return [PigeonTotpSecret makeWithCodeIntervalSeconds:nil
8887
codeLength:nil
8988
enrollmentCompletionDeadline:nil
9089
hashingAlgorithm:nil
9190
secretKey:secret.sharedSecretKey];
9291
}
93-
#endif
9492

9593
+ (PigeonAuthCredential *)getPigeonAuthCredential:(FIRAuthCredential *)authCredential
9694
token:(NSNumber *_Nullable)token {

packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/include/Private/PigeonParser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
(nullable PigeonActionCodeSettings *)settings;
2626
+ (PigeonUserCredential *_Nullable)getPigeonUserCredentialFromFIRUser:(nonnull FIRUser *)user;
2727
+ (PigeonIdTokenResult *_Nonnull)parseIdTokenResult:(nonnull FIRAuthTokenResult *)tokenResult;
28-
#if TARGET_OS_IPHONE
2928
+ (PigeonTotpSecret *_Nonnull)getPigeonTotpSecret:(nonnull FIRTOTPSecret *)secret;
30-
#endif
3129
+ (PigeonAuthCredential *_Nullable)getPigeonAuthCredential:
3230
(FIRAuthCredential *_Nullable)authCredentialToken
3331
token:(NSNumber *_Nullable)token;

0 commit comments

Comments
 (0)