aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2017-08-23 09:02:50 -0700
committerGravatar GitHub <noreply@github.com>2017-08-23 09:02:50 -0700
commit768c4058f3489917be7d433ad685b2f16d59aac4 (patch)
treea9ad6d452b03f518aae669316426eb3b3cbc45fa /Firebase
parent6e12c501f8dde3057d26149826e82489e114b2a1 (diff)
Adds reCAPTCHA Token (#211)
* Adds reCAPTCHA Token to the "send verification code" request.
Diffstat (limited to 'Firebase')
-rw-r--r--Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m1
-rw-r--r--Firebase/Auth/Source/FIRAuthErrorUtils.h7
-rw-r--r--Firebase/Auth/Source/FIRAuthErrorUtils.m14
-rw-r--r--Firebase/Auth/Source/FIRAuthInternalErrors.h5
-rw-r--r--Firebase/Auth/Source/Public/FIRAuthErrors.h4
-rw-r--r--Firebase/Auth/Source/RPCs/FIRAuthBackend.m10
-rw-r--r--Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.h12
-rw-r--r--Firebase/Auth/Source/RPCs/FIRSendVerificationCodeRequest.m12
8 files changed, 62 insertions, 3 deletions
diff --git a/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m b/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m
index b456a2d..7c29f13 100644
--- a/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m
+++ b/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m
@@ -132,6 +132,7 @@ typedef void (^FIRVerifyClientCallback)(FIRAuthAppCredential *_Nullable appCrede
FIRSendVerificationCodeRequest *request =
[[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:phoneNumber
appCredential:appCredential
+ reCAPTCHAToken:nil
requestConfiguration:_auth.requestConfiguration];
[FIRAuthBackend sendVerificationCode:request
callback:^(FIRSendVerificationCodeResponse *_Nullable response,
diff --git a/Firebase/Auth/Source/FIRAuthErrorUtils.h b/Firebase/Auth/Source/FIRAuthErrorUtils.h
index a857d4b..c2c9171 100644
--- a/Firebase/Auth/Source/FIRAuthErrorUtils.h
+++ b/Firebase/Auth/Source/FIRAuthErrorUtils.h
@@ -444,6 +444,13 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (NSError *)appNotVerifiedErrorWithMessage:(nullable NSString *)message;
+/** @fn captchaCheckFailedErrorWithMessage:
+ @brief Constructs an @c NSError with the @c FIRAuthErrorCaptchaCheckFailed code.
+ @param message Error message from the backend, if any.
+ @return The NSError instance associated with the given FIRAuthError.
+ */
++ (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message;
+
/** @fn keychainErrorWithFunction:status:
@brief Constructs an @c NSError with the @c FIRAuthErrorCodeKeychainError code.
@param keychainFunction The keychain function which was invoked and yielded an unexpected
diff --git a/Firebase/Auth/Source/FIRAuthErrorUtils.m b/Firebase/Auth/Source/FIRAuthErrorUtils.m
index 42fb543..0439f81 100644
--- a/Firebase/Auth/Source/FIRAuthErrorUtils.m
+++ b/Firebase/Auth/Source/FIRAuthErrorUtils.m
@@ -339,6 +339,12 @@ static NSString *const kFIRAuthErrorMessageAppNotVerified = @"Firebase could not
"silent push notification and therefore could not verify your app. Ensure that you configured "
"your app correctly to recieve push notifications.";
+/** @var kFIRAuthErrorMessageCaptchaCheckFailed
+ @brief Message for @c FIRAuthErrorCodeCaptchaCheckFailed error code.
+ */
+static NSString *const kFIRAuthErrorMessageCaptchaCheckFailed = @"The reCAPTCHA response token "
+ "provided is either invalid, expired or already";
+
/** @var kFIRAuthErrorMessageInternalError
@brief Message for @c FIRAuthErrorCodeInternalError error code.
*/
@@ -447,6 +453,8 @@ static NSString *FIRAuthErrorDescription(FIRAuthErrorCode code) {
return kFIRAuthErrorMessageNotificationNotForwarded;
case FIRAuthErrorCodeAppNotVerified:
return kFIRAuthErrorMessageAppNotVerified;
+ case FIRAuthErrorCodeCaptchaCheckFailed:
+ return kFIRAuthErrorMessageCaptchaCheckFailed;
}
}
@@ -552,6 +560,8 @@ static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
return @"ERROR_NOTIFICATION_NOT_FORWARDED";
case FIRAuthErrorCodeAppNotVerified:
return @"ERROR_APP_NOT_VERIFIED";
+ case FIRAuthErrorCodeCaptchaCheckFailed:
+ return @"ERROR_CAPTCHA_CHECK_FAILED";
}
}
@@ -859,6 +869,10 @@ static NSString *const FIRAuthErrorCodeString(FIRAuthErrorCode code) {
return [self errorWithCode:FIRAuthInternalErrorCodeAppNotVerified message:message];
}
++ (NSError *)captchaCheckFailedErrorWithMessage:(nullable NSString *)message {
+ return [self errorWithCode:FIRAuthInternalErrorCodeCaptchaCheckFailed message:message];
+}
+
+ (NSError *)keychainErrorWithFunction:(NSString *)keychainFunction status:(OSStatus)status {
NSString *failureReason = [NSString stringWithFormat:@"%@ (%li)", keychainFunction, (long)status];
return [self errorWithCode:FIRAuthInternalErrorCodeKeychainError userInfo:@{
diff --git a/Firebase/Auth/Source/FIRAuthInternalErrors.h b/Firebase/Auth/Source/FIRAuthInternalErrors.h
index 5f4a5c7..724b95c 100644
--- a/Firebase/Auth/Source/FIRAuthInternalErrors.h
+++ b/Firebase/Auth/Source/FIRAuthInternalErrors.h
@@ -307,6 +307,11 @@ typedef NS_ENUM(NSInteger, FIRAuthInternalErrorCode) {
FIRAuthInternalErrorCodeInvalidAppCredential =
FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeInvalidAppCredential,
+ /** Indicates that the reCAPTCHA token is not valid.
+ */
+ FIRAuthInternalErrorCodeCaptchaCheckFailed =
+ FIRAuthPublicErrorCodeFlag | FIRAuthErrorCodeCaptchaCheckFailed,
+
/** Indicates that an invalid verification ID was used in the verifyPhoneNumber request.
*/
FIRAuthInternalErrorCodeInvalidVerificationID =
diff --git a/Firebase/Auth/Source/Public/FIRAuthErrors.h b/Firebase/Auth/Source/Public/FIRAuthErrors.h
index 2859161..6ab6900 100644
--- a/Firebase/Auth/Source/Public/FIRAuthErrors.h
+++ b/Firebase/Auth/Source/Public/FIRAuthErrors.h
@@ -272,6 +272,10 @@ typedef NS_ENUM(NSInteger, FIRAuthErrorCode) {
*/
FIRAuthErrorCodeAppNotVerified = 17055,
+ /** Indicates that the reCAPTCHA token is not valid.
+ */
+ FIRAuthErrorCodeCaptchaCheckFailed = 17056,
+
/** Indicates an error occurred while attempting to access the keychain.
*/
FIRAuthErrorCodeKeychainError = 17995,
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;
}