New to IdentityServer 4. I followed the IdentityServer4 EntityFramework sample here on the documentation.
After the migration script is run
dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb
It works and now my application has 3 DB Contexts.
My question is what are the two DB contexts for? What is the difference between the application db context and the other two?
If I update or add any models, do I need to update all three? Or when should I run a migration on the ApplicationDbContext and when to run on the other two.
Any insight or literature on these is appreciated. Thanks.
PersistedGrantDbContext - used for temporary operational data such as authorization codes, and refresh tokens.
By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project."
Figured it out. Leaving this for anyone confused about this as I was.
There are 3 DB contexts and, as @Jasen mentioned, it is to split up access to the entities, or tables.
IdeneityServer4 + EntityFramework + ASP.NET Identity creates the following tables in the database:
The contexts are used to reference the following:
ApplicationDbContext - responsible for users involved with ASP.NET Identity so tables
PersistedGrantDbContext - responsible for storing consent, authorization codes, refresh tokens, and reference tokens
ConfigurationDbContext - responsible for everything else remaining in the database
So in regards to migrations, if I update any of the AspNet Identity models (i.e. ApplicationUser) then I would run the migration on the ApplicationDbContext. Any client tables or other scopes would be run on the ConfigurationDbContext. And to access the entites (or tables) would be the corresponding context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With