0

I've been playing around with UITextField's password autofill feature for logging into my backend, and as of yet I've been unable to find a way to actually confirm or validate that the user has authenticated via TouchID to access their passwords.

Am I crazy or because this feature is so baked in to iOS, we can't actually check to see if the user was able to successfully authenticate?

Or am I missing some kind of delegate call in the LocalAuthentication API that gets called?

TIA for your help.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
  • Show the code please. – meaning-matters Dec 26 '17 at 19:06
  • @meaning-matters there is literally no code to turning a UITextField into a password field and invoking the Safari AutoFill manager. This is done in Interface Builder. – David Strauss Dec 26 '17 at 19:32
  • Which is why I'm wondering if I'm missing a delegate call or something that is called by the text field. – David Strauss Dec 26 '17 at 19:33
  • You don't get a specific notification that the user has authenticated to unlock the keychain password store since they haven't actually authenticated to your app at this point. You should get an indication via the text field delegate that it now has content. You still need to submit the credentials to your backend to validate them. It shouldn't matter to your App whether the user used stored credentials or typed them in. You will get a notification that your app has resigned active when the Touch ID prompt is displayed and it will resume active once the user has finished – Paulw11 Dec 26 '17 at 20:21
  • @Paulw11 I see what you're saying. I've gone ahead and just implemented a custom control to make my life easier. Thanks for your assistance. – David Strauss Dec 27 '17 at 23:43

1 Answers1

0

I use a method like this with a callback with the result, sometimes I store off the result to look up later on in the session. Not sure if this is what you're looking for, or if you needed something more advanced. This is part of a class for me where I have made my own delegates that I call on authentication or failure as well.

private func authenticateUser(completion: @escaping (Bool)->()) {
    let context = LAContext()
    var error:NSError?
    let reason = "Authenticate for access"

    context.localizedFallbackTitle = ""

    if(context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)){
        context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason, reply: { (success, error) -> Void in
            if(success){
                completion(true)
            } else {
                completion(false)
            }
        })
    }
}
g1231s49
  • 26
  • 6
  • Hi Paul, thanks for the quick response. I also have a similar method that I can invoke wherever/whenever, but I'm referencing the "freebie" given to us in the form of the Safari AutoFill manager when you designate a UITextField as a Password field. It seems that Apple has not supplied us with any way to confirm the user has authenticated using this method. – David Strauss Dec 26 '17 at 19:29
  • Sorry, I'm no help there. It doesn't appear there is a confirmation that it came with biometrics. – g1231s49 Dec 26 '17 at 19:40