From 881e65d97fce0e246264b2cab01151db29693e30 Mon Sep 17 00:00:00 2001 From: Michiel Vrins Date: Thu, 23 Mar 2023 15:47:18 +0100 Subject: [PATCH] Fix a bug where pin auth events would not get sent correctly --- .../NativeBridge/Handlers/LoginHandler.swift | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/ios/Classes/NativeBridge/Handlers/LoginHandler.swift b/ios/Classes/NativeBridge/Handlers/LoginHandler.swift index 0dc23509..054145e1 100644 --- a/ios/Classes/NativeBridge/Handlers/LoginHandler.swift +++ b/ios/Classes/NativeBridge/Handlers/LoginHandler.swift @@ -23,17 +23,25 @@ class LoginHandler: NSObject { completion(.success) } + private func mapErrorFromPinChallenge(_ challenge: ONGPinChallenge) -> Error? { + if let error = challenge.error, error.code != ONGAuthenticationError.touchIDAuthenticatorFailure.rawValue { + return error + } else { + return nil + } + } + func handleDidReceiveChallenge(_ challenge: ONGPinChallenge) { pinChallenge = challenge - guard challenge.error?.code != ONGAuthenticationError.touchIDAuthenticatorFailure.rawValue else { - SwiftOneginiPlugin.flutterApi?.n2fOpenPinScreenAuth {} + guard mapErrorFromPinChallenge(challenge) == nil else { + let authAttempt = OWAuthenticationAttempt( + failedAttempts: Int64(challenge.previousFailureCount), + maxAttempts: Int64(challenge.maxFailureCount), + remainingAttempts: Int64(challenge.remainingFailureCount)) + SwiftOneginiPlugin.flutterApi?.n2fNextAuthenticationAttempt(authenticationAttempt: authAttempt) {} return } - let authAttempt = OWAuthenticationAttempt( - failedAttempts: Int64(challenge.previousFailureCount), - maxAttempts: Int64(challenge.maxFailureCount), - remainingAttempts: Int64(challenge.remainingFailureCount)) - SwiftOneginiPlugin.flutterApi?.n2fNextAuthenticationAttempt(authenticationAttempt: authAttempt) {} + SwiftOneginiPlugin.flutterApi?.n2fOpenPinScreenAuth {} } func handleDidAuthenticateUser() {