Skip to content

Commit c36c220

Browse files
committed
[Auth] Add support for upcoming Recaptcha changes
1 parent 1d367ae commit c36c220

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

FirebaseAuth/Sources/ObjC/FIRRecaptchaBridge.m

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@
2424
static void retrieveToken(NSString *actionString,
2525
NSString *fakeToken,
2626
FIRAuthRecaptchaTokenCallback callback) {
27-
Class RecaptchaActionClass = NSClassFromString(@"RecaptchaAction");
27+
Class RecaptchaActionClass = NSClassFromString(@"RecaptchaEnterprise.RCAAction");
2828
SEL customActionSelector = NSSelectorFromString(@"initWithCustomAction:");
29+
if (!RecaptchaActionClass) {
30+
// Fall back to attempting to connect with pre-18.7.0 RecaptchaEnterprise.
31+
RecaptchaActionClass = NSClassFromString(@"RecaptchaAction");
32+
}
33+
2934
if (RecaptchaActionClass &&
3035
[RecaptchaActionClass instancesRespondToSelector:customActionSelector]) {
3136
// Initialize with a custom action
3237
id (*funcWithCustomAction)(id, SEL, NSString *) = (id(*)(
3338
id, SEL, NSString *))[RecaptchaActionClass instanceMethodForSelector:customActionSelector];
3439

35-
id<RCAActionProtocol> customAction = funcWithCustomAction([[RecaptchaActionClass alloc] init],
36-
customActionSelector, actionString);
40+
id<RCAActionProtocol> customAction =
41+
funcWithCustomAction([RecaptchaActionClass alloc], customActionSelector, actionString);
3742
if (customAction) {
3843
[recaptchaClient execute:customAction
3944
completion:^(NSString *_Nullable token, NSError *_Nullable error) {
@@ -64,8 +69,15 @@ void FIRRecaptchaGetToken(NSString *siteKey,
6469
return;
6570
}
6671

67-
Class RecaptchaClass = NSClassFromString(@"Recaptcha");
68-
SEL selector = NSSelectorFromString(@"getClientWithSiteKey:completion:");
72+
// Why not use `conformsToProtocol`?
73+
Class RecaptchaClass = NSClassFromString(@"RecaptchaEnterprise.RCARecaptcha");
74+
SEL selector = NSSelectorFromString(@"fetchClientWithSiteKey:completion:");
75+
if (!RecaptchaClass) {
76+
// Fall back to attempting to connect with pre-18.7.0 RecaptchaEnterprise.
77+
RecaptchaClass = NSClassFromString(@"Recaptcha");
78+
selector = NSSelectorFromString(@"getClientWithSiteKey:completion:");
79+
}
80+
6981
if (RecaptchaClass && [RecaptchaClass respondsToSelector:selector]) {
7082
void (*funcWithoutTimeout)(id, SEL, NSString *,
7183
void (^)(id<RCARecaptchaClientProtocol> _Nullable recaptchaClient,

0 commit comments

Comments
 (0)