RESTful WCF 4 服务中移动客户端的用户身份验证
我正在尝试开发一个供移动客户端(目前是 iOS 客户端)使用的 Web 服务,我读到 RESTful 服务比 SOAP 服务轻量得多,所以我想尝试一下。
大多数方法都需要身份验证,但我不确定如何处理这个问题,因为我读到 REST 应该是无状态的,所以我如何验证从 iOS 访问服务的用户,然后使用该身份验证来验证对其他方法的连续调用网络方法?
注意:我将使用 IIS 上的 WCF 4 WebHttp。
谢谢你!
I'm trying to develop a web service to be consumed by mobile clients (iOS clients, for now), I read that RESTful services are much more lightweight than SOAP services, so I'd like to try my hand at this.
Most methods will require authentication, but I'm not sure how to handle this, as I read REST is supposed to be stateless, so how can I validate the user accessing the service from iOS and then use that authentication to validate successive calls to other web methods?
Note: I'll be using WCF 4's WebHttp on IIS.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有许多相当成熟的模式可以做到这一点。
There are a number of fairly established patterns for doing this.
我建议使用类似于 OAuth 的策略。您将专门编写一项服务来验证凭据并分发访问令牌,并且对 API 的任何请求都需要有效的访问令牌。
如果您在 IIS 中托管,我会在使用 HttpModule 检查所有传入请求是否有有效令牌之前完成此操作。如果没有,模块只会以 401 Unauthorized Http 状态代码结束请求。
编辑:
如果您想在每个操作的基础上进行更细粒度的授权,我建议使用自定义授权策略。查看 http://msdn.microsoft.com/en-us/library/ms731181 .aspx 了解更多详细信息。
I would suggest using a strategy similar to OAuth. You would write one service specifically to validate credentials and hand out access tokens, and require a valid access token for any request to your API.
If you're hosting in IIS, I've accomplished this before using an HttpModule to inspect all incoming requests for a valid token. If there isn't one, the module just ends the request with a 401 Unauthorized Http status code.
EDIT:
If you'd like to do more fine-grained authorization on a per operation basis, I'd suggest using a custom authorization policy. Check out http://msdn.microsoft.com/en-us/library/ms731181.aspx for more details.