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

Published: 21 August 2020
on channel: Stoyan Cheresharov
4,851
39

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

Using EntityFramework Core for configuration and operational data: https://identityserver4.readthedocs.i...

Migrations Overview: https://docs.microsoft.com/en-us/ef/c...

Applying Migrations: https://docs.microsoft.com/en-us/ef/c...

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


Watch video Lection 53, IdentityServer4 - Using LocalDb for IdentityServer4 and ASP.NET Identity online without registration, duration hours minute second in high quality. This video was added by user Stoyan Cheresharov 21 August 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 4,851 once and liked it 39 people.