skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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)
        {
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search