Skip to content

Commit c9661f0

Browse files
SelaseKaycbenhagen
authored andcommitted
feat(remote_config): add support for Pigeon. Update iOS to Swift and Android to Swift (#17489)
* feat(remote_config): add support for Pigeon. Update iOS to Swift and Android to Swift * chore: migrate ios implementation to Swift * chore: add license header to FirebaseRemoteConfigUtils.swift * chore: reference `binaryMessenger` * chore: fix ci * chore: remove uncecessary log
1 parent 6068edf commit c9661f0

File tree

38 files changed

+2677
-896
lines changed

38 files changed

+2677
-896
lines changed

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

Lines changed: 10 additions & 19 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 {
@@ -515,11 +509,6 @@ - (void)handleMultiFactorError:(AuthPigeonFirebaseApp *)app
515509
completion:(nonnull void (^)(PigeonUserCredential *_Nullable,
516510
FlutterError *_Nullable))completion
517511
withError:(NSError *_Nullable)error {
518-
#if TARGET_OS_OSX
519-
completion(nil, [FlutterError errorWithCode:@"second-factor-required"
520-
message:error.description
521-
details:nil]);
522-
#else
523512
FIRMultiFactorResolver *resolver =
524513
(FIRMultiFactorResolver *)error.userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey];
525514

@@ -560,7 +549,6 @@ - (void)handleMultiFactorError:(AuthPigeonFirebaseApp *)app
560549
completion(nil, [FlutterError errorWithCode:@"second-factor-required"
561550
message:error.description
562551
details:output]);
563-
#endif
564552
}
565553

566554
static void launchAppleSignInRequest(FLTFirebaseAuthPlugin *object, AuthPigeonFirebaseApp *app,
@@ -841,13 +829,11 @@ - (void)ensureAPNSTokenSetting {
841829
#endif
842830
}
843831

844-
#if !TARGET_OS_OSX
845832
- (FIRMultiFactor *)getAppMultiFactorFromPigeon:(nonnull AuthPigeonFirebaseApp *)app {
846833
FIRAuth *auth = [self getFIRAuthFromAppNameFromPigeon:app];
847834
FIRUser *currentUser = auth.currentUser;
848835
return currentUser.multiFactor;
849836
}
850-
#endif
851837

852838
- (nonnull ASPresentationAnchor)presentationAnchorForAuthorizationController:
853839
(nonnull ASAuthorizationController *)controller API_AVAILABLE(macos(10.15), ios(13.0)) {
@@ -858,12 +844,16 @@ - (nonnull ASPresentationAnchor)presentationAnchorForAuthorizationController:
858844
#endif
859845
}
860846

861-
#if TARGET_OS_IPHONE
862-
863847
- (void)enrollPhoneApp:(nonnull AuthPigeonFirebaseApp *)app
864848
assertion:(nonnull PigeonPhoneMultiFactorAssertion *)assertion
865849
displayName:(nullable NSString *)displayName
866850
completion:(nonnull void (^)(FlutterError *_Nullable))completion {
851+
#if TARGET_OS_OSX
852+
completion([FlutterError errorWithCode:@"unsupported-platform"
853+
message:@"Phone authentication is not supported on macOS"
854+
details:nil]);
855+
#else
856+
867857
FIRMultiFactor *multiFactor = [self getAppMultiFactorFromPigeon:app];
868858

869859
FIRPhoneAuthCredential *credential =
@@ -885,6 +875,7 @@ - (void)enrollPhoneApp:(nonnull AuthPigeonFirebaseApp *)app
885875
details:nil]);
886876
}
887877
}];
878+
#endif
888879
}
889880

890881
- (void)getEnrolledFactorsApp:(nonnull AuthPigeonFirebaseApp *)app
@@ -975,10 +966,12 @@ - (void)resolveSignInResolverId:(nonnull NSString *)resolverId
975966
FIRMultiFactorAssertion *multiFactorAssertion;
976967

977968
if (assertion != nil) {
969+
#if TARGET_OS_IPHONE
978970
FIRPhoneAuthCredential *credential =
979971
[[FIRPhoneAuthProvider provider] credentialWithVerificationID:[assertion verificationId]
980972
verificationCode:[assertion verificationCode]];
981973
multiFactorAssertion = [FIRPhoneMultiFactorGenerator assertionWithCredential:credential];
974+
#endif
982975
} else if (totpAssertionId != nil) {
983976
multiFactorAssertion = _multiFactorAssertionMap[totpAssertionId];
984977
} else {
@@ -1071,8 +1064,6 @@ - (void)openInOtpAppSecretKey:(nonnull NSString *)secretKey
10711064
completion(nil);
10721065
}
10731066

1074-
#endif
1075-
10761067
- (void)applyActionCodeApp:(nonnull AuthPigeonFirebaseApp *)app
10771068
code:(nonnull NSString *)code
10781069
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;

packages/firebase_auth/firebase_auth/lib/src/user.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,11 +673,9 @@ class User {
673673
}
674674

675675
MultiFactor get multiFactor {
676-
if (!kIsWeb &&
677-
(defaultTargetPlatform == TargetPlatform.macOS ||
678-
defaultTargetPlatform == TargetPlatform.windows)) {
676+
if (!kIsWeb && (defaultTargetPlatform == TargetPlatform.windows)) {
679677
throw UnimplementedError(
680-
'MultiFactor Authentication is only supported on web, Android and iOS.',
678+
'MultiFactor Authentication is only supported on web, Android, iOS and macOS.',
681679
);
682680
}
683681
return _multiFactor ??= MultiFactor._(_delegate.multiFactor);

packages/firebase_auth/firebase_auth/macos/firebase_auth/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ let package = Package(
9393
.library(name: "firebase-auth", targets: ["firebase_auth"]),
9494
],
9595
dependencies: [
96-
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: firebase_sdk_version),
96+
.package(url: "https://github.com/cbenhagen/firebase-ios-sdk", branch: "11.15.0-totp"),
9797
.package(url: "https://github.com/firebase/flutterfire", exact: shared_spm_version),
9898
],
9999
targets: [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# in the LICENSE file.
4+
5+
include: ../../analysis_options.yaml
6+
7+
analyzer:
8+
exclude:
9+
- firebase_remote_config_platform_interface/lib/src/pigeon/messages.pigeon.dart
10+
- firebase_remote_config_platform_interface/test/pigeon/test_api.dart

packages/firebase_remote_config/firebase_remote_config/android/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ apply plugin: 'com.android.library'
55
apply from: file("local-config.gradle")
66

77
buildscript {
8+
ext.kotlin_version = "1.8.22"
89
repositories {
910
google()
1011
mavenCentral()
@@ -18,6 +19,8 @@ rootProject.allprojects {
1819
}
1920
}
2021

22+
apply plugin: 'kotlin-android'
23+
2124
def firebaseCoreProject = findProject(':firebase_core')
2225
if (firebaseCoreProject == null) {
2326
throw new GradleException('Could not find the firebase_core FlutterFire plugin, have you added it as a dependency in your pubspec?')
@@ -44,11 +47,20 @@ android {
4447
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4548
}
4649

50+
kotlinOptions {
51+
jvmTarget = JavaVersion.VERSION_17
52+
}
53+
4754
compileOptions {
4855
sourceCompatibility project.ext.javaVersion
4956
targetCompatibility project.ext.javaVersion
5057
}
5158

59+
sourceSets {
60+
main.java.srcDirs += "src/main/kotlin"
61+
test.java.srcDirs += "src/test/kotlin"
62+
}
63+
5264
buildFeatures {
5365
buildConfig = true
5466
}

0 commit comments

Comments
 (0)