C
C#8mo ago
Bordin

✅ SignalR Authorized Connection

namespace LebUpwork.Api.Hubs
{
//[Authorize] <- This causes error when connecting
public class NotificationHub : Hub<INotification>
{
public override async Task OnConnectedAsync()
{
await Clients.Client(Context.ConnectionId).ReceiveNotification($"Thank you for connecting {Context.User?.Identity.Name}");
await base.OnConnectedAsync();
}
}

}
namespace LebUpwork.Api.Hubs
{
//[Authorize] <- This causes error when connecting
public class NotificationHub : Hub<INotification>
{
public override async Task OnConnectedAsync()
{
await Clients.Client(Context.ConnectionId).ReceiveNotification($"Thank you for connecting {Context.User?.Identity.Name}");
await base.OnConnectedAsync();
}
}

}
hello, i am initiating a connection on this Hub, however when i add [Authorized] the connection is failing
const connection = new HubConnectionBuilder()
.withUrl("https://localhost:7170/Hubs/NotificationHub", {
accessTokenFactory: () => token,
skipNegotiation: true,
transport: HttpTransportType.WebSockets,
})
.build();
const connection = new HubConnectionBuilder()
.withUrl("https://localhost:7170/Hubs/NotificationHub", {
accessTokenFactory: () => token,
skipNegotiation: true,
transport: HttpTransportType.WebSockets,
})
.build();
even tho I am adding the accessTokenFactory. Am i doing something wrong?
4 Replies
Bordin
BordinOP8mo ago
[Authorize] works on other endpoints it just has issues here
error, Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
error, Error: WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.
bruhhhh oh my god nvm i fixed it
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX8mo ago
Use the /close command to mark a forum thread as answered
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server