I'm trying to use authentication in an ASP.NET Core project using Angular. The problem is that we have a database full of tables that are already in use. In particular, we have a User
table and a UserTypes
table which is basically our 'Roles.' I would like to use IdentityServer since that seems to be the default option when creating a new project. I have used the following command in Package Manager Console:
Scaffold-DbContext "Server=-----;Database=MP_Administration;Persist Security Info=True;User id=sa; Password=------"
Microsoft.EntityFrameworkCore.SqlServer
-OutputDir Models -Context MpContext -t User, UserType
It works fine but in my Startup.cs
I'm struggling to make things work. I would like to do something like this:
services.AddDbContext<MpContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MPAdministrationDatabase")));
services.AddDefaultIdentity<User>()
.AddEntityFrameworkStores<MpContext>();
services.AddIdentityServer()
.AddApiAuthorization<User, MpContext>();
services.AddAuthentication()
.AddIdentityServerJwt();
But the Identity Server doesn't seem to like the MpContext
(which implements DbContext
) generated by the scaffolding command mentioned earlier. I've tried writing my own versions of ApiAuthorizationDbContext
which would take the place of DbContext
, as well as KeyApiAuthorizationDbContext
, but I'm slowly starting to feel like I'm sinking. Any help would be greatly appreciated.