I am using ASP.NET Core 2.2 and ASP.NET Identity on an API.
Is it possible to Manually Authenticate a User with Claims for every request?
I would like to use this during initial development stages ...
I am using ASP.NET Core 2.2 and ASP.NET Identity on an API.
Is it possible to Manually Authenticate a User with Claims for every request?
I would like to use this during initial development stages ...
For authenticating a user without logging, you could try like:
public async Task<IActionResult> Login()
{
var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme, ClaimTypes.Name, ClaimTypes.Role);
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "edward"));
identity.AddClaim(new Claim(ClaimTypes.Name, "edward zhou"));
//add your own claims
var principal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, new AuthenticationProperties { IsPersistent = true });
return View();
}