在我的“REST API”中,我想使用一些基于令牌/基于 cookie 的身份验证。这意味着,在消费者可以使用 API 之前,消费者需要通过使用用户名/密码调用一些身份验证 URL 来获取此令牌。
只返回一个 Set-Cookie Header 可以吗?
我认为它实际上违反了 REST 原则,但是如果没有 HTTP Basic Auth(这意味着在每个请求中发送用户名/密码),你将如何做到(或设计 uris 和动词)?
也许像这样?
GET api/authentication/signin/?username=abc&pwd=123
GET api/authentication/signout
或者?
GET api/user/authtoken/?username=abc&pwd=123 (signin)
DELETE api/user/authtoken/ (signout)
GET api/user/ (returning details of the current user)
那么注册呢?
POST api/user/ (which would also return an authtoken)
或者?
GET api/user/abc/authtoken/?pwd=123 (signin of user abc)
DELETE api/user/abc/authtoken/ (signout)
GET api/user/abc/ (returning details of user abc)