Persist auth async

This commit is contained in:
Max Goedjen 2025-08-14 20:07:53 -07:00
parent 720ae72beb
commit 7ae52ef482
No known key found for this signature in database

View File

@ -182,7 +182,7 @@ extension SecureEnclave {
return persisted return persisted
} }
public func persistAuthentication(secret: Secret, forDuration duration: TimeInterval) throws { public func persistAuthentication(secret: Secret, forDuration duration: TimeInterval) async throws {
let newContext = LAContext() let newContext = LAContext()
newContext.touchIDAuthenticationAllowableReuseDuration = duration newContext.touchIDAuthenticationAllowableReuseDuration = duration
newContext.localizedCancelTitle = String(localized: "auth_context_request_deny_button") newContext.localizedCancelTitle = String(localized: "auth_context_request_deny_button")
@ -196,14 +196,12 @@ extension SecureEnclave {
} else { } else {
newContext.localizedReason = String(localized: "auth_context_persist_for_duration_unknown_\(secret.name)") newContext.localizedReason = String(localized: "auth_context_persist_for_duration_unknown_\(secret.name)")
} }
newContext.evaluatePolicy(LAPolicy.deviceOwnerAuthentication, localizedReason: newContext.localizedReason) { [weak self] success, _ in guard try await newContext.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: newContext.localizedReason) else { return }
guard success, let self else { return }
let context = PersistentAuthenticationContext(secret: secret, context: newContext, duration: duration) let context = PersistentAuthenticationContext(secret: secret, context: newContext, duration: duration)
self.persistedAuthenticationContexts.withLock { self.persistedAuthenticationContexts.withLock {
$0[secret] = context $0[secret] = context
} }
} }
}
public func reloadSecrets() async { public func reloadSecrets() async {
await reloadSecretsInternal(notifyAgent: false) await reloadSecretsInternal(notifyAgent: false)