Identityserver4: Does idsrv4 supports asp.net identity with integer instead of guid?

Created on 14 Jun 2018  路  3Comments  路  Source: IdentityServer/IdentityServer4

I implemented ApplicationUser which should use int instead of guid:

    public class ApplicationUser : IdentityUser<int>
    {
    }
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, int>
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            // Customize the ASP.NET Identity model and override the defaults if needed.
            // For example, you can rename the ASP.NET Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);
        }
    }
    public class ApplicationUserRole : IdentityUserRole<int> { }
    public class ApplicationUserClaim : IdentityUserClaim<int> { }
    public class ApplicationUserLogin : IdentityUserLogin<int> { }
    public class ApplicationUserToken : IdentityUserToken<int> { }

    public class ApplicationRole : IdentityRole<int>
    {
        public ApplicationRole() { }
        public ApplicationRole(string name) { Name = name; }
    }

    public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationDbContext, int>
    {
        public ApplicationUserStore(ApplicationDbContext context)
            : base(context)
        {
        }
    }

I then register idsrv in startup:

            services.AddIdentity<ApplicationUser, ApplicationRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

When I run app I get error:

System.InvalidOperationException
HResult=0x80131509
Message=Service type: IUserClaimsPrincipalFactory`1 not registered.
Source=IdentityServer4.AspNetIdentity
StackTrace:
at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensions.AddDecoratorTService in C:\local\identityserver4\AspNetIdentitysrc\IdentityServer4.AspNetIdentity\IdentityServerBuilderExtensions.cs:line 100
at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensions.AddTransientDecoratorTService,TImplementation in C:\local\identityserver4\AspNetIdentitysrc\IdentityServer4.AspNetIdentity\IdentityServerBuilderExtensions.cs:line 62
at Microsoft.Extensions.DependencyInjection.IdentityServerBuilderExtensions.AddAspNetIdentityTUser in C:\local\identityserver4\AspNetIdentitysrc\IdentityServer4.AspNetIdentity\IdentityServerBuilderExtensions.cs:line 33

Most helpful comment

Ok as usual after I ask I find the answer.
I forgot to change this part:

            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryIdentityResources(Config.GetIdentityResources())
                .AddInMemoryApiResources(Config.GetApiResources())
                .AddInMemoryClients(Config.GetClients(Configuration.GetSection("HostSettings:WebAppClientUrl").Value.ToString()))
                .AddAspNetIdentity<ApplicationUser>();

I had AddAspNetIdentity< IdentityUser >();

All 3 comments

Ok as usual after I ask I find the answer.
I forgot to change this part:

            services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryIdentityResources(Config.GetIdentityResources())
                .AddInMemoryApiResources(Config.GetApiResources())
                .AddInMemoryClients(Config.GetClients(Configuration.GetSection("HostSettings:WebAppClientUrl").Value.ToString()))
                .AddAspNetIdentity<ApplicationUser>();

I had AddAspNetIdentity< IdentityUser >();

All set on this issue -- can we close?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings