diff options
author | 2017-08-23 09:02:50 -0700 | |
---|---|---|
committer | 2017-08-23 09:02:50 -0700 | |
commit | 768c4058f3489917be7d433ad685b2f16d59aac4 (patch) | |
tree | a9ad6d452b03f518aae669316426eb3b3cbc45fa /Firebase/Auth/Source/RPCs | |
parent | 6e12c501f8dde3057d26149826e82489e114b2a1 (diff) |
Adds reCAPTCHA Token (#211)
* Adds reCAPTCHA Token to the "send verification code" request.
Diffstat (limited to 'Firebase/Auth/Source/RPCs')
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRAuthBackend.m | 10 | ||||
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.h | 12 | ||||
-rw-r--r-- | Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.m | 12 |
3 files changed, 31 insertions, 3 deletions
diff --git a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m index 8eca6d5..0964d3f 100644 --- a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m +++ b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m @@ -341,6 +341,12 @@ static NSString *const kQuoutaExceededErrorMessage = @"QUOTA_EXCEEDED"; */ static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED"; +/** @var kCaptchaCheckFailedErrorMessage + @brief This is the error message the server will respond with if the reCAPTCHA token provided is + invalid. + */ +static NSString *const kCaptchaCheckFailedErrorMessage = @"CAPTCHA_CHECK_FAILED"; + /** @var gBackendImplementation @brief The singleton FIRAuthBackendImplementation instance to use. */ @@ -1014,6 +1020,10 @@ static id<FIRAuthBackendImplementation> gBackendImplementation; return [FIRAuthErrorUtils appNotVerifiedErrorWithMessage:serverErrorMessage]; } + if ([shortErrorMessage isEqualToString:kCaptchaCheckFailedErrorMessage]) { + return [FIRAuthErrorUtils captchaCheckFailedErrorWithMessage:serverErrorMessage]; + } + // In this case we handle an error that might be specified in the underlying errors dictionary, // the error message in determined based on the @c reason key in the dictionary. if (errorDictionary[kErrorsKey]) { diff --git a/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.h b/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.h index 9a5c41c..af6cc93 100644 --- a/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.h +++ b/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.h @@ -33,7 +33,13 @@ NS_ASSUME_NONNULL_BEGIN /** @property appCredential @brief The credential to prove the identity of the app in order to send the verification code. */ -@property(nonatomic, strong, readonly) FIRAuthAppCredential *appCredential; +@property(nonatomic, strong, readonly, nullable) FIRAuthAppCredential *appCredential; + +/** @property reCAPTCHAToken + @brief The reCAPTCHA token to prove the identity of the app in order to send the verification + code. + */ +@property(nonatomic, strong, readonly, nullable) NSString *reCAPTCHAToken; /** @fn initWithEndpoint:requestConfiguration: @brief Please use initWithPhoneNumber:appCredentials:requestConfiguration: instead. @@ -46,10 +52,12 @@ NS_ASSUME_NONNULL_BEGIN @brief Designated initializer. @param phoneNumber The phone number to which the verification code is to be sent. @param appCredential The credential that proves the identity of the app. + @param reCAPTCHAToken The reCAPTCHA token that proves the identity of the app. @param requestConfiguration An object containing configurations to be added to the request. */ - (nullable instancetype)initWithPhoneNumber:(NSString *)phoneNumber - appCredential:(FIRAuthAppCredential *)appCredential + appCredential:(nullable FIRAuthAppCredential *)appCredential + reCAPTCHAToken:(nullable NSString *)reCAPTCHAToken requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration NS_DESIGNATED_INITIALIZER; diff --git a/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.m b/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.m index 2f33e02..38ad8cf 100644 --- a/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.m +++ b/Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.m @@ -40,17 +40,24 @@ static NSString *const kReceiptKey = @"iosReceipt"; */ static NSString *const kSecretKey = @"iosSecret"; +/** @var kreCAPTCHATokenKey + @brief The key for the reCAPTCHAToken parameter in the request. + */ +static NSString *const kreCAPTCHATokenKey = @"recaptchaToken"; + @implementation FIRSendVerificationCodeRequest { } - (nullable instancetype)initWithPhoneNumber:(NSString *)phoneNumber - appCredential:(FIRAuthAppCredential *)appCredential + appCredential:(nullable FIRAuthAppCredential *)appCredential + reCAPTCHAToken:(nullable NSString *)reCAPTCHAToken requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration { self = [super initWithEndpoint:kSendVerificationCodeEndPoint requestConfiguration:requestConfiguration]; if (self) { _phoneNumber = [phoneNumber copy]; _appCredential = appCredential; + _reCAPTCHAToken = [reCAPTCHAToken copy]; } return self; } @@ -66,6 +73,9 @@ static NSString *const kSecretKey = @"iosSecret"; if (_appCredential.secret) { postBody[kSecretKey] = _appCredential.secret; } + if (_reCAPTCHAToken) { + postBody[kreCAPTCHATokenKey] = _reCAPTCHAToken; + } return postBody; } |