I started my project as a .NET Core Web API project using Code-First EF (database managed via migration classes). I have my endpoints working but now need authentication.
I have scaffolded identity by following the instructions here. I made sure to scaffold using my existing DB context and then ran the migration code. The required tables for Identity were created on my SQL local database.
My next step is to create a default admin user using the .NET API. From several sources I found online, it looks like I can create the user via the UserManager (and RoleManager) class, something like this:
userManager.CreateAsync(user, ADMIN_PASSWORD).Result;
However, I want to call such code in the Startup.cs Configure function. How the userManager and roleManager.
It seems that the dependency injection is achieved when configuring the app with this line:
app.UseAuthorization();
within the Configure class. That is how the classes are injected into the controller actions? Correct? But first, I need to create a default admin.
I do not want users to register. I just want this app to be used by admins.
How do I inject the usermanager?
Really, I just want a default admin created, so if doing it this way is wrong, that's fine, but where and how can I do it?
I don't know if this makes a difference, but the intention is to use JWT tokens with an Angular app.