Skip to content

Commit 2661133

Browse files
committed
feat(auth): add support for initializeRecaptchaConfig
1 parent 7bd6369 commit 2661133

File tree

14 files changed

+192
-0
lines changed

14 files changed

+192
-0
lines changed

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,4 +2172,16 @@ - (void)verifyBeforeUpdateEmailApp:(nonnull AuthPigeonFirebaseApp *)app
21722172
}];
21732173
}
21742174

2175+
- (void)initializeRecaptchaConfigApp:(AuthPigeonFirebaseApp *)app
2176+
completion:(void (^)(FlutterError *_Nullable))completion {
2177+
FIRAuth *auth = [self getFIRAuthFromAppNameFromPigeon:app];
2178+
[auth initializeRecaptchaConfigWithCompletion:^(NSError *_Nullable error) {
2179+
if (error != nil) {
2180+
completion([FLTFirebaseAuthPlugin convertToFlutterError:error]);
2181+
} else {
2182+
completion(nil);
2183+
}
2184+
}];
2185+
}
2186+
21752187
@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 {

packages/firebase_auth/firebase_auth_platform_interface/test/pigeon/test_api.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ abstract class TestFirebaseAuthHostApi {
187187
Future<void> revokeTokenWithAuthorizationCode(
188188
AuthPigeonFirebaseApp app, String authorizationCode);
189189

190+
Future<void> initializeRecaptchaConfig(AuthPigeonFirebaseApp app);
191+
190192
static void setUp(
191193
TestFirebaseAuthHostApi? api, {
192194
BinaryMessenger? binaryMessenger,
@@ -993,6 +995,38 @@ abstract class TestFirebaseAuthHostApi {
993995
});
994996
}
995997
}
998+
{
999+
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
1000+
Object?>(
1001+
'dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.initializeRecaptchaConfig$messageChannelSuffix',
1002+
pigeonChannelCodec,
1003+
binaryMessenger: binaryMessenger);
1004+
if (api == null) {
1005+
_testBinaryMessengerBinding!.defaultBinaryMessenger
1006+
.setMockDecodedMessageHandler<Object?>(__pigeon_channel, null);
1007+
} else {
1008+
_testBinaryMessengerBinding!.defaultBinaryMessenger
1009+
.setMockDecodedMessageHandler<Object?>(__pigeon_channel,
1010+
(Object? message) async {
1011+
assert(message != null,
1012+
'Argument for dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.initializeRecaptchaConfig was null.');
1013+
final List<Object?> args = (message as List<Object?>?)!;
1014+
final AuthPigeonFirebaseApp? arg_app =
1015+
(args[0] as AuthPigeonFirebaseApp?);
1016+
assert(arg_app != null,
1017+
'Argument for dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.initializeRecaptchaConfig was null, expected non-null AuthPigeonFirebaseApp.');
1018+
try {
1019+
await api.initializeRecaptchaConfig(arg_app!);
1020+
return wrapResponse(empty: true);
1021+
} on PlatformException catch (e) {
1022+
return wrapResponse(error: e);
1023+
} catch (e) {
1024+
return wrapResponse(
1025+
error: PlatformException(code: 'error', message: e.toString()));
1026+
}
1027+
});
1028+
}
1029+
}
9961030
}
9971031
}
9981032

packages/firebase_auth/firebase_auth_web/lib/firebase_auth_web.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,13 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {
633633
'revokeTokenWithAuthorizationCode() is only available on apple platforms.',
634634
);
635635
}
636+
637+
@override
638+
Future<void> initializeRecaptchaConfig() async {
639+
await guardAuthExceptions(
640+
() => delegate.initializeRecaptchaConfig(),
641+
);
642+
}
636643
}
637644

638645
String getOriginName(String appName) {

packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,11 @@ class Auth extends JsObjectWrapper<auth_interop.AuthJsImpl> {
804804
.verifyPasswordResetCode(jsObject, code.toJS)
805805
.toDart
806806
.then((value) => (value! as JSString).toDart);
807+
808+
/// Initializes the reCAPTCHA Enterprise client proactively to enhance reCAPTCHA signal collection and
809+
/// to complete reCAPTCHA-protected flows in a single attempt.
810+
Future initializeRecaptchaConfig() =>
811+
auth_interop.initializeRecaptchaConfig(jsObject).toDart;
807812
}
808813

809814
/// Represents an auth provider.

packages/firebase_auth/firebase_auth_web/lib/src/interop/auth_interop.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,3 +984,6 @@ class PhoneAuthCredentialJsImpl extends AuthCredential {
984984
extension PhoneAuthCredentialJsImplExtension on PhoneAuthCredentialJsImpl {
985985
external JSObject toJSON();
986986
}
987+
988+
@JS()
989+
external JSPromise initializeRecaptchaConfig(AuthJsImpl auth);

0 commit comments

Comments
 (0)