客户端何时适合与 SignalR 服务重新协商?
When is it appropriate for the client to re-negotiate with SignalR Service?
我正在尝试了解 SignalR Service
的 negotiate
步骤返回的访问令牌。
[FunctionName("negotiate")]
public static SignalRConnectionInfo Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req,
[SignalRConnectionInfo(HubName = "chat")]SignalRConnectionInfo connectionInfo)
{
return connectionInfo;
}
- 默认情况下,
SignalRConnectionInfo
返回的token有效期是多久?
- 有没有办法手动配置令牌寿命?
- 如果令牌不再有效,
Microsoft.AspNetCore.SignalR.Client.HubConnection
对象(尤其是它的 State
属性)会怎样?会不会设置成Disconnected
?
基本上,我正在尝试确定何时应该重新协商以保持我的连接打开。如果令牌过期,客户端如何知道它需要再协商一次才能发送和接收实时消息?
深入 Azure SignalR SDK code,默认的访问令牌生命周期似乎是 1 小时。
而 SDK seems to support customizing the lifetime, the service binding doesn't seem expose it.
对于 3,不要认为你真的需要它,但你可以 raise on issue on its repo 或贡献一个 PR 来支持它。
在 @microsoft/signalr
包中,您可以 enable automatic reconnect or manually reconnect。我相信图书馆会自行在内部处理协商电话。
在 Microsoft 文档的身份验证和授权部分中说:
The access token function you provide is called before every HTTP request made by SignalR. If you need to renew the token in order to keep the connection active (because it may expire during the connection), do so from within this function and return the updated token.
所以你需要在第一次启动连接时发送一个"refreshed"令牌。在应用程序上下文中,当您的令牌过期时,它应该将用户重定向到身份服务器以刷新令牌,然后重新启动一个新连接。
在我们公司,我们使用应用程序令牌与集线器建立持久连接,因此当它过期时,它会强制刷新令牌,这将触发使用新令牌与集线器的新连接。
我正在尝试了解 SignalR Service
的 negotiate
步骤返回的访问令牌。
[FunctionName("negotiate")]
public static SignalRConnectionInfo Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req,
[SignalRConnectionInfo(HubName = "chat")]SignalRConnectionInfo connectionInfo)
{
return connectionInfo;
}
- 默认情况下,
SignalRConnectionInfo
返回的token有效期是多久? - 有没有办法手动配置令牌寿命?
- 如果令牌不再有效,
Microsoft.AspNetCore.SignalR.Client.HubConnection
对象(尤其是它的State
属性)会怎样?会不会设置成Disconnected
?
基本上,我正在尝试确定何时应该重新协商以保持我的连接打开。如果令牌过期,客户端如何知道它需要再协商一次才能发送和接收实时消息?
深入 Azure SignalR SDK code,默认的访问令牌生命周期似乎是 1 小时。
而 SDK seems to support customizing the lifetime, the service binding doesn't seem expose it.
对于 3,不要认为你真的需要它,但你可以 raise on issue on its repo 或贡献一个 PR 来支持它。
在
@microsoft/signalr
包中,您可以 enable automatic reconnect or manually reconnect。我相信图书馆会自行在内部处理协商电话。
在 Microsoft 文档的身份验证和授权部分中说:
The access token function you provide is called before every HTTP request made by SignalR. If you need to renew the token in order to keep the connection active (because it may expire during the connection), do so from within this function and return the updated token.
所以你需要在第一次启动连接时发送一个"refreshed"令牌。在应用程序上下文中,当您的令牌过期时,它应该将用户重定向到身份服务器以刷新令牌,然后重新启动一个新连接。
在我们公司,我们使用应用程序令牌与集线器建立持久连接,因此当它过期时,它会强制刷新令牌,这将触发使用新令牌与集线器的新连接。