AspNetCore.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();
});

 

posted @ 2019-05-19 16:46  两颗番茄两块七  阅读(932)  评论(0编辑  收藏  举报