aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firebase/Auth
diff options
context:
space:
mode:
authorGravatar Zsika Phillip <protocol86@users.noreply.github.com>2018-04-29 19:29:48 -0700
committerGravatar Paul Beusterien <paulbeusterien@google.com>2018-04-29 19:29:48 -0700
commit22a943708d156712a97d29dcd11ee903cb9d8494 (patch)
tree918aa3254d408010679b415b5cbe6fb2866d6cea /Firebase/Auth
parent1476e2bfe5db393ac3b069c1e12d14f91f6b529b (diff)
Adds phone auth testing. (disableAppVerification) (#1192)
Diffstat (limited to 'Firebase/Auth')
-rw-r--r--Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m15
-rw-r--r--Firebase/Auth/Source/FIRAuth.m2
-rw-r--r--Firebase/Auth/Source/FIRAuthSettings.m29
-rw-r--r--Firebase/Auth/Source/Public/FIRAuth.h6
-rw-r--r--Firebase/Auth/Source/Public/FIRAuthSettings.h30
-rw-r--r--Firebase/Auth/Source/Public/FirebaseAuth.h1
-rw-r--r--Firebase/Auth/Source/RPCs/FIRAuthBackend.m14
7 files changed, 97 insertions, 0 deletions
diff --git a/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m b/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m
index 948a515..2d06a15 100644
--- a/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m
+++ b/Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m
@@ -29,6 +29,7 @@
#import "FIRAuthNotificationManager.h"
#import "FIRAuthErrorUtils.h"
#import "FIRAuthBackend.h"
+#import "FIRAuthSettings.h"
#import "FIRAuthWebUtils.h"
#import "FirebaseAuthVersion.h"
#import <FirebaseCore/FIROptions.h>
@@ -364,6 +365,20 @@ NSString *const kReCAPTCHAURLStringFormat = @"https://%@/__/auth/handler?";
- (void)verifyClientAndSendVerificationCodeToPhoneNumber:(NSString *)phoneNumber
retryOnInvalidAppCredential:(BOOL)retryOnInvalidAppCredential
callback:(FIRVerificationResultCallback)callback {
+ if (_auth.settings.isAppVerificationDisabledForTesting) {
+ FIRSendVerificationCodeRequest *request =
+ [[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:phoneNumber
+ appCredential:nil
+ reCAPTCHAToken:nil
+ requestConfiguration:
+ _auth.requestConfiguration];
+ [FIRAuthBackend sendVerificationCode:request
+ callback:^(FIRSendVerificationCodeResponse *_Nullable response,
+ NSError *_Nullable error) {
+ callback(response.verificationID, error);
+ }];
+ return;
+ }
[self verifyClientWithCompletion:^(FIRAuthAppCredential *_Nullable appCredential,
NSError *_Nullable error) {
if (error) {
diff --git a/Firebase/Auth/Source/FIRAuth.m b/Firebase/Auth/Source/FIRAuth.m
index 82a7c02..c83a19a 100644
--- a/Firebase/Auth/Source/FIRAuth.m
+++ b/Firebase/Auth/Source/FIRAuth.m
@@ -33,6 +33,7 @@
#import "FIRAuthGlobalWorkQueue.h"
#import "FIRAuthKeychain.h"
#import "FIRAuthOperationType.h"
+#import "FIRAuthSettings.h"
#import "FIRUser_Internal.h"
#import "FirebaseAuth.h"
#import "FIRAuthBackend.h"
@@ -434,6 +435,7 @@ static NSMutableDictionary *gKeychainServiceNameForAppName;
if (self) {
_listenerHandles = [NSMutableArray array];
_requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:APIKey];
+ _settings = [[FIRAuthSettings alloc] init];
_firebaseAppName = [appName copy];
#if TARGET_OS_IOS
UIApplication *application = [UIApplication sharedApplication];
diff --git a/Firebase/Auth/Source/FIRAuthSettings.m b/Firebase/Auth/Source/FIRAuthSettings.m
new file mode 100644
index 0000000..575bb3c
--- /dev/null
+++ b/Firebase/Auth/Source/FIRAuthSettings.m
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2018 Google
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import "FIRAuthSettings.h"
+
+@implementation FIRAuthSettings
+
+- (instancetype)init {
+ self = [super init];
+ if (self) {
+ _appVerificationDisabledForTesting = NO;
+ }
+ return self;
+}
+
+@end
diff --git a/Firebase/Auth/Source/Public/FIRAuth.h b/Firebase/Auth/Source/Public/FIRAuth.h
index c262c49..2901fca 100644
--- a/Firebase/Auth/Source/Public/FIRAuth.h
+++ b/Firebase/Auth/Source/Public/FIRAuth.h
@@ -28,6 +28,7 @@
@class FIRAuth;
@class FIRAuthCredential;
@class FIRAuthDataResult;
+@class FIRAuthSettings;
@class FIRUser;
@protocol FIRAuthStateListener;
@@ -288,6 +289,11 @@ NS_SWIFT_NAME(Auth)
*/
@property (nonatomic, copy, nullable) NSString *languageCode;
+/** @property settings
+ @brief Contains settings related to the auth object.
+ */
+@property (nonatomic, copy, nullable) FIRAuthSettings *settings;
+
#if TARGET_OS_IOS
/** @property APNSToken
@brief The APNs token used for phone number authentication. The type of the token (production
diff --git a/Firebase/Auth/Source/Public/FIRAuthSettings.h b/Firebase/Auth/Source/Public/FIRAuthSettings.h
new file mode 100644
index 0000000..d3fee3e
--- /dev/null
+++ b/Firebase/Auth/Source/Public/FIRAuthSettings.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2018 Google
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#import <Foundation/Foundation.h>
+
+/** @class FIRAuthSettings
+ @brief Determines settings related to an auth object.
+ */
+@interface FIRAuthSettings : NSObject
+
+/** @property appVerificationDisabledForTesting
+ @brief Flag to determine whether app verification should be disabled for testing or not.
+ */
+@property (nonatomic, assign, getter=isAppVerificationDisabledForTesting) BOOL
+ appVerificationDisabledForTesting;
+
+@end
diff --git a/Firebase/Auth/Source/Public/FirebaseAuth.h b/Firebase/Auth/Source/Public/FirebaseAuth.h
index cd7e4a4..c8837f8 100644
--- a/Firebase/Auth/Source/Public/FirebaseAuth.h
+++ b/Firebase/Auth/Source/Public/FirebaseAuth.h
@@ -39,4 +39,5 @@
#import "FIRPhoneAuthCredential.h"
#import "FIRPhoneAuthProvider.h"
#import "FIRAuthAPNSTokenType.h"
+#import "FIRAuthSettings.h"
#endif
diff --git a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m
index e380e34..ff8f2f0 100644
--- a/Firebase/Auth/Source/RPCs/FIRAuthBackend.m
+++ b/Firebase/Auth/Source/RPCs/FIRAuthBackend.m
@@ -350,6 +350,13 @@ static NSString *const kQuoutaExceededErrorMessage = @"QUOTA_EXCEEDED";
*/
static NSString *const kAppNotVerifiedErrorMessage = @"APP_NOT_VERIFIED";
+/** @var kMissingClientIdentifier
+ @brief This is the error message the server will respond with if Firebase could not verify the
+ app during a phone authentication flow when a real phone number is used and app verification
+ is disabled for testing.
+ */
+static NSString *const kMissingClientIdentifier = @"MISSING_CLIENT_IDENTIFIER";
+
/** @var kCaptchaCheckFailedErrorMessage
@brief This is the error message the server will respond with if the reCAPTCHA token provided is
invalid.
@@ -1073,6 +1080,13 @@ static id<FIRAuthBackendImplementation> gBackendImplementation;
return [FIRAuthErrorUtils appNotVerifiedErrorWithMessage:serverErrorMessage];
}
+ if ([shortErrorMessage isEqualToString:kMissingClientIdentifier]) {
+ return [FIRAuthErrorUtils appNotVerifiedErrorWithMessage:@"Missing app verification via"
+ " reCAPTCHA or APNS token. Please verify that appVerificationDisabledForTesting is not"
+ " enabled when testing with a phone number that is not marked as a test Phone number in the"
+ " app console."];
+ }
+
if ([shortErrorMessage isEqualToString:kCaptchaCheckFailedErrorMessage]) {
return [FIRAuthErrorUtils captchaCheckFailedErrorWithMessage:serverErrorMessage];
}