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)
2
Answers
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.
Except for what @gbede said about the
ApiAuthorizationDbContext<TUser>
usage,ApiAuthorizationDbContext<TUser>
forceTUser
to extendsIdentityUser
instead ofIdentityUser<TKey>
. This means it is impossible to use Identity Server on application withApplicationUser : IdentityUser<Guid>
(or anything different fromIdentityUser<string>
).IdentityDbContext
can work with differentIdentityUser<TKey>
, you can customize your model like:Then use the DbContext like: