Skip to content

Commit b8f70da

Browse files
authored
Adds event ID validation to verify phone number (#263)
* Adds event ID validation to verify phone number
1 parent dc02ea9 commit b8f70da

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,19 @@ - (void)verifyPhoneNumber:(NSString *)phoneNumber
153153
completion(nil, error);
154154
return;
155155
}
156-
[self reCAPTCHAURLWithCompletion:^(NSURL *_Nullable reCAPTCHAURL,
157-
NSError *_Nullable error) {
156+
NSMutableString *eventID = [[NSMutableString alloc] init];
157+
for(int i=0; i<10; i++) {
158+
[eventID appendString:
159+
[NSString stringWithFormat:@"%c", 'a' + arc4random_uniform('z' - 'a' + 1)]];
160+
}
161+
[self reCAPTCHAURLWithEventID:eventID completion:^(NSURL *_Nullable reCAPTCHAURL,
162+
NSError *_Nullable error) {
158163
if (error) {
159164
callBackOnMainThread(nil, error);
160165
return;
161166
}
162167
FIRAuthURLCallbackMatcher callbackMatcher = ^BOOL(NSURL *_Nullable callbackURL) {
163-
return [self isVerifyAppURL:callbackURL];
168+
return [self isVerifyAppURL:callbackURL eventID:eventID];
164169
};
165170
[_auth.authURLPresenter presentURL:reCAPTCHAURL
166171
UIDelegate:UIDelegate
@@ -275,7 +280,7 @@ - (NSString *)reCAPTCHATokenForURL:(NSURL *)URL error:(NSError **)error {
275280
@param URL The url to be checked against the authType string.
276281
@return Whether or not the URL matches authType.
277282
*/
278-
- (BOOL)isVerifyAppURL:(nullable NSURL *)URL {
283+
- (BOOL)isVerifyAppURL:(nullable NSURL *)URL eventID:(NSString *)eventID {
279284
if (!URL) {
280285
return NO;
281286
}
@@ -297,7 +302,8 @@ - (BOOL)isVerifyAppURL:(nullable NSURL *)URL {
297302
NSURL *deeplinkURL = [NSURL URLWithString:URLQueryItems[@"deep_link_id"]];
298303
NSDictionary<NSString *, NSString *> *deeplinkQueryItems =
299304
[NSDictionary gtm_dictionaryWithHttpArgumentsString:deeplinkURL.query];
300-
if ([deeplinkQueryItems[@"authType"] isEqualToString:kAuthTypeVerifyApp]) {
305+
if ([deeplinkQueryItems[@"authType"] isEqualToString:kAuthTypeVerifyApp] &&
306+
[deeplinkQueryItems[@"eventId"] isEqualToString:eventID]) {
301307
return YES;
302308
}
303309
return NO;
@@ -423,7 +429,7 @@ - (void)verifyClientWithCompletion:(FIRVerifyClientCallback)completion {
423429
}];
424430
}
425431

426-
- (void)reCAPTCHAURLWithCompletion:(FIRReCAPTCHAURLCallBack)completion {
432+
- (void)reCAPTCHAURLWithEventID:(NSString *)eventID completion:(FIRReCAPTCHAURLCallBack)completion {
427433
[self fetchAuthDomainWithCompletion:^(NSString *_Nullable authDomain,
428434
NSError *_Nullable error) {
429435
if (error) {
@@ -438,7 +444,8 @@ - (void)reCAPTCHAURLWithCompletion:(FIRReCAPTCHAURLCallBack)completion {
438444
@"authType" : kAuthTypeVerifyApp,
439445
@"ibi" : bundleID ?: @"",
440446
@"clientId" : clienID,
441-
@"v" : [FIRAuthBackend authUserAgent]
447+
@"v" : [FIRAuthBackend authUserAgent],
448+
@"eventId" : eventID,
442449
}];
443450
if (_auth.requestConfiguration.languageCode) {
444451
urlArguments[@"hl"] = _auth.requestConfiguration.languageCode;

0 commit comments

Comments
 (0)