0

I have set my IdentityServer4 in a service fabric project, all is working fine until I decided to stop loading my configuration in-memory and use the ConfigurationDb and PersistedGrantDb they have. I get the error on cmd of "Cant find PersistedGrantDbContext"; if I change the program.cs to run with the webhost code Im able to get it and create the migrations. Is there something Im missing here? Can it be done in a different way? This is my startup code for identity server, keep in mind I have the code related to load the context in comments for now.

        const string connectionString = @"Data Source=.;Initial Catalog=DbIdentity;MultipleActiveResultSets=true; User ID=admin; Password=123";
        var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;

services.AddIdentityServer(options =>
        {
            options.Events.RaiseErrorEvents = true;
            options.Events.RaiseInformationEvents = true;
            options.Events.RaiseFailureEvents = true;
            options.Events.RaiseSuccessEvents = true;
        })
        .AddInMemoryClients(IdentityServerConfiguration.GetClients(clientSettings))
        .AddInMemoryApiResources(IdentityServerConfiguration.GetApiResources(clientSettings))
        .AddInMemoryIdentityResources(IdentityServerConfiguration.GetIdentityResources())
       // .AddDeveloperSigningCredential();
        .AddSigningCredential(cert);
        //.AddConfigurationStore(options =>
        //{
        //    options.ConfigureDbContext = builder =>
        //        builder.UseSqlServer(connectionString,
        //            sql => sql.MigrationsAssembly(migrationsAssembly));
        //})
        //.AddOperationalStore(options =>
        //{
        //    options.ConfigureDbContext = builder =>
        //        builder.UseSqlServer(connectionString,
        //            sql => sql.MigrationsAssembly(migrationsAssembly));

        //    options.EnableTokenCleanup = true;
        //    options.TokenCleanupInterval = 30;
        //});

let me know if you need more context or code to figure this out. Thanks!

marsalal1014
  • 1,897
  • 3
  • 17
  • 24
  • Have you setup the Configruation context and Persitance context in your db yet? Are you using the ID4 seed setup or you creating your own? – Aeseir Feb 23 '18 at 02:14
  • @Aeseir Im using the IS4 seed setup. How do you setup the ConfiguratioDbContext and PersistanceDbContext in the db? – marsalal1014 Feb 23 '18 at 15:27

1 Answers1

0

Based on the commentary for the question i don't think the db has been setup.

You need to run the update database command against the proper context to ensure it gets created and populated.

dotnet-cli

dotnet ef database update -c PersistedGrantDbContext
dotnet ef database update -c ConfigurationDbContext

Package Manager Console

Update-Database -Context PersistedGrantDbContext
Update-Database -Context ConfigurationDbContext

If the contexts aren't in the db this will create them and seed them with creation data.

Aeseir
  • 7,754
  • 10
  • 58
  • 107
  • yeap, thats what Ive done and after running those commands I get the errors about PersistedGrantDbContext cant be found. This happens if the program.cs has the service fabric standard main method, if It switch it for the webhost code, it works. Im affraid this can be an issue once I deploy to Azure and production – marsalal1014 Feb 26 '18 at 17:06
  • Unfortunately it's not what happened to me. After i manually trigger those commands, everything else worked. Give it a go, if it doesn't i'll look at other options. – Aeseir Feb 26 '18 at 22:22