What is different between ApiAuthorizationDbContext<TUser>
and IdentityDbContext<TUser>
in a Web API project?
DbContext can inherit those but don't know what is different between those
(I'm using .NET 6.0 and Entity Framework Core for Web API project)
CodePudding user response:
As you can see in the source code, or in the documentation, ApiAuthorizationDbContext inherits from IdentityDbContext and it also implements IPersistedGrantDbContext which is responsible for storing consent, authorization codes, refresh tokens, and reference tokens.
CodePudding user response:
Except for what @gbede said about the ApiAuthorizationDbContext<TUser>
usage, ApiAuthorizationDbContext<TUser>
force TUser
to extends IdentityUser
instead of IdentityUser<TKey>
. This means it is impossible to use Identity Server on application with ApplicationUser : IdentityUser<Guid>
(or anything different from IdentityUser<string>
).
IdentityDbContext
can work with different IdentityUser<TKey>
, you can customize your model like:
public class AppUser:IdentityUser<Guid>
{
//add any additional properties
}
Then use the DbContext like:
public class MvcProjContext : IdentityDbContext<AppUser,IdentityRole<Guid>,Guid>
{
public MvcProjContext (DbContextOptions<MvcProjContext> options)
: base(options)
{
}
}