IIS 模块和 WCF
我编写了一个 IIS 模块(基本 IHttpModule),它在使用 WCF REST 服务之前执行一些自定义 (OpenAuth) 身份验证。 我已经扩展了 GenericPrincipal 来使用 IIdentity 来跟踪我的用户,并设置 我的新委托人的 context.User 字段: )
但是,当我在 WCF 中收到上下文(管道的下一步)时,用户显示为“默认”未经身份验证的 WindowsPrincipal(不是我设置的 GenericPrincipal 。
我在网上看到很多关于实现这项工作的内容(包括 serviceHostingEnvironment 的 aspNetCompatibilityEnabled="true"、使用 OperationContext 等...),但我尝试过的似乎都不起作用。
有两个问题:
- 有没有办法让它发挥作用(或者我只是在这里咆哮错误的树)。
- 执行此操作的规范方法是什么,或者可能是处理此自定义身份验证的更“WCF”方法。
谢谢
I have written an IIS module (base IHttpModule) that does some custom (OpenAuth) authentication before preceding to my WCF REST service.
I have extended GenericPrincipal to track my user, with an IIdentity, and set
the context.User field to my new principal:application.context.User = principal
However, when I receive the context in WCF (next step down the pipeline), the User shows up as a "default" unauthenticated WindowsPrincipal (not the GenericPrincipal that i set).
I see lots of stuff on the net about making this work (including aspNetCompatibilityEnabled="true" for serviceHostingEnvironment, playing with OperationContext, etc...) But nothing I have tried seems to work.
Two questions:
- Is there a way to get this to work (or am I just barking up the wrong tree here).
- What would be the canonical way to do this, or maybe the more "WCF" way to handle this custom authentication.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在 WCF 的授权阶段设置您的主体身份。这需要自定义授权策略。我建议您阅读这篇文章了解更多信息。我没有尝试使用自定义 HttpModule 和 REST 来执行此操作,但我已经使用默认身份验证方案成功完成了此操作。
You have to set your principal identity during the authorization phase in WCF. This requires a custom Authorization Policy. I suggest you read this article for more info. I've not tried to do this with a custom HttpModule and REST, but I have successfully done so with the default authentication schemes.