Skip to content

Commit

Permalink
Bugfix FXIOS-9014 ⁃ Unauthorized access for http authentication prompt (
Browse files Browse the repository at this point in the history
#20021)

* FXIOS-9014 #19912 ⁃ Unauthorized access for http authentication prompt

* FXIOS-9014 #19912 ⁃ Unauthorized access for http authentication prompt

Replaced (URLCredential?, _ isSuccess: Bool) -> Void with (Result<URLCredential?, Error>) -> Void
  • Loading branch information
dicarobinho authored Apr 30, 2024
1 parent 7032936 commit 27af704
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions firefox-ios/Client/Frontend/Browser/Authenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,23 @@ class Authenticator {
findMatchingCredentialsForChallenge(
challenge,
fromLoginsProvider: loginsHelper.logins
) { credentials in
) { result in
DispatchQueue.main.async {
guard let credentials = credentials else {
switch result {
case .success(let credentials):
self.promptForUsernamePassword(
viewController,
credentials: credentials,
protectionSpace: challenge.protectionSpace,
loginsHelper: loginsHelper,
completionHandler: completionHandler
)
case .failure:
sendLoginsAutofillFailedTelemetry()
completionHandler(.failure(
LoginRecordError(description: "Unknown error when finding credentials")
))
return
}
self.promptForUsernamePassword(
viewController,
credentials: credentials,
protectionSpace: challenge.protectionSpace,
loginsHelper: loginsHelper,
completionHandler: completionHandler
)
}
}
return
Expand All @@ -90,13 +91,13 @@ class Authenticator {
_ challenge: URLAuthenticationChallenge,
fromLoginsProvider loginsProvider: RustLogins,
logger: Logger = DefaultLogger.shared,
completionHandler: @escaping (URLCredential?) -> Void
completionHandler: @escaping (Result<URLCredential?, Error>) -> Void
) {
loginsProvider.getLoginsFor(protectionSpace: challenge.protectionSpace, withUsername: nil) { result in
switch result {
case .success(let logins):
guard logins.count >= 1 else {
completionHandler(nil)
completionHandler(.success(nil))
return
}

Expand Down Expand Up @@ -133,9 +134,9 @@ class Authenticator {
loginsProvider.updateLogin(id: login.id, login: new) { result in
switch result {
case .success:
completionHandler(credentials)
case .failure:
completionHandler(nil)
completionHandler(.success(credentials))
case .failure(let error):
completionHandler(.failure(error))
}
}
return
Expand All @@ -150,10 +151,10 @@ class Authenticator {
category: .webview)
}

completionHandler(credentials)
completionHandler(.success(credentials))

case .failure:
completionHandler(nil)
case .failure(let error):
completionHandler(.failure(error))
}
}
}
Expand Down

0 comments on commit 27af704

Please sign in to comment.