Skip to content

Commit 73f9028

Browse files
authored
feat(auth): add support for initializeRecaptchaConfig (#17365)
* feat(auth): add support for initializeRecaptchaConfig * chore: add macOS check for initializeRecaptchaConfigApp and return early * chore: remove extra nil argument * chore: add test for initializeRecaptchaConfig * chore: update test for initializeRecaptchaConfig
1 parent 53320dc commit 73f9028

15 files changed

Lines changed: 215 additions & 0 deletions

File tree

packages/firebase_auth/firebase_auth/android/src/main/java/io/flutter/plugins/firebase/auth/FlutterFirebaseAuthPlugin.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,25 @@ public void revokeTokenWithAuthorizationCode(
678678
result.success();
679679
}
680680

681+
@Override
682+
public void initializeRecaptchaConfig(
683+
@NonNull GeneratedAndroidFirebaseAuth.AuthPigeonFirebaseApp app,
684+
@NonNull GeneratedAndroidFirebaseAuth.VoidResult result) {
685+
FirebaseAuth firebaseAuth = getAuthFromPigeon(app);
686+
firebaseAuth
687+
.initializeRecaptchaConfig()
688+
.addOnCompleteListener(
689+
task -> {
690+
if (task.isSuccessful()) {
691+
result.success();
692+
} else {
693+
result.error(
694+
FlutterFirebaseAuthPluginException.parserExceptionToFlutter(
695+
task.getException()));
696+
}
697+
});
698+
}
699+
681700
@Override
682701
public Task<Map<String, Object>> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) {
683702
TaskCompletionSource<Map<String, Object>> taskCompletionSource = new TaskCompletionSource<>();

packages/firebase_auth/firebase_auth/android/src/main/java/io/flutter/plugins/firebase/auth/GeneratedAndroidFirebaseAuth.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,6 +2642,8 @@ void revokeTokenWithAuthorizationCode(
26422642
@NonNull String authorizationCode,
26432643
@NonNull VoidResult result);
26442644

2645+
void initializeRecaptchaConfig(@NonNull AuthPigeonFirebaseApp app, @NonNull VoidResult result);
2646+
26452647
/** The codec used by FirebaseAuthHostApi. */
26462648
static @NonNull MessageCodec<Object> getCodec() {
26472649
return FirebaseAuthHostApiCodec.INSTANCE;
@@ -3395,6 +3397,38 @@ public void error(Throwable error) {
33953397
channel.setMessageHandler(null);
33963398
}
33973399
}
3400+
{
3401+
BasicMessageChannel<Object> channel =
3402+
new BasicMessageChannel<>(
3403+
binaryMessenger,
3404+
"dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.initializeRecaptchaConfig"
3405+
+ messageChannelSuffix,
3406+
getCodec());
3407+
if (api != null) {
3408+
channel.setMessageHandler(
3409+
(message, reply) -> {
3410+
ArrayList<Object> wrapped = new ArrayList<Object>();
3411+
ArrayList<Object> args = (ArrayList<Object>) message;
3412+
AuthPigeonFirebaseApp appArg = (AuthPigeonFirebaseApp) args.get(0);
3413+
VoidResult resultCallback =
3414+
new VoidResult() {
3415+
public void success() {
3416+
wrapped.add(0, null);
3417+
reply.reply(wrapped);
3418+
}
3419+
3420+
public void error(Throwable error) {
3421+
ArrayList<Object> wrappedError = wrapError(error);
3422+
reply.reply(wrappedError);
3423+
}
3424+
};
3425+
3426+
api.initializeRecaptchaConfig(appArg, resultCallback);
3427+
});
3428+
} else {
3429+
channel.setMessageHandler(null);
3430+
}
3431+
}
33983432
}
33993433
}
34003434

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,4 +2172,22 @@ - (void)verifyBeforeUpdateEmailApp:(nonnull AuthPigeonFirebaseApp *)app
21722172
}];
21732173
}
21742174

2175+
- (void)initializeRecaptchaConfigApp:(AuthPigeonFirebaseApp *)app
2176+
completion:(void (^)(FlutterError *_Nullable))completion {
2177+
#if TARGET_OS_OSX
2178+
NSLog(@"initializeRecaptchaConfigWithCompletion is not supported on the "
2179+
@"MacOS platform.");
2180+
completion(nil);
2181+
#else
2182+
FIRAuth *auth = [self getFIRAuthFromAppNameFromPigeon:app];
2183+
[auth initializeRecaptchaConfigWithCompletion:^(NSError *_Nullable error) {
2184+
if (error != nil) {
2185+
completion([FLTFirebaseAuthPlugin convertToFlutterError:error]);
2186+
} else {
2187+
completion(nil);
2188+
}
2189+
}];
2190+
#endif
2191+
}
2192+
21752193
@end

packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/firebase_auth_messages.g.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,32 @@ void SetUpFirebaseAuthHostApiWithSuffix(id<FlutterBinaryMessenger> binaryMesseng
15531553
[channel setMessageHandler:nil];
15541554
}
15551555
}
1556+
{
1557+
FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
1558+
initWithName:[NSString
1559+
stringWithFormat:@"%@%@",
1560+
@"dev.flutter.pigeon.firebase_auth_platform_interface."
1561+
@"FirebaseAuthHostApi.initializeRecaptchaConfig",
1562+
messageChannelSuffix]
1563+
binaryMessenger:binaryMessenger
1564+
codec:FirebaseAuthHostApiGetCodec()];
1565+
if (api) {
1566+
NSCAssert([api respondsToSelector:@selector(initializeRecaptchaConfigApp:completion:)],
1567+
@"FirebaseAuthHostApi api (%@) doesn't respond to "
1568+
@"@selector(initializeRecaptchaConfigApp:completion:)",
1569+
api);
1570+
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
1571+
NSArray *args = message;
1572+
AuthPigeonFirebaseApp *arg_app = GetNullableObjectAtIndex(args, 0);
1573+
[api initializeRecaptchaConfigApp:arg_app
1574+
completion:^(FlutterError *_Nullable error) {
1575+
callback(wrapResult(nil, error));
1576+
}];
1577+
}];
1578+
} else {
1579+
[channel setMessageHandler:nil];
1580+
}
1581+
}
15561582
}
15571583
@interface FirebaseAuthUserHostApiCodecReader : FlutterStandardReader
15581584
@end

packages/firebase_auth/firebase_auth/ios/firebase_auth/Sources/firebase_auth/include/Public/firebase_auth_messages.g.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ NSObject<FlutterMessageCodec> *FirebaseAuthHostApiGetCodec(void);
385385
- (void)revokeTokenWithAuthorizationCodeApp:(AuthPigeonFirebaseApp *)app
386386
authorizationCode:(NSString *)authorizationCode
387387
completion:(void (^)(FlutterError *_Nullable))completion;
388+
- (void)initializeRecaptchaConfigApp:(AuthPigeonFirebaseApp *)app
389+
completion:(void (^)(FlutterError *_Nullable))completion;
388390
@end
389391

390392
extern void SetUpFirebaseAuthHostApi(id<FlutterBinaryMessenger> binaryMessenger,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,12 @@ class FirebaseAuth extends FirebasePluginPlatform {
819819
return _delegate.revokeTokenWithAuthorizationCode(authorizationCode);
820820
}
821821

822+
/// Initializes the reCAPTCHA Enterprise client proactively to enhance reCAPTCHA signal collection and
823+
/// to complete reCAPTCHA-protected flows in a single attempt.
824+
Future<void> initializeRecaptchaConfig() {
825+
return _delegate.initializeRecaptchaConfig();
826+
}
827+
822828
@override
823829
String toString() {
824830
return 'FirebaseAuth(app: ${app.name})';

packages/firebase_auth/firebase_auth_platform_interface/lib/src/method_channel/method_channel_firebase_auth.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,15 @@ class MethodChannelFirebaseAuth extends FirebaseAuthPlatform {
667667
);
668668
}
669669
}
670+
671+
@override
672+
Future<void> initializeRecaptchaConfig() async {
673+
try {
674+
await _api.initializeRecaptchaConfig(pigeonDefault);
675+
} catch (e, stack) {
676+
convertPlatformException(e, stack);
677+
}
678+
}
670679
}
671680

672681
/// Simple helper class to make nullable values transferable through StreamControllers.

packages/firebase_auth/firebase_auth_platform_interface/lib/src/pigeon/messages.pigeon.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,30 @@ class FirebaseAuthHostApi {
14781478
return;
14791479
}
14801480
}
1481+
1482+
Future<void> initializeRecaptchaConfig(AuthPigeonFirebaseApp app) async {
1483+
final String __pigeon_channelName =
1484+
'dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.initializeRecaptchaConfig$__pigeon_messageChannelSuffix';
1485+
final BasicMessageChannel<Object?> __pigeon_channel =
1486+
BasicMessageChannel<Object?>(
1487+
__pigeon_channelName,
1488+
pigeonChannelCodec,
1489+
binaryMessenger: __pigeon_binaryMessenger,
1490+
);
1491+
final List<Object?>? __pigeon_replyList =
1492+
await __pigeon_channel.send(<Object?>[app]) as List<Object?>?;
1493+
if (__pigeon_replyList == null) {
1494+
throw _createConnectionError(__pigeon_channelName);
1495+
} else if (__pigeon_replyList.length > 1) {
1496+
throw PlatformException(
1497+
code: __pigeon_replyList[0]! as String,
1498+
message: __pigeon_replyList[1] as String?,
1499+
details: __pigeon_replyList[2],
1500+
);
1501+
} else {
1502+
return;
1503+
}
1504+
}
14811505
}
14821506

14831507
class _FirebaseAuthUserHostApiCodec extends StandardMessageCodec {

packages/firebase_auth/firebase_auth_platform_interface/lib/src/platform_interface/platform_interface_firebase_auth.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,4 +706,10 @@ abstract class FirebaseAuthPlatform extends PlatformInterface {
706706
throw UnimplementedError(
707707
'revokeTokenWithAuthorizationCode() is not implemented');
708708
}
709+
710+
/// Initializes the reCAPTCHA Enterprise client proactively to enhance reCAPTCHA signal collection and
711+
/// to complete reCAPTCHA-protected flows in a single attempt.
712+
Future<void> initializeRecaptchaConfig() {
713+
throw UnimplementedError('initializeRecaptchaConfig() is not implemented');
714+
}
709715
}

packages/firebase_auth/firebase_auth_platform_interface/pigeons/messages.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ abstract class FirebaseAuthHostApi {
419419
AuthPigeonFirebaseApp app,
420420
String authorizationCode,
421421
);
422+
423+
@async
424+
void initializeRecaptchaConfig(
425+
AuthPigeonFirebaseApp app,
426+
);
422427
}
423428

424429
class PigeonIdTokenResult {

0 commit comments

Comments
 (0)