看起来ServiceStack只接受基于会话的身份验证。我正在阅读https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization,我找不到任何描述如何做我想要的事情。
我也看了http://enehana.nohea.com/general/customizing-iauthprovider-for-servicestack-net-step-by-step/,但这也是基于会话的。
我想做的是,与WebAPI如何与个人用户帐户配合使用非常相似。
我想将其发送到API:
POST http://localhost:49436/Token HTTP/1.1
User-Agent: Fiddler
Host: localhost:49436
Content-Type: application/x-www-form-urlencoded
Content-Length: 55
grant_type=password&username=Alice&password=password123
然后,如果在我的自定义身份验证方法中找到该用户,则返回以下内容:
{
"access_token":"boQtj0SCGz2GFGz[...]",
"token_type":"bearer",
"expires_in":1209599,
"userName":"Alice",
".issued":"Mon, 14 Oct 2013 06:53:32 GMT",
".expires":"Mon, 28 Oct 2013 06:53:32 GMT"
}
然后,客户端应用程序可以通过在HTTP请求中附加这样的值,在后续请求中发送access_token:
Authorization: Bearer boQtj0SCGz2GFGz[...]
这可以在ServiceStack中使用吗?
编辑:使用.NET的WebAPI实现:http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api