开发者

Why do API's (like Facebook, last.fm etc) generate session keys for logged in users?

I am building an RESTful API for an application I am working on and client coders need to be able to submit data to the API on behalf of a user. All the popular API's I've used require me to send the generated session token 开发者_开发百科(created when a user is logged in) for the user with a request to post information on the users behalf.

My question out of curiosity is why do these API's require a session key and not just allow me to send the username and password again with each request?

Thanks.


The main reason is no doubt a security issue around passing sensitive data back and forth. Passing a session key means that if it is compromised it only has a limited lifespan for the attacker to use it. Also, if an attacker compromised the session key, they could not use that information to launch an attack against other websites that the user may have accounts with (and will likely use the same password).

Another reason to use the session key is that if the user changes their password whilst you are busy using the API's you will not suddenly be locked out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜