简体   繁体   English

SignalR 配置option.AccessTokenProvider时客户端连接失败

[英]SignalR client fails to connect when configuring option.AccessTokenProvider

This connects:这连接:

const connection = new signalR.HubConnectionBuilder()
   .withUrl('/ArgoRtc/Hub')
   .configureLogging(signalR.LogLevel.Information)
   .build();

This fails to connect:这无法连接:

const connection = new signalR.HubConnectionBuilder()
   .withUrl('/ArgoRtc/Hub', options => {
      options.AccessTokenProvider = () => {
         return 'test';                   
      };
    })
    .configureLogging(signalR.LogLevel.Information)
    .build();

Only difference is that options.AccessTokenProvider is configured.唯一的区别是配置了options.AccessTokenProvider

Client error is: SignalR connection failed: Unable to connect to the server with any of the available transports.客户端错误是:SignalR 连接失败:无法使用任何可用传输连接到服务器。 WebSockets failed: Error: 'WebSockets' is disabled by the client. WebSockets 失败:错误:'WebSockets' 被客户端禁用。 ServerSentEvents failed: Error: 'ServerSentEvents' is disabled by the client. ServerSentEvents 失败:错误:'ServerSentEvents' 被客户端禁用。 LongPolling failed: Error: 'LongPolling' is disabled by the client. LongPolling 失败:错误:'LongPolling' 被客户端禁用。

Obviously none of these transports are disabled because it connects fine without AccessTokenProvider option set.显然,这些传输都没有被禁用,因为它在没有设置 AccessTokenProvider 选项的情况下连接良好。 I don't have any type of authentication configured on the server side.我没有在服务器端配置任何类型的身份验证。

All I want is to be able to read my "test" token string on server through:我想要的只是能够通过以下方式读取服务器上的“测试”令牌字符串:

var authToken = Context.GetHttpContext().Request.Headers["Authorization"].ToString();

Which I later plan to custom authenticate myself through hub filters.我稍后计划通过集线器过滤器自定义验证自己。

It looks like AccessTokenProvider is now accessTokenFactory.看起来 AccessTokenProvider 现在是 accessTokenFactory。 So many changes to this API over the years and so many examples out there from different versions that this can get confusing.多年来,这个 API 发生了如此多的变化,不同版本的示例如此之多,这可能会让人感到困惑。

Also docs have always been misleading on how the access token is refreshed.此外,文档一直在误导访问令牌的刷新方式。 They implied that accessTokenFactory is called on every method call but in reality it only does on initial connection.他们暗示在每次方法调用时都会调用 accessTokenFactory,但实际上它只在初始连接时执行。 Wished in wasn't so because now I have to pass new tokens through hub method props which is ugly.希望不是这样,因为现在我必须通过丑陋的集线器方法道具传递新令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM