在 MVC 应用程序中为我自己的 IPrincipal 对抗 WIF

发布于 2024-11-14 17:36:39 字数 311 浏览 3 评论 0原文

我想将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂归处 2024-11-21 17:36:39

我认为有一个非常简单的解决方案可以解决您的问题:

WSFederationAuthenticationModuleSecurityTokenValidated 事件上注册,将 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 the WSFederationAuthenticationModule, set e.Cancel to true and start your sign in logic with the information provided in the ClaimsPrincipal property of the event args.

Setting Cancel to true on the event args prevents WIF from creating any IPrincipal or session, so you can handle this stuff by your self.

过度放纵 2024-11-21 17:36:39

使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文