如何将 Azure BC2 身份验证添加到 Java 程序中的 SignalR 连接?[已结束]

How can I add Azure BC2 authentication to the SignalR connection in a Java program? [closed]

提问人:ISTI Kevin 提问时间:11/17/2023 更新时间:11/17/2023 访问量:22

问:


想改进这个问题吗?通过编辑这篇文章添加详细信息并澄清问题。

7天前关闭。

截至 4 天前,社区正在审查是否重新讨论此问题。

我有一个 Java 程序,它不是连接到在 ServerLess 模式下运行的 Azure SignalR 中心并侦听事件的 Web 应用程序。该程序在不同的操作系统上运行,包括 Windows、macOS 和 Linux。该程序使用 ASP.NET Core SignalR Java 客户端。

我想添加身份验证,以使用用户名和密码通过 Azure BC2 进行验证。

下面是连接到 SignalR 的简单示例:

    /**
     * Example program for SignalR.
     *
     * @param args the program arguments, which consists of the URL for the SignalR
     *             server and the hub name.
     */
    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.print("\nUsage: ");
            System.out.print(Example.class);
            System.out.println(" signalr_url hubname");
            return;
        }
        try {
            final HttpHubConnectionBuilder builder = HubConnectionBuilder.create(args[0]);
            final HubConnection hubConnection = builder.build();
            final Action1<Object> callback = new Action1<Object>() {
                @Override
                public void invoke(Object param1) {
                    System.out.print("Signalr hub connection ID: ");
                    System.out.println(hubConnection.getConnectionId());
                    System.out.println(param1);
                }
            };
            hubConnection.on(args[1], callback, Object.class);
            // start the hub connection and wait until connected
            hubConnection.start().blockingAwait();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

我已经找到了如何使用 Java Web 应用程序或在 Windows 上运行的 Java 程序执行此操作的示例,但我需要适用于任何操作系统的解决方案。

Java Azure Azure-Active-Directory SignalR

评论


答: 暂无答案