我一直试图在REST API上进行身份验证。
我试图想出一种成功验证用户身份的方法,记住用户可以访问客户端上的所有数据,我想出了这个想法。
Client sends username and password to the server
Server checks if they match a user.
If it does, we create a hashed string with user_id+e-mail+currentTime+salt
and stores this in a database-table with an expiration date.
Server returns hashed string to client
Client sends random request to server including key
Server checks if key is correct and if it's expired这是一种正确的方法吗?你看到安全漏洞了吗?
发布于 2013-11-10 15:26:23
在服务器上有效地存储会话状态,这在RESTful API上是不应该做的。
RESTful API上的身份验证应该简单地遵循底层协议的标准身份验证方法。与其重新创建HTTP身份验证,您应该只要求客户端在每个请求上使用Authorization头通过HTTP进行身份验证。显然,您的所有客户机-服务器交互都应该通过SSL完成。
如果您确实需要一些带有过期日期的身份验证令牌,您可以拥有一个资源,一旦客户端使用basic (如签名时间戳)进行身份验证后,就可以提供该令牌,但是客户端仍然应该在Authorization标头中发送该标记,并具有自定义域,并且服务器上不应该存储任何状态。
https://stackoverflow.com/questions/19891405
复制相似问题