Add claims when creating a new user

asked9 years ago
last updated7 years ago
viewed17.2k times
Up Vote22Down Vote

I am creating a new User using ASP.NET Core Identity as follows:

new User {
  Email = "john@company.com",
  Name = "John"
}

await userManager.CreateAsync(user, "password");

I need to add a Claims when creating the user. I tried:

new User {
  Email = "john@company.com",
  Name = "John",
  Claims = new List<Claim> { /* Claims to be added */ }  
}

But Claims property is read only.

What is the best way to do this?