Skip to content

Commit f71480c

Browse files
paulb777ncooke3
andauthored
Fix Phone Auth via APNS for Sandbox Tokens and update Sample's Firebase app (#13539)
Co-authored-by: Nick Cooke <[email protected]>
1 parent 6835193 commit f71480c

File tree

14 files changed

+35
-74
lines changed

14 files changed

+35
-74
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 11.2.0
22
- [Fixed] Fixed crashes that could occur in Swift continuation blocks running in the Xcode 16
33
betas. (#13480)
4+
- [Fixed] Fixed Phone Auth via Sandbox APNS tokens that broke in 11.0.0. (#13479)
45

56
# 11.1.0
67
- [fixed] Fixed `Swift.error` conformance for `AuthErrorCode`. (#13430)

FirebaseAuth/Sources/Swift/Backend/VerifyClientRequest.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class VerifyClientRequest: IdentityToolkitRequest, AuthRPCRequest {
3232
if let appToken = appToken {
3333
postBody[Self.appTokenKey] = appToken
3434
}
35-
postBody[Self.isSandboxKey] = isSandbox
35+
if isSandbox {
36+
postBody[Self.isSandboxKey] = true
37+
}
3638
return postBody
3739
}
3840

@@ -42,11 +44,10 @@ class VerifyClientRequest: IdentityToolkitRequest, AuthRPCRequest {
4244
/// The flag that denotes if the appToken pertains to Sandbox or Production.
4345
private(set) var isSandbox: Bool
4446

45-
init(withAppToken: String?,
47+
init(withAppToken appToken: String?,
4648
isSandbox: Bool,
4749
requestConfiguration: AuthRequestConfiguration) {
48-
appToken = withAppToken
49-
self.isSandbox = isSandbox
50+
self.appToken = appToken
5051
self.isSandbox = isSandbox
5152
super.init(endpoint: Self.verifyClientEndpoint, requestConfiguration: requestConfiguration)
5253
}

FirebaseAuth/Sources/Swift/SystemService/AuthAPNSTokenManager.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,11 @@
143143
}
144144

145145
// TODO: resolve https://github.com/firebase/firebase-ios-sdk/issues/10921
146-
if Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt" {
147-
// Distributed via TestFlight
148-
return defaultAppTypeProd
149-
}
146+
// to support TestFlight
150147

151-
let path = Bundle.main.bundlePath + "embedded.mobileprovision"
152-
guard let url = URL(string: path) else {
153-
AuthLog.logInfo(code: "I-AUT000007", message: "\(path) does not exist")
154-
return defaultAppTypeProd
155-
}
148+
let path = Bundle.main.bundlePath + "/" + "embedded.mobileprovision"
156149
do {
157-
let profileData = try Data(contentsOf: url)
150+
let profileData = try NSData(contentsOfFile: path) as Data
158151

159152
// The "embedded.mobileprovision" sometimes contains characters with value 0, which signals
160153
// the end of a c-string and halts the ASCII parser, or with value > 127, which violates
@@ -177,7 +170,7 @@
177170

178171
let scanner = Scanner(string: embeddedProfile)
179172
if scanner.scanUpToString("<plist") != nil {
180-
guard let plistContents = scanner.scanUpToString("</plist>"),
173+
guard let plistContents = scanner.scanUpToString("</plist>")?.appending("</plist>"),
181174
let data = plistContents.data(using: .utf8) else {
182175
return defaultAppTypeProd
183176
}
@@ -194,7 +187,8 @@
194187
message: "Provisioning profile has specifically provisioned devices, " +
195188
"most likely a Dev profile.")
196189
}
197-
guard let apsEnvironment = plistMap["Entitlements.aps-environment"] as? String else {
190+
guard let entitlements = plistMap["Entitlements"] as? [String: Any],
191+
let apsEnvironment = entitlements["aps-environment"] as? String else {
198192
AuthLog.logInfo(code: "I-AUT000013",
199193
message: "No aps-environment set. If testing on a device APNS is not " +
200194
"correctly configured. Please recheck your provisioning profiles.")

FirebaseAuth/Tests/SampleSwift/AuthenticationExample.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@
794794
"$(inherited)",
795795
"@executable_path/Frameworks",
796796
);
797-
PRODUCT_BUNDLE_IDENTIFIER = com.google.FirebaseExperimental1;
797+
PRODUCT_BUNDLE_IDENTIFIER = com.google.firebaseAuthSDKSampleApp.dev;
798798
PRODUCT_NAME = "$(TARGET_NAME)";
799799
PROVISIONING_PROFILE_SPECIFIER = "";
800800
SWIFT_VERSION = 5.0;
@@ -817,7 +817,7 @@
817817
"$(inherited)",
818818
"@executable_path/Frameworks",
819819
);
820-
PRODUCT_BUNDLE_IDENTIFIER = com.google.FirebaseExperimental1;
820+
PRODUCT_BUNDLE_IDENTIFIER = com.google.firebaseAuthSDKSampleApp.dev;
821821
PRODUCT_NAME = "$(TARGET_NAME)";
822822
PROVISIONING_PROFILE_SPECIFIER = "";
823823
SWIFT_VERSION = 5.0;

FirebaseAuth/Tests/SampleSwift/AuthenticationExample.xcodeproj/xcshareddata/xcschemes/AuthenticationExample.xcscheme

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@
8181
ReferencedContainer = "container:AuthenticationExample.xcodeproj">
8282
</BuildableReference>
8383
</BuildableProductRunnable>
84+
<CommandLineArguments>
85+
<CommandLineArgument
86+
argument = "-FIRDebugEnabled"
87+
isEnabled = "YES">
88+
</CommandLineArgument>
89+
</CommandLineArguments>
8490
</LaunchAction>
8591
<ProfileAction
8692
buildConfiguration = "Release"

FirebaseAuth/Tests/SampleSwift/AuthenticationExampleUITests/SettingsUITests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class SettingsUITests: XCTestCase {
5050

5151
// Swap Firebase App
5252
let appCell = app.cells.containing(.staticText, identifier: "Active App").element
53-
XCTAssertTrue(appCell.staticTexts["gcip-ios-test"].exists)
53+
XCTAssertTrue(appCell.staticTexts["fir-ios-auth-sample"].exists)
5454
appCell.tap()
5555
XCTAssertTrue(appCell.staticTexts["fb-sa-upgraded"].exists)
5656
appCell.tap()
57-
XCTAssertTrue(appCell.staticTexts["gcip-ios-test"].exists)
57+
XCTAssertTrue(appCell.staticTexts["fir-ios-auth-sample"].exists)
5858

5959
// Current Access Group
6060
let accessCell = app.cells.containing(.staticText, identifier: "Current Access Group").element

FirebaseAuth/Tests/SampleSwift/ObjCApiTests/AccountInfoTests.m

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,52 +51,15 @@ - (void)testUpdatingUsersEmailAlreadyInUse {
5151
XCTFail(@"Could not obtain auth object.");
5252
}
5353

54-
__block NSError *apiError;
5554
XCTestExpectation *expectation =
5655
[self expectationWithDescription:@"Created account with email and password."];
5756
[auth createUserWithEmail:kOldUserEmail
5857
password:@"password"
5958
completion:^(FIRAuthDataResult *user, NSError *error) {
60-
if (error.code != FIRAuthErrorCodeEmailAlreadyInUse) {
61-
apiError = error;
62-
}
59+
XCTAssertEqual(error.code, FIRAuthErrorCodeEmailAlreadyInUse);
6360
[expectation fulfill];
6461
}];
6562
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
6663
}
6764

68-
- (void)testUpdatingUsersEmail {
69-
SKIP_IF_ON_MOBILE_HARNESS
70-
FIRAuth *auth = [FIRAuth auth];
71-
if (!auth) {
72-
XCTFail(@"Could not obtain auth object.");
73-
}
74-
75-
__block NSError *apiError;
76-
XCTestExpectation *expectation = [self expectationWithDescription:@"Updating email"];
77-
[auth signInWithEmail:kOldUserEmail
78-
password:@"password"
79-
completion:^(FIRAuthDataResult *_Nullable authResult, NSError *_Nullable error) {
80-
apiError = error;
81-
[expectation fulfill];
82-
}];
83-
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
84-
85-
XCTAssertEqualObjects(auth.currentUser.email, kOldUserEmail);
86-
XCTAssertNil(apiError);
87-
88-
expectation = [self expectationWithDescription:@"Update email address."];
89-
[auth.currentUser updateEmail:kNewUserEmail
90-
completion:^(NSError *_Nullable error) {
91-
apiError = error;
92-
[expectation fulfill];
93-
}];
94-
[self waitForExpectationsWithTimeout:kExpectationsTimeout handler:nil];
95-
XCTAssertNil(apiError);
96-
XCTAssertEqualObjects(auth.currentUser.email, kNewUserEmail);
97-
98-
// Clean up the created Firebase user for future runs.
99-
[self deleteCurrentUser];
100-
}
101-
10265
@end

FirebaseAuth/Tests/SampleSwift/SwiftApiTests/AccountInfoTests.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ class AccountInfoTests: TestsBase {
6363
expectation2.fulfill()
6464
}
6565
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
66-
67-
let expectation3 = expectation(description: "Update email address.")
68-
auth.currentUser?.updateEmail(to: kNewUserEmail) { error in
69-
XCTAssertNil(error)
70-
XCTAssertEqual(auth.currentUser?.email,
71-
self.kNewUserEmail,
72-
"Signed user does not match change.")
73-
expectation3.fulfill()
74-
}
75-
waitForExpectations(timeout: TestsBase.kExpectationsTimeout)
7666
}
7767

7868
func testUpdatingUsersEmailAsync() async throws {
@@ -91,10 +81,5 @@ class AccountInfoTests: TestsBase {
9181
XCTAssertEqual(auth.currentUser?.email,
9282
kOldUserEmail,
9383
"Signed user does not match request.")
94-
95-
try await auth.currentUser?.updateEmail(to: kNewUserEmail)
96-
XCTAssertEqual(auth.currentUser?.email,
97-
kNewUserEmail,
98-
"Signed user does not match change.")
9984
}
10085
}

FirebaseAuth/Tests/SampleSwift/SwiftApiTests/Credentials.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,19 @@ import Foundation
4949
*/
5050

5151
enum Credentials {
52+
/// The `CLIENT_ID` key from a`GoogleService-Info.plist`. If this cannot be
53+
/// found, enable Google Sign In enabled as an authentication provider in the
54+
/// corresponding Firebase project and re-download the
55+
/// `GoogleService-Info.plist`.
5256
static let kGoogleClientID = KGOOGLE_CLIENT_ID
57+
/// This is the refresh token associated with the
58+
/// `[email protected]` test acount.
59+
/// In the event this token needs to be generated, this refresh token is
60+
/// returned upon successful sign-in via GSI via the `GIDSignInResult`'s
61+
/// `user.refreshToken.tokenString` property.
5362
static let kGoogleTestAccountRefreshToken = KGOOGLE_TEST_ACCOUNT_REFRESH_TOKEN
63+
/// This is the display name for the `[email protected]` test
64+
/// account.
5465
static let kGoogleUserName = KGOOGLE_USER_NAME
5566
static let kFacebookAppID = KFACEBOOK_APP_ID
5667
static let kFacebookAppAccessToken = KFACEBOOK_APP_ACCESS_TOKEN

FirebaseAuth/Tests/SampleSwift/SwiftApiTests/GoogleTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class GoogleTests: TestsBase {
4747
accessToken: googleAccessToken)
4848
_ = try await auth.signIn(with: credential)
4949
let displayName = try XCTUnwrap(auth.currentUser?.displayName)
50-
XCTAssertEqual(displayName, "apitests ios")
50+
XCTAssertEqual(displayName, Credentials.kGoogleUserName)
5151
}
5252

5353
/// Sends http request to Google OAuth2 token server to use refresh token to exchange for Google

0 commit comments

Comments
 (0)