IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

AddIdentityCore

Open jonathan-daniel opened this issue 3 years ago • 2 comments

Issue / Steps to reproduce the problem

This works:

services.AddDefaultIdentity<User>(options =>{
                options.User.RequireUniqueEmail = true;
                options.Stores.MaxLengthForKeys = 128;
            })
                .AddRoles<IdentityRole>()
                .AddEntityFrameworkStores<AppDbContext>()
                .AddSignInManager<SignInManager<User>>()
                .AddDefaultTokenProviders();

This throws a nullreference exception in app.UseIdentityServer();

services.AddIdentityCore<User>(options =>{
                options.User.RequireUniqueEmail = true;
                options.Stores.MaxLengthForKeys = 128;
            })
                .AddRoles<IdentityRole>()
                .AddEntityFrameworkStores<AppDbContext>()
                .AddSignInManager<SignInManager<User>>()
                .AddDefaultTokenProviders();

I looked into the source of AddDefaultIdentity and its almost the same as AddIdentityCore except that it adds cookies.

Relevant parts of the log file

 	IdentityServer4.dll!Microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.ValidateAsync(System.IServiceProvider services, Microsoft.Extensions.Logging.ILogger logger)	C#
>	IdentityServer4.dll!Microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.Validate(Microsoft.AspNetCore.Builder.IApplicationBuilder app) Line 54	C#
 	IdentityServer4.dll!Microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.UseIdentityServer(Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.AspNetCore.Builder.IdentityServerMiddlewareOptions options) Line 19	C#
 	Project.dll!Project.Startup.Configure(Microsoft.AspNetCore.Builder.IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IWebHostEnvironment env, Microsoft.AspNetCore.Identity.RoleManager<Microsoft.AspNetCore.Identity.IdentityRole> roleManager) Line 152	C#

IdentityServer4.Startup: Information: Using explicitly configured authentication scheme Identity.Application for IdentityServer
Exception thrown: 'System.NullReferenceException' in IdentityServer4.dll
Object reference not set to an instance of an object.

jonathan-daniel avatar Feb 06 '21 18:02 jonathan-daniel

Brother, did you solve this problem, I also encountered it

SmRiley avatar Jul 12 '21 09:07 SmRiley

Brother, did you solve this problem, I also encountered it

Yeah, was this ever solved???

fafafooey916 avatar Jun 02 '22 03:06 fafafooey916