【问题标题】:Ticket authentication in Autobahn.jsAutobahn.js 中的票证身份验证
【发布时间】:2023-03-16 14:45:01
【问题描述】:

我已经实现了路由器和发布者。客户端需要使用基于票证的身份验证连接到路由器。需要在onchallange方法中发送token的格式。

下面是我的js代码。

var connection = new autobahn.Connection({
    url: 'ws://127.0.0.1:26429/',
    realm: 'testRealm',
    authmethods: ["ticket"],
    authid: 'testAuthid',
    onchallenge: function () {
        // Code to send token in the expected format
    }
});

在路由器端,以下是我要验证的值:

 private readonly IDictionary<string, string> mUserToTicket =
            new Dictionary<string, string>
            {
                ["joe"] = "magic_secret_1"
            };

如何将 ["joe"] = "magic_secret_1" 转换为路由器期望的令牌?

大多数示例都在 python 中,并实现了不同类型的身份验证。

请帮忙。

已编辑

以下是使用的路由器端身份验证的一部分。

public IWampSessionAuthenticator GetSessionAuthenticator
            (WampPendingClientDetails details,
             IWampSessionAuthenticator transportAuthenticator)
        {
            HelloDetails helloDetails = details.HelloDetails;

            if (helloDetails.AuthenticationMethods?.Contains("ticket") != true)
            {
                throw new WampAuthenticationException("supports only 'ticket' authentication");
            }

            string user = helloDetails.AuthenticationId;

            string ticket;

            if (user == null ||
                !mUserToTicket.TryGetValue(user, out ticket))
            {
                throw new WampAuthenticationException
                    ($"no user with authid '{user}' in user database");
            }

            return new TicketSessionAuthenticator(user, ticket, mUserToAuthorizer[user]);
        }

【问题讨论】:

    标签: autobahn crossbar wamp-protocol


    【解决方案1】:

    由于您正在构建自己的路由器,因此您需要构建逻辑 处理 WAMP 身份验证。

    在您的示例中,票证是“magic_secret_1”,这是客户端将发送到路由器的内容,路由器将进行检查。

    在您的路由器中,您需要添加代码来处理 HELLO 和 AUTHENTICATE 消息。每个的粗略逻辑是:

    处理 HELLO

    检查用户名在领域是否允许。

    检查authmethods 数组是否包含ticket

    回复挑战信息:[4, "ticket", {}]

    处理身份验证

    客户端会发送类似[5, "magic_secret_1", {}]的消息。获取 authid 与 wamp 会话相关联(路由器在处理 HELLO 消息时应该存储它)并将 realmauthidticket 传递给检查 mUserToTicket 字典内部的函数。

    客户

    在客户端,您可以像这样添加票证:

    var connection = new autobahn.Connection({
        url: 'ws://127.0.0.1:26429/',
        realm: 'testRealm',
        authmethods: ["ticket"],
        authid: 'joe',
        onchallenge: function () {
            return "magic_secret_1";
        }
    });
    

    WAMP Ticket-based Authentication

    【讨论】:

    • 您好,感谢您的回复。我最初也是这样做的,但我得到了以下错误。可能未处理的拒绝 [1] {"error":"wamp.error.not_authorized","args":[],"kwargs":{}}(警告:未使用错误)
    • 不清楚发生了什么。 [1] 表明这是一个被路由器拒绝的 HELLO 尝试,对吗?您已经实现了路由器,因此您应该能够调试 HELLO 被拒绝的原因。
    • 路由器作为 Windows 服务运行。而且我无法为该进程附加调试器。它说 '没有符号已加载' 。是否尝试清理/重建 sln。并明确指定所需的 .pdb 文件。仍然无法调试...我在想可能是我在 js 的 onchallenge 方法中发送了错误的票证格式..
    • 感谢您的帮助。关于相同的另一个问题。如何检查路由器中的传入消息?我的路由器主机代码: var hostsRealm = host.RealmContainer.GetRealmByName(realm); hostsRealm.SessionCreated += (sender, arguments) => { counters++; _logger.Log(DateTime.UtcNow.ToString() + "\r\n" + "会话已打开。" + "\r\n" + "- 会话 ID:" + arguments.SessionId.ToString() + " \r\n" + "- 打开的会话总数:" + counters.ToString()); };
    • 好吧,您可以尝试向路由器添加代码,以便在每条消息到达时将其打印出来。路由器使用什么 javascript 库?您可以检查senderarguments 参数,看看它们是否有办法让您附加您自己的可用于打印消息的回调。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多