Is session used to REST authentication?

2019-06-23 19:16发布

Sorry for the noobish question, this is the first time i try to implement a REST interface (in PHP). Anyway, because the stateless nature of HTTP protocol, what's the best practice in order to ensure that:

GET/ /user/{id}/friends

is always and only executed by the current authenticated user? Is session usually used as a method to restrict REST access?

1条回答
乱世女痞
2楼-- · 2019-06-23 20:03

You can use HTTP sessions, which are nothing more than server-side cookies. They're usually ok, but there has been a lot of reports of session hijacking lately. So my answer if you're really concerned about this is to use HMAC. It's tricky to set up, but once it is you can be sure that the message really did come from an authenticated user.

查看更多
登录 后发表回答