aspnetcore: .Net Core Console connect signalR 401 under windows authentication
Describe the bug
When .net core signalR console app connect signalR server with Windows Authentication, receive 401.
To Reproduce
Steps to reproduce the behavior:
- Using this version of ASP.NET Core
netcoreapp2.1
with Windows Authentication enabled.
[Authorize]
public class TimeHub: Hub
{
public async Task UpdateTime(string message)
{
if (Clients != null)
{
await Clients?.All.SendAsync("ReceiveMessage", message);
}
}
}
- .Net Core Console App
class Program
{
static Action<string> OnReceivedAction = OnReceived;
static void Main(string[] args)
{
Console.WriteLine(WindowsIdentity.GetCurrent().Name);
//WindowsIdentity.RunImpersonated(WindowsIdentity.GetCurrent().AccessToken, Connect);
Connect();
Console.WriteLine("Hello World!");
Console.ReadLine();
}
private static async void Connect()
{
var hubConnectionBuilder = new HubConnectionBuilder();
var hubConnection = hubConnectionBuilder.WithUrl("http://localhost:61045/timeHub",options => {
options.UseDefaultCredentials = true;
}).Build();
await hubConnection.StartAsync();
await hubConnection.SendAsync("UpdateTime", $"From Client");
var on = hubConnection.On("ReceiveMessage", OnReceivedAction);
Console.WriteLine($"Client is Start");
Console.ReadLine();
on.Dispose();
await hubConnection.StopAsync();
}
static void OnReceived(string message)
{
Console.WriteLine($"{ message }");
}
}
Expected behavior
Console App connect signalR server correctly.
Current behavior
Receive error 401 at console app.
Update:
After making a test with https
and http
url in client signalr, it works with https url, it seems app.UseHttpsRedirection();
at server side fail to redirect the client credential while redirecting http to https.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (9 by maintainers)
https://docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-2.2#visual-studio-settings-for-windows-and-anonymous-authentication