Skip to content

Commit

Permalink
[Auth] Refactor MultiFactor.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Dec 10, 2024
1 parent e0eaaea commit 965f0e3
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 additions & 4 deletions FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,31 @@ import Foundation
displayName: String?,
completion: ((Error?) -> Void)?) {
// TODO: Refactor classes so this duplicated code isn't necessary for phone and totp.

guard
assertion.factorID == PhoneMultiFactorInfo.TOTPMultiFactorID ||
assertion.factorID == PhoneMultiFactorInfo.TOTPMultiFactorID
else {
return
}

guard let user = user, let auth = user.auth else {

Check warning on line 78 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

immutable value 'auth' was never used; consider replacing with '_' or removing it

Check warning on line 78 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, iOS spm)

immutable value 'auth' was never used; consider replacing with '_' or removing it
fatalError("Internal Auth error: failed to get user enrolling in MultiFactor")
}

var request: FinalizeMFAEnrollmentRequest? = nil

Check warning on line 82 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

variable 'request' was never used; consider replacing with '_' or removing it

Check warning on line 82 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, iOS spm)

variable 'request' was never used; consider replacing with '_' or removing it
if assertion.factorID == PhoneMultiFactorInfo.TOTPMultiFactorID {
guard let totpAssertion = assertion as? TOTPMultiFactorAssertion else {
fatalError("Auth Internal Error: Failed to find TOTPMultiFactorAssertion")
}
switch totpAssertion.secretOrID {
case .enrollmentID: fatalError("Missing secret in totpAssertion")
case let .secret(secret):
guard let user = user, let auth = user.auth else {
fatalError("Internal Auth error: failed to get user enrolling in MultiFactor")
}
let finalizeMFATOTPRequestInfo =

Check warning on line 90 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

initialization of immutable value 'finalizeMFATOTPRequestInfo' was never used; consider replacing with assignment to '_' or removing it

Check warning on line 90 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, iOS spm)

initialization of immutable value 'finalizeMFATOTPRequestInfo' was never used; consider replacing with assignment to '_' or removing it
AuthProtoFinalizeMFATOTPEnrollmentRequestInfo(sessionInfo: secret.sessionInfo,
verificationCode: totpAssertion
.oneTimePassword)
<<<<<<< Updated upstream

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (AuthenticationExampleUITests)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, tvOS spm)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, watchOS spm)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, visionOS spm)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, catalyst spm)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (SwiftApiTests)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (ObjCApiTests)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, macOS spmbuildonly)

source control conflict marker in source file

Check failure on line 94 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, iOS spm)

source control conflict marker in source file
let request = FinalizeMFAEnrollmentRequest(idToken: self.user?.rawAccessToken(),
displayName: displayName,
totpVerificationInfo: finalizeMFATOTPRequestInfo,
Expand All @@ -106,13 +117,63 @@ import Foundation
completion(error)
}
}
=======
request = FinalizeMFAEnrollmentRequest(idToken: self.user?.rawAccessToken(),
displayName: displayName,
totpVerificationInfo: finalizeMFATOTPRequestInfo,
requestConfiguration: user
.requestConfiguration)
}
} else if assertion.factorID == PhoneMultiFactorInfo.PhoneMultiFactorID {
let phoneAssertion = assertion as? PhoneMultiFactorAssertion
guard let credential = phoneAssertion?.authCredential else {
fatalError("Internal Error: Missing credential")
}
switch credential.credentialKind {
case .phoneNumber: fatalError("Internal Error: Missing verificationCode")
case let .verification(verificationID, code):
let finalizeMFAPhoneRequestInfo =
AuthProtoFinalizeMFAPhoneRequestInfo(
sessionInfo: verificationID,
verificationCode: code
)
request = FinalizeMFAEnrollmentRequest(
idToken: self.user?.rawAccessToken(),
displayName: displayName,
phoneVerificationInfo: finalizeMFAPhoneRequestInfo,
requestConfiguration: user.requestConfiguration
)
}
}

guard let request else {
// Assertion is not a phone assertion or TOTP assertion.
return
}

Task {
do {
let response = try await AuthBackend.call(with: request)
do {
let user = try await auth.completeSignIn(withAccessToken: response.idToken,
accessTokenExpirationDate: nil,
refreshToken: response.refreshToken,
anonymous: false)
try auth.updateCurrentUser(user, byForce: false, savingToDisk: true)
if let completion {
DispatchQueue.main.async {
completion(nil)
>>>>>>> Stashed changes
}
} catch {
}
} catch {

Check failure on line 169 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, tvOS spm)

consecutive declarations on a line must be separated by ';'

Check failure on line 169 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, tvOS spm)

expected declaration

Check failure on line 169 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (ObjCApiTests)

consecutive declarations on a line must be separated by ';'

Check failure on line 169 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (ObjCApiTests)

expected declaration
DispatchQueue.main.async {
if let completion {
completion(error)
}
}
}
<<<<<<< Updated upstream

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (AuthenticationExampleUITests)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, tvOS spm)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, watchOS spm)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, visionOS spm)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, catalyst spm)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (SwiftApiTests)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (ObjCApiTests)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, macOS spmbuildonly)

source control conflict marker in source file

Check failure on line 176 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, iOS spm)

source control conflict marker in source file
}
return
} else if assertion.factorID != PhoneMultiFactorInfo.PhoneMultiFactorID {
Expand Down Expand Up @@ -162,6 +223,11 @@ import Foundation
if let completion {
completion(error)
}
=======
} catch {
if let completion {
completion(error)
>>>>>>> Stashed changes
}
}

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (AuthenticationExampleUITests)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, tvOS spm)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, watchOS spm)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, visionOS spm)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, catalyst spm)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (SwiftApiTests)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (ObjCApiTests)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, macOS spmbuildonly)

extraneous '}' at top level

Check failure on line 232 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, iOS spm)

extraneous '}' at top level
}

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (AuthenticationExampleUITests)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, tvOS spm)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, watchOS spm)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, visionOS spm)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, catalyst spm)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (SwiftApiTests)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / integration-tests (ObjCApiTests)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, macOS spmbuildonly)

extraneous '}' at top level

Check failure on line 233 in FirebaseAuth/Sources/Swift/MultiFactor/MultiFactor.swift

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.1, iOS spm)

extraneous '}' at top level
Expand Down

0 comments on commit 965f0e3

Please sign in to comment.