Lection 53, IdentityServer4 – Using LocalDb for IdentityServer4 and ASP.NET Identity



Lection 53, IdentityServer4 – Using LocalDb for IdentityServer4 and ASP.NET Identity

Lection 53, IdentityServer4 - Using LocalDb for IdentityServer4 and ASP.NET Identity

Lection 53, IdentityServer4 – Using LocalDB for IdentityServer4 and ASP.NET Identity

Using EntityFramework Core for configuration and operational data: https://identityserver4.readthedocs.io/en/latest/quickstarts/5_entityframework.html

Migrations Overview: https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli

Applying Migrations: https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying?tabs=dotnet-core-cli

1. Switch to LocalDb
1.1. appsettings.json
“DefaultConnection”: “Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.IdSrvQuickstart.FirstIdSrvAspNetIdentity;trusted_connection=yes;”

1.2. Startup.cs
options.UseSqlServer(

1.3. Redo the migrations

Make sure you have
1.3.1. dotnet add package Microsoft.EntityFrameworkCore.SqlServer
1.3.2. dotnet tool install –global dotnet-ef
1.3.3. dotnet add package Microsoft.EntityFrameworkCore.Design
1.3.4. dotnet ef migrations add CreateIdentitySchema -c ApplicationDbContext -o Data/Migrations

2. Update the database
dotnet ef database update

3. Use EF with IdentityServer4
dotnet add package IdentityServer4.EntityFramework

4. Adding Migrations
dotnet tool install –global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design

4.1. dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb

4.2. dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb

5. Change the stores in the Startup
5.1.
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
.AddConfigurationStore(options…

5.2. seed the DB in Startup from Config.cs

6. Run the App. The tables will be created and seeded with data from Config.cs
InitializeDatabase(app);

private void InitializeDatabase(IApplicationBuilder app)
{
using (var serviceScope = app.ApplicationServices.GetService…

Comments are closed.