使用 PHP 为移动设备进行令牌身份验证
我正在编写一个 iPhone 应用程序作为我网站的移动版本。
我打算公开一些 REST API,以便应用程序可以更新用户的数据。
我不希望用户每次都登录,但我想保存他的令牌/cookie 并在以后的所有请求中重用它。
我可以设置一个随机令牌并将其与用户 ID 一起传递,但它不是很安全,因为在越狱设备上访问它很容易。我无法使用 IP 来限制它,因为 IP 可能会经常更改(因为它是移动设备)。
实现这种身份验证的最佳方法是什么,既足够安全,又不会要求用户经常对自己进行身份验证而惹恼用户?
I'm writing an iPhone app to be the mobile version of my website.
I intend to expose some REST API so the app can update the user's data.
I do not wish the user to login every time, but I want to save his token/cookie and reuse it for all future requests.
I can setup a random token and pass it along with the user ID, but it's not very secure since it's easy to access it on a jailbroken device. I cannot restrict it using an IP, since the IP will probably change frequently (since it's a mobile device).
What's the best way to implement such an authentication which will be secure enough but won't annoy the user by asking him to authenticate himself often?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 UDID 或 MAC 地址以及初始登录详细信息发送到您的服务器。为此用户/UDID(或 mac)组合创建一个唯一的令牌,如果用户名/密码成功,则将其发送回(加密)到设备。在后续访问时,设备会发送加密令牌和 UDID/mac(通过安全连接)以进行重新身份验证。
如果你想让偏执的人放心地跟踪 UDID,你可以使用 UDID/mac 来加盐加密令牌,但这不会那么安全,但仍然可以完成工作。
send the UDID or mac address with the initial login details to your server. create a unique token for this user/UDID (or mac) combination and send it back(encrypted) to the device if username/pass is successful. on subsequent access, the device sends the encrypted token and UDID/mac (over secure connection) for re-authentication.
if you want to put paranoid people at ease about tracking UDID, you could instead use the UDID/mac to salt the encrypted token, but this wont be as secure, but should do the job still.