【问题标题】:Web api 2 - windows + client cert auth - is it possible?Web api 2 - windows + 客户端证书身份验证 - 有可能吗?
【发布时间】:2017-04-07 21:08:23
【问题描述】:

我目前有一个托管在 IIS 中的 asp.net web api 2 站点,通过 Windows 身份验证进行保护。除了 Windows 之外,我们现在还需要支持客户端证书身份验证,我正在努力寻找: - 如果这是可能的 - 如果有任何可用的工作示例

我认为可能能够添加额外的 owin 中间件或消息处理程序或过滤器,但看不到任何现有的专门为 Windows 执行此操作而不仅仅是依赖 IIS。我知道thinktecture identitymodel可以做client cert,但不确定两者是否可以结合?

我认为可能相似的表单+win示例在这里https://techblog.dorogin.com/mixed-windows-forms-authentication-for-ajax-single-page-application-e4aaaac0424a

【问题讨论】:

    标签: asp.net-web-api asp.net-web-api2 windows-authentication client-certificates


    【解决方案1】:

    是的,所以我设法弄清楚了。幸运的是,如果控制器返回 401,IIS 会自动添加协商/ntlm 标头,因此如果用户使用的是 Windows 浏览器,它将照常自动进行身份验证。因此,考虑到这一点,为了保持 Windows 身份验证正常工作,我:

    • 更新了 IIS 和 VS 中的站点以允许匿名和 windows 身份验证
    • 将 [AuthorizeAttribute] 添加为全局操作过滤器(如果用户在点击过滤器时未通过身份验证,则会返回 401)

    为了让客户端证书验证正常工作,我使用了强大的 Thinktecture.IdentityModel 库,它只允许我在我的 Startup.cs 文件中添加一行(我们使用的是 OWIN,所以这很容易)

    app.UseClientCertificateAuthentication();
    

    请参阅https://github.com/IdentityModel/Thinktecture.IdentityModel/blob/master/samples/OWIN/AuthenticationTansformation/KatanaAuthentication/Startup.cs 了解示例

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      • 2013-10-07
      • 1970-01-01
      • 2022-06-23
      相关资源
      最近更新 更多