我使用Owin进行身份验证/授权,在配置更改时,我想更新所有用户的声明。
我所做的是创建了一个事件,我订阅了我的Principal对象,并在处理程序中更新了他们的声明。但是,为了更新声明,我必须执行以下操作:
private void OnTimeOutChange(object sender, SystemConfigurationUpdatedEventArgs args)
{
int timeout = args.SystemConfiguration.ValueAs<int>();
if (this.MyIdentity.HasClaim(c => c.Type == DemoIdentity.IPClaimType))
{
this.MyIdentity.RemoveClaim(this.FindFirst(c => c.Type == DemoIdentity.IPClaimType));
}
this.MyIdentity.AddClaim(new Claim(DemoIdentity.IPClaimType, timeout.ToString()));
HttpContext.Current.GetOwinContext().Authentication.SignIn(new AuthenticationProperties{ IsPersistent = false }, this.MyIdentity);
}
问题在于,即使每个Principal对象中的处理程序都被命中,唯一更新的声明是针对正在更改配置的用户,即HttpContext.Current
我假设这是因为使用了HttpContext.Current.GetOwinContext(),因为这是当前请求的上下文。
有没有办法让全球或每个用户获得OwinContext,或者我试图做不到的事情?