【发布时间】:2019-04-24 21:51:51
【问题描述】:
在我的 SignalR 身份验证原型中,JS 客户端没有 Context.UserIdentifier,当连接到 JS 客户端的 SignalR 集线器时,connectionId 将为 0。它适用于 .NET 客户端。
想知道构造连接是否错误? 这是我的连接:
state.connection = new signalR.HubConnectionBuilder()
.withUrl("/chatHub", {
accessTokenFactory: async () => {
axios.post('https://localhost:44384/api/account/token', { email: email, password: password })
.then(async (response) => {
if (typeof response === 'undefined') {
return;
}
else {
console.log(response.data);
console.log(state.connection.id);
return response.data;
}
})
.catch((error) => {
console.log(error);
});
}
})
.build();
WPF 客户端可以通过以下代码很好地连接令牌:
_connection = new HubConnectionBuilder()
.WithUrl("https://localhost:44384/ChatHub", options =>
{
options.AccessTokenProvider = async () =>
{
var tokenUserCommand = new TokenUserCommand
{
Email = emailTextBox.Text,
Password = passwordBox.Password
};
var token = await RestService.PostAsync<string>("account/token", tokenUserCommand);
return token;
};
})
.Build();
我在哪里找到SignalR Authentication configuration 和SignalR Bearer Authentication
【问题讨论】:
标签: c# asp.net-core jwt signalr