1
在我的Web API 2項目中,我有基於JWT的身份驗證。配置是SignalR 2.0中的IAuthenticationFilter
var config = new HttpConfiguration();
app.UseJwtBearerAuthentication(new JwtBearerAuthenticationOptions {/**/});
config.Filters.Add(new MyAuthenticationFilter());
app.UseWebApi(config);
app.UseCors(CorsOptions.AllowAll);
app.MapSignalR();
MyAuthenticationFilter
建立了基於傳入智威湯遜自定義主要並將其附加到一個請求,以致在我的控制器動作,我可以訪問它this.User
。一切工作正常,除了過濾器的SignalR請求忽略:
public class MyHub : Hub {
public override Task OnConnected() {
// here Context.User is ClaimsPrincipal which contain a JWT from Authorization header
// I expect it to be MyCustomPrincipal
return base.OnConnected();
}
}
爲什麼IAuthenticationFiltter
被忽略?我如何解決這個問題?