SignalR的JwtBearer认证
作者:互联网
一、客户端请求SignalR时,将Token放入QueryString
var connection = new HubConnectionBuilder().WithUrl($"http://xxx/signalr?Bearer={Token}").Build();
二、在Startup中,在UseAuthentication之前获取Token并放入Header
app.Use((context, next) => { if (context.Request.Query.TryGetValue("Bearer", out var token)) context.Request.Headers.Add("Authorization", $"Bearer {token}"); return next.Invoke(); });
标签:Bearer,JwtBearer,token,认证,SignalR,Token,context,next 来源: https://www.cnblogs.com/liyanjie8712/p/10889778.html