radzenhq / radzen-blazor-studio

Sample applications created with Radzen Blazor Studio
https://www.radzen.com/blazor-studio
18 stars 3 forks source link

Adding ASP.Net Identity does not show the users, roles, or tenants in Admin's dropdown #147

Closed VR-Architect closed 2 weeks ago

VR-Architect commented 2 weeks ago

I created a new project using Postgresql and added ASP.NET Identity to the project. When I run the project, I don't see the Users, Roles, or Tenants in the menu at the top right under the Admin user. According to the tutorial video, they should be there. I see that the items exist in the menu code and the pages exists so I am guessing either the correct roles are not be automatically assigned to the various pages and/or the admin user is not getting the correct permission default set?

I have tried this from scratch multiple times with the same results.

I am stuck and not able to move forward with my corporate project which we just purchased this for.

VR-Architect commented 2 weeks ago

I noticed that when getting the roles, the user admin is not a member of a tenant and no tenant records exists. Should the seed created a tenant record and associated it with the Admin user? I was able to get pass the error on this page by putting in a check for username = "admin".

       public async Task<IEnumerable<ApplicationRole>> GetRoles()
       {
           var uri = new Uri(baseUri, $"ApplicationRoles");

           if (this.Principal.Identity.Name != "admin")
           {
               uri = uri.GetODataUri(filter: $"TenantId eq {Tenant.Id}");
           }

           var response = await httpClient.GetAsync(uri);

           var result = await response.ReadAsync<ODataServiceResult<ApplicationRole>>();

           return result.Value;
       }

Also the same for get Users:

        public async Task<IEnumerable<ApplicationUser>> GetUsers()
        {
            var uri = new Uri(baseUri, $"ApplicationUsers");

            if (this.Principal.Identity.Name != "admin")
            {
                uri = uri.GetODataUri(filter: $"TenantId eq {Tenant.Id}");
            }

            var response = await httpClient.GetAsync(uri);

            var result = await response.ReadAsync<ODataServiceResult<ApplicationUser>>();

            return result.Value;
        }
VR-Architect commented 2 weeks ago

In ApplicationController's Tenant Post, it is checking for the username of "tenantsadmin" but the method receives "admin" so the controller is passing back an Unauthorized. So I guess it is not very clear to me the intent of the "admin" user verses the "tenantsadmin" user. Basically we need 2 roles; admin who can create and see all tenants with their users, and the ability for the tenant to manage their own users only and not create other tenants.

akorchev commented 2 weeks ago

I suggest checking the related help article: https://www.radzen.com/blazor-studio/documentation/security/multi-tenancy/#create-tenants