Skip to content

Commit

Permalink
[Auth] Restore MFA request setup to Firebase 10 behavior (#13858)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 authored Oct 9, 2024
1 parent 2b75c5c commit 0e3e20d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 4 additions & 0 deletions FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased
- [Fixed] Restore Firebase 10 behavior by ignoring `nil` display names used
during multi factor enrollment. (#13856)

# 11.3.0
- [Fixed] Restore Firebase 10 behavior by querying with the
`kSecAttrSynchronizable` key when auth state is set to be shared across
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class FinalizeMFAEnrollmentRequest: IdentityToolkitRequest, AuthRPCRequest {
}
if let displayName = displayName {
body["displayName"] = displayName
if let phoneVerificationInfo {
body["phoneVerificationInfo"] = phoneVerificationInfo.dictionary
} else if let totpVerificationInfo {
body["totpVerificationInfo"] = totpVerificationInfo.dictionary
}
}
if let phoneVerificationInfo {
body["phoneVerificationInfo"] = phoneVerificationInfo.dictionary
} else if let totpVerificationInfo {
body["totpVerificationInfo"] = totpVerificationInfo.dictionary
}

if let tenantID = tenantID {
Expand Down
12 changes: 10 additions & 2 deletions FirebaseAuth/Tests/Unit/FinalizeMFAEnrollmentRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ class FinalizeMFAEnrollmentRequestTests: RPCBaseTests {
@brief Tests the Finalize MFA Enrollment using TOTP request.
*/
func testTOTPStartMFAEnrollmentRequest() async throws {
try await assertTOTPStartMFAEnrollmentRequest(displayName: "sparky")
}

func testTOTPStartMFAEnrollmentRequest_WhenDisplayNameIsNil() async throws {
try await assertTOTPStartMFAEnrollmentRequest(displayName: nil)
}

func assertTOTPStartMFAEnrollmentRequest(displayName: String?) async throws {
let kIDToken = "idToken"
let kDisplayName = "displayName"
let kSessionInfo = "sessionInfo"
Expand All @@ -40,7 +48,7 @@ class FinalizeMFAEnrollmentRequestTests: RPCBaseTests {
let requestInfo = AuthProtoFinalizeMFATOTPEnrollmentRequestInfo(sessionInfo: kSessionInfo,
verificationCode: kVerificationCode)
let request = FinalizeMFAEnrollmentRequest(idToken: kIDToken,
displayName: kDisplayName,
displayName: displayName,
totpVerificationInfo: requestInfo,
requestConfiguration: requestConfiguration)

Expand All @@ -55,7 +63,7 @@ class FinalizeMFAEnrollmentRequestTests: RPCBaseTests {
value: kIDToken
)
let requestDictionary = try XCTUnwrap(rpcIssuer.decodedRequest as? [String: AnyHashable])
XCTAssertEqual(requestDictionary[kDisplayName], kDisplayName)
XCTAssertEqual(requestDictionary[kDisplayName], displayName)
let totpInfo = try XCTUnwrap(requestDictionary[kTOTPVerificationInfo] as? [String: String])
XCTAssertEqual(totpInfo["verificationCode"], kVerificationCode)
XCTAssertNil(requestDictionary[kPhoneVerificationInfo])
Expand Down

0 comments on commit 0e3e20d

Please sign in to comment.