Apple security for developers
Ask for Touch ID before releasing a secret (LocalAuthentication and Keychain)
Two ways to require Touch ID on a Mac: LocalAuthentication for a prompt, and Keychain access control so the system itself refuses without a fingerprint.
Updated 8 October 2026 3 min read
The short answer
For a quick confirmation, use LAContext.evaluatePolicy. To truly protect a secret, store it in the Keychain with a SecAccessControl that requires .userPresence or .biometryCurrentSet: then macOS demands Touch ID before it hands the item over, and no code path in your app can skip it.
A Touch ID prompt with LocalAuthentication
import LocalAuthentication
func confirmWithTouchID(reason: String) async -> Bool {
let context = LAContext()
var error: NSError?
// .deviceOwnerAuthentication falls back to the Mac password; ...WithBiometrics doesn't
guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else { return false }
return (try? await context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason)) ?? false
}This is a UI check. It’s fine for “are you sure?”, but a secret guarded only by if await confirmWithTouchID(...) is guarded by your app’s logic, not by the system.
Make the Keychain demand it
let access = SecAccessControlCreateWithFlags(
nil,
kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
.userPresence, // Touch ID or the Mac password; use .biometryCurrentSet for Touch ID only
nil
)!
let add: [String: Any] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrService as String: "stripe-restricted-key",
kSecAttrAccount as String: NSUserName(),
kSecValueData as String: Data(secret.utf8),
kSecAttrAccessControl as String: access,
kSecUseDataProtectionKeychain as String: true,
]
SecItemAdd(add as CFDictionary, nil)Now every SecItemCopyMatching for this item shows the system Touch ID sheet. Pass an LAContext with kSecUseAuthenticationContext to set the reason text or reuse one authentication for a few reads.
When to ask
Ask when exposure widens: the first time a new agent gets a key, when a key is used for something that changes money or data, and when a secret leaves your Mac. Asking for everything trains people to tap without reading; asking for nothing defeats the point.
The safe way to do this
The Human Queue for Stripe
Your agent proposes, you approve with Touch ID
MoltenRock Connect puts Touch ID where it matters most: every change an agent proposes on Stripe waits for your fingerprint.
See it workingQuestions developers ask
What is the difference between .userPresence and .biometryCurrentSet?
.userPresence accepts Touch ID or the device password. .biometryCurrentSet accepts only the fingerprints enrolled now, and invalidates the item if they change.
Does evaluatePolicy protect my data?
No. It returns true or false to your code. Protection comes from Keychain access control, which the system enforces.
Does this work without Touch ID hardware?
With .userPresence, yes: macOS falls back to the account password. With .biometryCurrentSet it fails on Macs without Touch ID.