✅ SignalR authentication not working
Hi, im making a chat application with .net core and signalr. I use token auth. when im already authenticated but the message does not show it in this.
[Authorize]
public override async Task OnConnectedAsync()
{
await Clients.All.SendAsync("ReceiveSystemMessage",
$"{Context.UserIdentifier} joined.");
await base.OnConnectedAsync();
}
[Authorize]
public override async Task OnDisconnectedAsync(Exception exception)
{
await base.OnDisconnectedAsync(exception);
}
connection starts and only shows joined.
Please help
5 Replies
show me your program.cs
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
// Add Authentication
builder.Services.AddAuthentication().AddBearerToken(IdentityConstants.BearerScheme);
builder.Services.AddAuthorizationBuilder();
builder.Services.AddIdentityCore<User>()
.AddEntityFrameworkStores<Context>()
.AddApiEndpoints();
var app = builder.Build();
app.UseCors();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapIdentityApi<User>();
app.MapControllers();
app.MapHub<ChatHub>("/chathub");
app.Run();
not solved yet. what do you mean closing?
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
ok