RESTAPI身份验证-这就足够了吗?
我一直试图在RESTAPI身份验证-这就足够了吗?,api,rest,authentication,Api,Rest,Authentication,我一直试图在restapi上进行身份验证 我试图想出一种成功验证用户身份的方法,记住用户可以访问客户端上的所有数据,我想到了这个想法 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
restapi
上进行身份验证
我试图想出一种成功验证用户身份的方法,记住用户可以访问客户端上的所有数据,我想到了这个想法
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
这是一种正确的方法吗?您是否发现了任何安全缺陷?您正在有效地将会话状态存储在服务器上,这是不应该在RESTful API上执行的操作 RESTful API上的身份验证应该简单地遵循底层协议的标准化身份验证方法。与重新发明HTTP身份验证不同,您应该简单地要求客户端在每个请求上使用
授权
头通过HTTP Basic Auth进行身份验证。显然,所有的客户机-服务器交互都应该通过SSL完成
如果您确实需要某个具有过期日期的身份验证令牌,则在客户端使用basic(如签名的时间戳)进行身份验证后,您可以拥有一个资源来提供该令牌,但客户端仍应在
授权
头中使用自定义域发送该令牌,服务器上不应存储任何状态。您也可以使用随机UUID而不是散列字符串,如果salt是可预测的,可能更安全,那么可以在知道其他参数的情况下生成有效的散列。