Multi-Tenant does not cater for Role with same Role-Name in > 1 Tenant

I have created an issue (here)

Best wishes,
John

Thanks, it will be fixed in our update next week. In the meantime you can add the following code to your app:

    public class MultiTenancyUserStore : UserStore<ApplicationUser, ApplicationRole, ApplicationIdentityDbContext>
    {
        private readonly IHttpContextAccessor httpContextAccessor;
        public MultiTenancyUserStore(IHttpContextAccessor httpContextAccessor, ApplicationIdentityDbContext context, IdentityErrorDescriber describer = null) : base(context, describer)
        {
            this.httpContextAccessor = httpContextAccessor;
        }

        private ApplicationTenant GetTenant()
        {
            var tenants = Context.Set<ApplicationTenant>().ToList();

            var host = httpContextAccessor.HttpContext.Request.Host.Value;

            return tenants.Where(t => t.Hosts.Split(',').Where(h => h.Contains(host)).Any()).FirstOrDefault();
        }

        protected override async Task<ApplicationRole> FindRoleAsync(string normalizedRoleName, System.Threading.CancellationToken cancellationToken)
        {
            var tenant = GetTenant();
            ApplicationRole role = null;

            if (tenant != null)
            {
                role = await Context.Set<ApplicationRole>().SingleOrDefaultAsync(r => r.NormalizedName == normalizedRoleName && r.TenantId == tenant.Id, cancellationToken);
            }

            return role;
        }
    }

...
and in Program.cs

services.AddTransient<IUserStore<ApplicationUser>, MultiTenancyUserStore>();
1 Like