I have an Asp.Net core web application that uses Asp.Net Identity for user management. The application creates employees, and on the creation of an employee; I have to create an AspNetUser and his roles accordingly. That employee can then login into the application and UI is shown based on his role. So I am using SignInManager, RoleManager, and UserManager for all this. There is no API involved so far. EF Core with the repository pattern is being used.
Now I have the requirement from the client to develop a lite version of this web application as native apps. For that, I obviously need APIs. There are a lot of business rules involved, so my plan is to create an API project in the same solution and define API methods that will be calling my Business Layer which has rules written in it. So all business logic in one place and being accessed from web applications and mobile apps.
I was exploring best practices to secure Web APIs, there I found IdentityServer4. I have successfully configured the IdentityServer4. It's up and running. I am clear from the API side that what I need to do. I want my existing web application to also use IdentityServer4 for authentication and authorization. Like said before I need to create an Asp.Net user behind the scenes on the creation of an employee, so I have used UserManager and RoleManger in my Business Layer for this purpose.
I am not sure whether this is a valid scenario or not. But all I want is to replace only the authentication (Actually Login, forgot password, reset password) part of my web application with IdentityServer but my custom logic to create AspNetuser and roles in the business layer should remain intact.
When I remove the AddIdentity() part from my Startup, it starts to throw DI exceptions for SignInManager, RoleManager, and UserManger which I have used in my business layer.
services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
I cannot remove them because of behind the scene user creation on the creation of employees.
I am open to suggestions as long as my business layer is least affected.