![](/img/trans.png)
[英]How can I use the HttpContext.Current.User.Identity to provide authentication to my SmtpClient.Credentials?
[英]How do I check an OWIN request before HttpContext.Current.User.Identity is set?
我为使用Bearer令牌的webapi2网站设置了OWIN。 一切正常,但是我现在需要实施安全检查。
这是我需要完成的
我打算将检查放入自定义AuthorizeAttribute中,但是感觉不合适。
是否可以使用OAuthAuthorizationServerProvider检查OWIN请求,并在不满足条件的情况下取消身份验证? 我真的不知道在哪里进行实际检查以验证/解密承载令牌,并且如果可能的话,我想知道是否可以使用钩子或覆盖。
您可以创建一个owin中间件,以检查Ip地址,这是该链中的第一步。 将其放置为附加到IAppBuilder的第一个中间件,以确保它将在链的其余部分之前调用
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Use((context, next) =>
{
if (!IsIpAdressOk(context.Request)) //if the ip is invalid, stop the process and just return a response to the client
{
return context.Response.WriteAsync("Get lost!");
}
return Next.Invoke(context); //if the ip is correct then continue to the next middleware
});
...add OAuthAuthorizationServerProvider and the rest here
}
}
约Owin中间件伟大的博客在这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.