c# - SignalR 服务(无服务器)- Azure 函数

标签 c# signalr azure-functions serverless

我对 SignalR 感到困惑,特别是在使用 Azure SignalR 服务时,在考虑使用 Azure Functions 的无服务器实现时更是如此。

我有一个 Web 应用程序和一个 Azure Function 应用程序,其中实现了一个协商功能。客户端上的 JavaScript 已成功协商并能够连接到 Azure SignalR 服务,到目前为止一切顺利。

附带问题:阻止任何老年人连接并获取 token 的唯一因素是 CORS 设置吗?这本身就足够安全吗?

在这之后,我感到困惑。我现在有一个 Azure SignalR 服务和一个 Azure Function 应用程序,在与 Azure SignalR 服务的客户端连接建立后,Function App 提供什么服务?

在客户端交互方面,我需要做一些事情,例如加入一个组并向该组广播(从客户端上的 JavaScript),我假设那些是函数应用程序上的两个附加函数(Http 触发器)?

假设我对上述内容是正确的,我如何阻止任何人通过函数应用程序 http 端点调用“广播”函数 ?至少在本地,我可以从 Postman 调用它,而无需提供在初始协商响应中收到的任何信息。

我还需要从后端代码(.net 标准)将消息推送到组,这是通过调用函数应用还是直接调用 Azure SignalR 服务来完成的?

提前致谢。

最佳答案

这是一个很好的问题!
当我开始倾向于完全无服务器的方法时,我也在想同样的事情。

Is the only thing that stops any old person connecting and getting a token the CORS setting? Is this secure enough on its own?



刚开始时看起来确实如此,但答案是否定的。
您可以验证您的功能。要么与built in providers ,或者您可以通过创建自己的自定义绑定(bind)来验证自己,以检查通过 header 传递的 token 。

In terms of client interaction I need to do things like join a group and broadcast to said group (from JavaScript on the client), I assume those would be two additional functions (Http triggers) on the function app?



你假设正确。如果你想完全无服务器,这是要走的路。您可以使用与验证 SignalR 协商函数相同的方式验证函数,并且您将拥有一个安全端点,它将为您调用 SignalR 服务。

I also need to push messages to groups from backend code (.net standard), is this done by a call to the function app or straight to the Azure SignalR Service?



这个没有正确答案。这实际上取决于您的特定架构。如果没有更多上下文,尝试回答这个问题将是困难/错误的。

哦,如果您要使用 SignalR 实现无服务器,我真的希望您使用它们的绑定(bind)。 :)
  • GitHub
  • Official Doc
  • 关于c# - SignalR 服务(无服务器)- Azure 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58027809/

    相关文章:

    c# - Azure定时器触发功能依赖注入(inject)问题

    c# - SignalR 从 Controller 加入组

    SignalR(原始)不向客户端发送消息

    c# - Azure Web 应用程序与 Azure VM 上的 Windows 窗体应用程序之间的通信

    c# - Xamarin Forms 条目中的删除线文本

    c# - 在 ASP.NET Core 中全局重用变量

    c# - ASP .NET MVC 5 - 客户地址一对一关系

    python - 读取 Azure Functions 上的 Shapefile

    使用 AD B2C 进行守护程序应用程序的 Azure 函数身份验证

    java - 如何使用 Android Volley 将参数发送到 Azure Functions?