在 MVC 应用程序中为我自己的 IPrincipal 对抗 WIF
我想将 Azure ACS 添加到我的一个站点,但所有功能都存在问题。我有一个 MVC 应用程序,它使用全局过滤器为请求的生命周期设置自定义 IPrincipal。 WIF 的“添加 STS 引用”方法的问题在于它通过 HttpModule 短路了这一点。
我知道的就这么多:ACS 反弹回我的 Web 应用程序到我为其配置的 URL,并且该反弹是带有规范化 SAML 令牌的 POST。我对 WIF 设置 cookie 或任何其他废话不感兴趣...我只想从 POST 中获取我感兴趣的声明,并从那里自行设置身份验证内容。工作流程是怎样的?该文档很糟糕,并且专注于神奇的“右键单击”解决方案。
I want to add Azure ACS to one of my sites, but having issues with all of the magic. I have an MVC app that uses a global filter to set a custom IPrincipal for the life of the request. The problem with the "add STS reference" methodology of WIF is that it short circuits this via an HttpModule.
This much I know: ACS bounces back to my Web app to the URL I configured it for, and that bounce is a POST with the normalized SAML token. I'm not interested in WIF setting cookies or any of that nonsense... I just want to get the claims I'm interested in from the POST and deal with setting auth stuff up myself from there. What's the workflow? The documentation is lousy, and focuses on the magic "right click" solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为有一个非常简单的解决方案可以解决您的问题:
在
WSFederationAuthenticationModule
的SecurityTokenValidated
事件上注册,将e.Cancel
设置为true
并使用事件参数的ClaimsPrincipal
属性中提供的信息启动登录逻辑。将事件参数上的
Cancel
设置为true
可防止 WIF 创建任何 IPrincipal 或会话,因此您可以自行处理这些内容。I think there is a really easy solution to your problem:
Register on the
SecurityTokenValidated
event of theWSFederationAuthenticationModule
, sete.Cancel
totrue
and start your sign in logic with the information provided in theClaimsPrincipal
property of the event args.Setting
Cancel
totrue
on the event args prevents WIF from creating any IPrincipal or session, so you can handle this stuff by your self.使用WIF+MVC的例子有很多,控制程度也不同。我建议这些:http://claimsid.codeplex.com 或身份培训套件中的那些。
WIF 几乎会为您处理一切。要获得更深入的可扩展性,您应该查看 Vittorio 的书。
关于:我只想从 POST 中获取我感兴趣的声明,并从那里自行设置身份验证内容。
您希望自己做什么而 WIF 不想做的事情?您希望在 IPrincipal 中包含哪些 IClaimsPrincipal 不提供的功能?
WIF 中有许多旋钮和控制杆,可以进行各种细粒度控制。如果您分享您想做的事情可能会有所帮助。
There are many examples of using WIF + MVC, with different levels of control. I would suggest these ones: http://claimsid.codeplex.com or the ones in the Identity Training Kit.
WIF pretty much takes care of everything for you. For deeper extensibility, you should check Vittorio's book.
Regarding: I just want to get the claims I'm interested in from the POST and deal with setting auth stuff up myself from there.
What would you want to do yourself that WIF doesn't? What functionality would you include in your IPrincipal that IClaimsPrincipal doesn't provide?
There are many knobs and levers in WIF with all kind of fine grain control. It would probably help if you share what is it you want to do.