当托管在 IIS 中时,使用 HTTPS 进行 Webhttp 绑定并使用 UserNamepPasswordValidator 进行身份验证
我正在尝试设置托管在 IIS 中的 WCF 服务,该服务公开充当生成 JSON 数据的 REST 服务的端点,并且我想使用 HTTPS。我想在 UserNamePasswordValidator 的帮助下自己处理用户身份验证,因为用户存储在数据库中。
目前我正在使用 webhttpbinding 来实现 REST 功能。当我尝试启用 HTTPS(将安全模式设置为传输)时,我的问题开始出现。我在服务器端有一个 SSL 证书(目前是自签名),所以这一切都很好,但我不知道如何配置绑定的传输 clientCredentialType 以便将凭据传递到我的 UserNamePasswordValidator 实现。
我用谷歌搜索了很多,但似乎找不到任何好东西。如果我理解正确的话,IIS会在WCF之前处理身份验证,并且没有什么可做的?我真的不想使用 ASP.Net 会员提供商,但也许这是一种方法,或者还有其他方法吗?
谢谢你!
编辑:找到 这个。并不是我真正希望的......
I'm trying to set up a WCF service hosted in IIS that exposes an endpoint that acts as a REST service producing JSON data, and I want to use HTTPS. I want to take care of the user authentication myself with the help of UserNamePasswordValidator, since the users are stored in a database.
At the moment I'm using a webhttpbinding to achieve the REST-fulness. My problem starts when I try to enable HTTPS (setting security mode to Transport). I have an SSL certificate on the server side (self signed for now), so that is all good, but I don't know how to configure the transport clientCredentialType of the binding so that the credentials are passed on to my implementation of UserNamePasswordValidator.
I've googled a lot, but can't seem to find any thing good. If I understand it correctly IIS handles the authentication before WCF and there is nothing to do about it? I would really prefer not to use a ASP.Net membership provider, but maybe that is an approach or is there another way?
Thank you!
Edit: Found this. Not really what I was hoping for...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用
UserName
凭据 - 即通过 SOAP 标头进行消息级身份验证,但 JSON 数据交换没有此类标头。尝试在传输元素中设置Basic
凭据(=传输级别身份验证)。 自 .NET 3.5 起它应该与自定义密码验证器一起使用。您必须传递有效的 HTTP 标头进行基本身份验证才能成功进行身份验证。编辑:
我没有使用 IIS 进行测试,因此可能会出现一些问题,因为 IIS 在执行自定义验证器之前触发身份验证。在这种情况下,您将需要自定义 HTTP 模块进行身份验证。
You can't use
UserName
credentials - that is message level authentication through SOAP header but JSON data exchange doesn't have such header. Try to setupBasic
credentials in transport element (= transport level authentication). It should work with custom password validator since .NET 3.5. You will have to pass valid HTTP header for basic authentication to successfully authenticate.Edit:
I didn't test it with IIS so there can be some problems because IIS trigger authentication before the custom validator is executed. In such case you will need custom HTTP module for authentication.
经过大量谷歌搜索后,我找到了一些可能的解决方案。
推荐方式要解决 IIS 中托管的 RESTful WCF 服务的身份验证问题,似乎需要使用令牌。借助 OAuth 的第三方实现或实现您的自我。但是,这会给我的 nettcp 端点带来一些问题,并且我可能无法对两个端点使用相同的实现(因为我需要对通过 webhttp 端点进行的调用进行一些令牌验证)
Ladislav Mrnka 给出的解决方案似乎也是有效的。
After a lot of googleing around I have found a couple of possible solutions.
The recommended way to solve authentication with RESTful WCF services hosted in IIS seems to be to use tokens. Either with the help of a third party implementation of OAuth or to implement something your self. However, this will give me some problems with my nettcp endpoint, and I probably won't be able to use the same implementation for both endpoints (since i will need to do some token validation on calls coming via the webhttp endpoint)
The solution given by Ladislav Mrnka appears to be valid as well.