Ow.net中间件是asp.net web API中的每个控制器

时间:2016-08-18 18:58:59

标签: asp.net-mvc asp.net-web-api2 owin

我正在使用以下JWT中间件来授权所有具有有效JWT的控制器,并且它按预期工作。我需要在其中一个控制器上启用基于客户端证书的授权。我知道我可以创建一个新的中间件并将其插入到验证客户端证书的owin管道中。

如何确定哪个控制器使用哪个中间件?据我所知,OWIN对任何控制器都不了解。请建议

public void ConfigureAuth(IAppBuilder app)
    {
         TextEncodings.Base64Url.Decode("IxrAjDoa2FqElO7IhrSrUJELhUckePEPVpaePlS_Xaw");

        var issuer = System.Configuration.ConfigurationManager.AppSettings["issuer"].ToString();
        var audience = System.Configuration.ConfigurationManager.AppSettings["ClientID"].ToString();
        var secret = TextEncodings.Base64Url.Decode(System.Configuration.ConfigurationManager.AppSettings["ClientSecret"].ToString());
        // Api controllers with an [Authorize] attribute will be validated with JWT
        app.UseJwtBearerAuthentication(
            new JwtBearerAuthenticationOptions
            {
                AuthenticationMode = AuthenticationMode.Active,
                AllowedAudiences = new[] { audience },
                IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                {
                    new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret),

                }                   
            });

    }

1 个答案:

答案 0 :(得分:0)

Owin"知道"由于其上面的[Authorize]标签而授权哪个控制器。

为什么不为其他系统做同样的事情?创建另一个标签然后启动其他身份验证系统?这是保持清洁系统正常工作的最简单方法。

你很可能会使用owin源代码来获得灵感并确切地了解事情是如何完成的。