I implement ASP.NET Core cookie Authentication In blazor server side.I write simple API Controller with Login endpoint.
When I post to API via postman everything works fine and I become identified and Authorized.
When I post via HttpClient: _http.PostJsonAsync<bool>("api/auth/Login", credentials);
I hit the API endpoint and its run to till end without error but the Authentication State don't change and no cookie is created.
var res = await _http.PostJsonAsync<bool>("api/v1/Auth/Login", credentials);
api:
[AllowAnonymous][HttpPost][Route("Login")]public async Task<bool> Login(){ const string Issuer = "mydomain.com"; var claims = new List<Claim> { new Claim("ID", dataTable.Rows[0]["ID"].ToString(), ClaimValueTypes.String, Issuer), new Claim("FullName", dataTable.Rows[0]["FullName"].ToString(), ClaimValueTypes.String, Issuer), new Claim("CompanyName", dataTable.Rows[0]["CompanyName"].ToString(), ClaimValueTypes.String, Issuer), new Claim("Email", dataTable.Rows[0]["Email"].ToString(), ClaimValueTypes.String, Issuer), }; var userIdentity = new ClaimsIdentity(claims, "User"); var userPrincipal = new ClaimsPrincipal(userIdentity); await HttpContext.SignInAsync ( CookieAuthenticationDefaults.AuthenticationScheme, userPrincipal, new AuthenticationProperties { ExpiresUtc = DateTime.UtcNow.AddMinutes(20), IsPersistent = false, AllowRefresh = false } ); return true;}