Skip to content

Commit

Permalink
Continuation was sometimes called twice. OATH error handlig improved.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Nov 25, 2024
1 parent 8e378e8 commit a9a1b3a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
4 changes: 1 addition & 3 deletions Authenticator/Model/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ class MainViewModel: ObservableObject {
}
}
} catch {
self?.sessionTask?.cancel()
// Only handle .otpEnabledError by presenting the disable OTP modal
if let sessionError = error as? OATHSessionError, sessionError == .otpEnabledError {
self?.sessionTask?.cancel()
self?.presentDisableOTP = true
} else {
guard let oathSessionError = error as? OATHSessionError, oathSessionError != .connectionCancelled else { return }
self?.connectionError = error
}
self?.sessionTask?.cancel()
}
}
}
Expand Down
35 changes: 25 additions & 10 deletions Authenticator/Model/OATHSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,37 @@ class OATHSessionHandler: NSObject, YKFManagerDelegate {
self.wiredConnectionCallback = { connection in
if connection.isKind(of: YKFSmartCardConnection.self) && deviceType == .phone {
connection.managementSession { session, error in
guard let session else { continuation.resume(throwing: error!); return }
guard let session else {
self.wiredContinuation?.resume(throwing: error!)
self.wiredContinuation = nil
self.wiredConnectionCallback = nil
return
}
session.getDeviceInfo { deviceInfo, error in
guard let deviceInfo else { continuation.resume(throwing: error!); return }
guard let configuration = deviceInfo.configuration else { continuation.resume(throwing: "Error!!!"); return }
guard let deviceInfo else {
self.wiredContinuation?.resume(throwing: error!)
self.wiredContinuation = nil
self.wiredConnectionCallback = nil
return
}
guard let configuration = deviceInfo.configuration else {
self.wiredContinuation?.resume(throwing: "Error!!!")
self.wiredContinuation = nil
self.wiredConnectionCallback = nil
return
}
guard !configuration.isEnabled(.OTP, overTransport: .USB) || SettingsConfig.isOTPOverUSBIgnored(deviceId: deviceInfo.serialNumber) else {
continuation.resume(throwing: OATHSessionError.otpEnabledError)
self.wiredContinuation?.resume(throwing: OATHSessionError.otpEnabledError)
self.wiredContinuation = nil
self.wiredConnectionCallback = nil
return
}
connection.oathSession { session, error in
if let session {
self.currentSession = session
continuation.resume(returning: OATHSession(session: session, type: .wired))
self.wiredContinuation?.resume(returning: OATHSession(session: session, type: .wired))
} else {
continuation.resume(throwing: error!)
self.wiredContinuation?.resume(throwing: error!)
}
self.wiredContinuation = nil
self.wiredConnectionCallback = nil
Expand All @@ -173,9 +188,9 @@ class OATHSessionHandler: NSObject, YKFManagerDelegate {
connection.oathSession { session, error in
if let session {
self.currentSession = session
continuation.resume(returning: OATHSession(session: session, type: .wired))
self.wiredContinuation?.resume(returning: OATHSession(session: session, type: .wired))
} else {
continuation.resume(throwing: error!)
self.wiredContinuation?.resume(throwing: error!)
}
self.wiredContinuation = nil
self.wiredConnectionCallback = nil
Expand All @@ -202,9 +217,9 @@ class OATHSessionHandler: NSObject, YKFManagerDelegate {
connection.oathSession { session, error in
if let session {
self.currentSession = session
continuation.resume(returning: OATHSession(session: session, type: .nfc))
self.nfcContinuation?.resume(returning: OATHSession(session: session, type: .nfc))
} else {
continuation.resume(throwing: error!)
self.nfcContinuation?.resume(throwing: error!)
}
self.nfcContinuation = nil
}
Expand Down

0 comments on commit a9a1b3a

Please sign in to comment.