在我的应用程序中,用户可以使用电子邮件/密码验证/登录到我的后端。现在我也在考虑实现touch ID。
但我对使用触摸ID的登录流感到困惑。
使用以下代码,我可以轻松地对用户进行身份验证:
func authenticateUser() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Identify yourself!"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
[unowned self] success, authenticationError in
DispatchQueue.main.async {
if success {
self.runSecretCode()
} else {
let ac = UIAlertController(title: "Authentication failed", message: "Sorry!", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
self.present(ac, animated: true)
}
}
}
} else {
let ac = UIAlertController(title: "Touch ID not available", message: "Your device is not configured for Touch ID.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default))
present(ac, animated: true)
}
}但我不知道是哪个用户。
因此,当用户创建帐户时,我是否应该在我的数据库中存储设备ID (如果存在),然后当用户使用触摸ID时,我可以检查它是什么设备ID,然后让用户登录?
发布于 2018-12-13 07:39:48
据我所知,touch ID只是作为本机应用程序本身的看门人,而不是API。
无论如何,您的用户必须至少使用API进行一次身份验证才能获得某种类型的秘密令牌(JWT等),然后在关闭/打开应用程序时将其持久化。在你的应用程序开始调用API之前,Touch ID必须是成功的,但API只会根据秘密进行验证。
这样,您可以在不保存凭据的情况下保持用户的登录,并且您在应用程序上具有touch ID,以防止不想要的用户拿起解锁的手机,只打开银行应用程序。
这就是我对它的理解,但如果我错了,请有人纠正我。
https://stackoverflow.com/questions/41048805
复制相似问题