Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
use touchid for tup where available
Browse files Browse the repository at this point in the history
  • Loading branch information
btoews committed Jun 8, 2017
1 parent 10b2c07 commit e2002e9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions SoftU2FTool/UserPresence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import Foundation
import LocalAuthentication

class UserPresence: NSObject {
enum Notification {
Expand Down Expand Up @@ -63,6 +64,37 @@ class UserPresence: NSObject {

// Send a notification popup to the user.
func test(_ type: Notification) {
if #available(OSX 10.12.2, *) {
let ctx = LAContext()

if ctx.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
ctx.localizedCancelTitle = "Cancel"
ctx.localizedFallbackTitle = "Skip TouchID"

var prompt: String
switch type {
case let .Register(facet):
prompt = "register with " + (facet ?? "site")
case let .Authenticate(facet):
prompt = "authenticate with " + (facet ?? "site")
}

ctx.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: prompt) { (success, err) in
guard let lerr = err as? LAError else {
self.complete(success)
return
}

switch lerr.code {
case .userFallback:
self.sendNotification(type)
default:
self.complete(false)
}
}
return
}
}
sendNotification(type)
}

Expand Down

0 comments on commit e2002e9

Please sign in to comment.