I use cookie based authentication on ASP.NET 6.0.0 SPA template.
this.connection = new HubConnectionBuilder()
.withUrl(`${setting.baseUrl}/hub/store`)
.build();
await this.connection.start();
And I logged in on action controller as below. I skip password verification. This is just example.
[HttpPost]
public async Task<ActionResult> Login(LoginModel model)
{
var user = await userManager.FindByNameAsync(model.Username);
if (user is null)
{
user = new ApplicationUser();
await userManager.SetUserNameAsync(user, model.PublicKey);
var createResult = await userManager.CreateAsync(user);
if (!createResult.Succeeded)
return BadRequest(createResult);
}
var claims = new List<Claim> { new Claim(ClaimTypes.NameIdentifier, user.Id) };
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{
IsPersistent = true,
ExpiresUtc = DateTime.UtcNow.AddDays(15)
};
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);
await storeHub.Clients.User(user.Id).LoggedIn();
return Ok();
}
As you can see i push LoggedIn message for logged in user at the end of login process.
I call the endpoint by ajax request and i see that LoggedIn message is not triggered on client side.
But LoggedIn event is really working when i tested it on another authorized endpoint.
I suspect there is something different when it is tried in login process method.
Any help ?