Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with IdentityServer4 upgrade to .NET Core 2.0 (AddConfigurationStore, AddOperationalStore)

I upgraded from .NET Core 1.1 to .NET Core 2.0 and encountered the following issue (I also upgraded a few libraries to support .net core 2.0 aswell)

CS1929 'ConfigurationStoreOptions' does not contain a definition for 'UseNpgsql' and the best extension method overload 'NpgsqlDbContextOptionsExtensions.UseNpgsql(DbContextOptionsBuilder, string, Action)' requires a receiver of type 'DbContextOptionsBuilder'

Startup.cs

        services.AddIdentityServer()
            .AddSigningCredential(Certificate.Get())
            .AddAspNetIdentity<User>()
            .AddConfigurationStore(builder =>
                builder.UseNpgsql(connectionString, options =>
                    options.MigrationsAssembly(migrationsAssembly)))
            .AddOperationalStore(builder =>
                builder.UseNpgsql(connectionString, options =>
                    options.MigrationsAssembly(migrationsAssembly)));

Same issue when using UseSqlServer

// configure identity server with in-memory users, but EF stores for clients and resources
services.AddIdentityServer()
    .AddTemporarySigningCredential()
    .AddTestUsers(Config.GetUsers())
    .AddConfigurationStore(builder =>
        builder.UseSqlServer(connectionString, options =>
            options.MigrationsAssembly(migrationsAssembly)))
    .AddOperationalStore(builder =>
        builder.UseSqlServer(connectionString, options =>
            options.MigrationsAssembly(migrationsAssembly)));

http://docs.identityserver.io/en/release/quickstarts/8_entity_framework.html

Note: I have added "using Microsoft.EntityFrameworkCore;"

like image 649
001 Avatar asked Dec 14 '22 21:12

001


1 Answers

Solution:

        services.AddIdentityServer()
            .AddSigningCredential(Certificate.Get())
            .AddAspNetIdentity<User>()
            .AddConfigurationStore(options =>
            {
                options.ConfigureDbContext = builder =>
                    builder.UseNpgsql(connectionString,
                        sql => sql.MigrationsAssembly(migrationsAssembly));
            })
            // this adds the operational data from DB (codes, tokens, consents)
            .AddOperationalStore(options =>
            {
                options.ConfigureDbContext = builder =>
                    builder.UseNpgsql(connectionString,
                        sql => sql.MigrationsAssembly(migrationsAssembly));

                // this enables automatic token cleanup. this is optional.
                options.EnableTokenCleanup = true;
                options.TokenCleanupInterval = 30;
            });
like image 121
001 Avatar answered Dec 16 '22 09:12

001