I am getting below exception even after registering the AddDefaultIdentity
System.InvalidOperationException: Service type: IUserClaimsPrincipalFactory`1 not registered.
Here's the Identity registration code:
services.AddDefaultIdentity<ApplicationUser>(options =>
{
//Disable account confirmation.
options.SignIn.RequireConfirmedAccount = false;
options.SignIn.RequireConfirmedEmail = false;
options.SignIn.RequireConfirmedPhoneNumber = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>();
And here's the IdentityServer code:
var builder = services.AddIdentityServer()
.AddInMemoryApiScopes(IdentityServerConfig.ApiScopes)
.AddInMemoryIdentityResources(IdentityServerConfig.IdentityResources)
.AddInMemoryApiResources(IdentityServerConfig.ApiResources)
.AddInMemoryClients(IdentityServerConfig.Clients)
.AddAspNetIdentity<IdentityUser>();
The IdentityServer IUserService that was used to integrate your user store is also gone, replaced with a new user store abstraction in the form of IProfileService and IResourceOwnerPasswordValidator . You must now implement user authentication yourself (and that’s a good thing).
An ASP.NET Identity-based implementation is provided for managing the identity database for users of IdentityServer. This implementation implements the extensibility points in IdentityServer needed to load identity data for your users to emit claims into tokens. The repo for this support is located here and the NuGet package is here.
Implementing IdentityServer4 on ASP.NET Core and .NET Core 1 OpenID Connect Discovery Document. ... 2 Signing Credentials. ... 3 Clients, Resources and Users. ... 4 OAuth Functionality. ... 5 Protecting an API. ... 6 Adding a User Interface. ... 7 OpenID Connect. ... 8 Entity Framework Core. ... 9 ASP.NET Core Identity. ...
Here is the list of tables that we have in the “IdentityServerQuickstart” database. Seven tables that start with the “AspNet” prefix are the ASP.NET Core Identity tables that hold user store (users, claims, roles, logins, and user tokens).
I spent hours solving this typo.
The problem was that my registration was wrong.
I was working with ApplicationUser
but I was registering IdentityUser
in the identity server.
I fixed my problem by setting the ApplicationUser
in both AddIdentityServer()
and AddDefaultIdentity()
.
Here's the working code: .Net Core Identity
services.AddDefaultIdentity<ApplicationUser>(options =>
{
//Disable account confirmation.
options.SignIn.RequireConfirmedAccount = false;
options.SignIn.RequireConfirmedEmail = false;
options.SignIn.RequireConfirmedPhoneNumber = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>();
IdentityServer4:
var builder = services.AddIdentityServer()
.AddInMemoryApiScopes(IdentityServerConfig.ApiScopes)
.AddInMemoryIdentityResources(IdentityServerConfig.IdentityResources)
.AddInMemoryApiResources(IdentityServerConfig.ApiResources)
.AddInMemoryClients(IdentityServerConfig.Clients)
.AddAspNetIdentity<ApplicationUser>();
Notice the use of ApplicationUser
.
I posted question here so that I remember it next time.
I fixed this error by changing the order. I had
var builder = services.AddIdentityServer()
.AddInMemoryIdentityResources(Config.IdentityResources)
.AddInMemoryClients(Config.Clients)
.AddAspNetIdentity<ApplicationUser>();
builder.AddDeveloperSigningCredential();
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("ApplicationDbContext")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
Now I have:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("ApplicationDbContext")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
var builder = services.AddIdentityServer()
.AddInMemoryIdentityResources(Config.IdentityResources)
.AddInMemoryClients(Config.Clients)
.AddAspNetIdentity<ApplicationUser>();
builder.AddDeveloperSigningCredential();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With