我们正在建立系统,需要所有页面的登录信息。该应用程序设计为Restful应用程序,使用编解码器作为菲尔斯特金库。这个库只使用API密钥通过HTTPS连接发送每个请求来授权api调用。
即使它使用双向身份验证或仅使用API密钥。我正在寻找的是以下场景:
- API KEY should be provided by the server to the client as a resource identified by this username (**Here is the question???!!!**)
- **How to send the API Key to the client in a secure way?** - **1)** Could i use session-cookies and restore the API KEY in a cookie then use this API KEY on every coming request (This is violent the Stateless of the Rest and i don't sure if it securely enough).
- **2)** Actually i don't know other options :) it's your turn if you could help
如果你能举个例子,这将是一个很大的帮助,因为我发现和阅读了很多文章。
:)
发布于 2013-06-28 18:11:30
因为连接是HTTPS,所以您通过线路发送的任何东西都是安全的(理论上来说是安全的,前提是您不是mitm'd)。不确定整个API是否在HTTPS之上服务(您没有指定),所以即使您可以将密钥作为登录的一部分返回(尽管仍然处于HTTPS的保护伞下),如果其他api不是HTTPS,那么在下一个请求中也可以监听密钥。
会话和cookie通常不是RESTful应用程序的一部分;REST是无状态的。
像循环键这样的东西对非HTTPS来说会更好(也适用于HTTPS)。您通过HTTPS登录,服务器返回api密钥,在下一个请求中使用它,服务器返回新的api密钥,在下一个请求中使用它,依此类推。虽然它比非HTTPS上的一个api密钥更好,但它并不完美。如果有人从后续请求中嗅探到响应,而您最终没有使用该密钥,那么他们可以使用它。这会将攻击矢量缩小为从服务器到客户端的非HTTPS响应,因为如果嗅探了来自客户端到服务器的请求,您的合法请求就已经使用了api密钥。但是,如果您没有通过HTTPS提供api,那么还需要做更多的工作来保护api。
如果是我,我会查看请求签名+ https。这里有一些关于请求签名的讨论:https://stackoverflow.com/a/8567909/183254
在保护http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/的API部分,还有一些关于摘要auth的信息
客户端上的伪代码示例js函数。
function get_calendar(){
var key = $('#api_key').value();
$.ajax({
type: 'get',
url: '/index.php/api/calendar?key=' + key,
success: function(response){
// show calendar
// ...
// set received api key in hidden field with id api_key
$('#api_key').value(response.api_key)
}
})
}示例控制器方法:
function calendar_get($api_key = ''){
if($api_key_matches){//verify incoming api key
$r = array();
$r['calendar'] = $this->some_model->get_calendar();
$r['api_key'] = $this->_generate_api_key();// generate or get api key
}
$this->response($r);
}https://stackoverflow.com/questions/17298152
复制相似问题