【发布时间】: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