使用OWIN和WsFederation对MVC,web api和signalR应用进行身份验证

PAP*_*PAP 8 asp.net-mvc identity ws-federation asp.net-web-api owin

对于我的公司,我必须制作一个POC来检查我们是否可以对我们的项目使用wsFederation身份验证,该项目有一个MVC应用程序,一些webapi控制器和一些signalR集线器,所有这些都在不同的项目中.我们还希望在客户端应用程序和身份提供商应用程序中使用OWIN身份验证中间件.

我使用Thinktecture Identity Server v2作为身份提供者的开始(但我们必须在某些时候开发自己).对于MVC应用程序,它非常直接,并且使用SAML2令牌工作正常.

但是现在事情变得有点复杂,因为我希望Web应用程序上的经过身份验证的用户能够使用ajax调用从web api应用程序(与MVC不同,请记住)调用控制器方法.

我已经阅读了许多关于委托和代理令牌的事情,但我有点迷失,不知道在哪里或如何开始这部分.此外,我找不到任何关于使用OWIN身份验证的委派.

所以我的第一个问题是:是否有可能实现这一目标?然后:有人能指出我正确的方向吗?

Dav*_*rds 1

我在做这件事时遵循了 Vittorio Bertocci 的指示。

http://www.cloudidentity.com/blog/2013/01/09/using-the-jwt-handler-for-implementing-poor-man-s-delegation-actas/

关于它的一些注释,其中写着 JWTSecurityTokenHandler,现在是 JwtSecurityTokenHandler。这是一个小错别字,但如果您没有意识到的话,这是一个节省 15 分钟时间的好方法。

我也无法使用 X509 FindByThumbprint 部分。我认为我没有正确注册本地证书。明天上班后,我将发布我必须更改的内容才能使其正常工作。

Dominick Baier ( http://leastprivilege.com/ ) 还开设了一门名为 WebApi v2 Security 的pluralsight 课程,该课程很好地讨论了如何注入安全管道以及设置 Web api 项目来处理此问题。

作为另一种选择,您可以将 Vittorio 使用的 TokenValidationHandler 类替换为 Microsoft.Owin.Security.Jwt 包,并在 Startup.cs 文件中实现以下代码。

app.UseJwtBearerAuthentication(
            new JwtBearerAuthenticationOptions
            {
                AuthenticationMode = AuthenticationMode.Active,
                AllowedAudiences = new[] { ConfigurationSettings.AppSettings["ida:Realm"] },
                IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[] 
                    { 
                        new SymmetricKeyIssuerSecurityTokenProvider(
                            ConfigurationSettings.AppSettings["ida:ValidIssuer"],
                            ConfigurationSettings.AppSettings["ida:SymmetricKey"])
                    },
                Provider = new OAuthBearerAuthenticationProvider
                {
                    OnValidateIdentity = context =>
                    {
                        var identity = context.Ticket.Identity;
                        return System.Threading.Tasks.Task.FromResult<object>(null);
                    }
                }
            });
Run Code Online (Sandbox Code Playgroud)