aspnet / Identity

[Archived] ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.97k stars 871 forks source link

Replace a Role Validator #2080

Closed mmillican closed 5 years ago

mmillican commented 5 years ago

I am trying to create a custom role validator to support pseudo-multi-tenancy (which I know is not officially supported in Identity) and am running into some issues.

I've verified that my validator does work and is being called. However, the default validator appears to be called also.

Here's my Identity service registration

services.AddIdentity<User, Role>(setup =>
    {
        // Redacted settings
    })
    .AddRoleValidator<CustomRoleValidator<Role>>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultTokenProviders();

How can I remove the default RoleValidator?

HaoK commented 5 years ago

If you add a IRoleValidator<Role> before calling AddIdentity, it should skip adding the default one. Alternatively i believe you can remove service registrations directly as well, but try adding yours first

mmillican commented 5 years ago

Thanks @HaoK! That did the trick.

I also had to change the unique index on the Roles table as well.