Dashboard for Blazor - How to Implement Multi-Tenant Dashboard Architecture using the ASP.NET Core's Identity Authentication System
This example shows how to configure the Dashboard component for Blazor so that it works in the multi-user environment.
You can identify a user in the ASP.NET Core's HttpContext.User
and return the user-specific content.
This example was created based on the Blazor Server App Visual Studio template with the Authentication Type = 'Individual Accounts' setting (see Secure ASP.NET Core Blazor Server apps). The example uses the ASP.NET Core's Identity mechanism for authentication. For this reason, you need to follow the steps below to initialize the Identity database and register required user accounts in it:
-
Apply the
00000000000000_CreateIdentitySchema
migration to theaspnet-BlazorAuth-9F8F37E8-C7E8-4D29-BFE6-47204A65FA44
database. You can run the following command in the Package Manager Console for this purpose:PM> Update-Database
-
In this example, the following user accounts were authorized:
Email: admin@gmail.com Password: 1*234aB Email: user@gmail.com Password: 1*234aC Email: guest@gmail.com Password: 1*234aD
If the current accounts do not exist, go to the Register page (Identity/Account/Register
) to create and confirm these user accounts.
You can limit access to sensitive information depending on the current user's ID. The MultiTenantDashboardConfigurator class is an entry point for configuring all providers. Every custom store/provider reads the IHttpContextAccessor.HttpContext.User.Identity
. In the MultiTenantDashboardConfigurator
class, use the standard IHttpContextAccessor with dependency injection to access the HTTP context and pass the retrieved user name to Dashboard providers listed above. This class is registered as a scoped DI service in the Program.cs file.
When the application starts, you see the Index view where you can select a user. Use the Log in link for this purpose. Below is a table that illustrates the user IDs and their associated rights in this example:
Role | Dashboard Storage | DataSource Storage | ConnectionString Provider | DBSchema Provider | Working Mode | Create/Edit |
---|---|---|---|---|---|---|
Admin | dashboard1_admin, dashboard2_admin | SqlDataSource, JsonDataSource | Northwind, CarsXtraScheduling | All (Categories, Products, Cars,...) | Designer, Viewer | Yes |
User | dashboard1_user | SqlDataSource | CarsXtraScheduling | Cars | Designer, Viewer | No |
Guest | dashboard1_guest | - | - | - | ViewerOnly | - |
Unauthorized | - | - | - | - | ViewerOnly | - |
You can return the following user-specific content:
Custom dashboard storage allows you to specify which dashboards the user can access, edit, and save.
API: IEditableDashboardStorage Interface
Files to review: CustomDashboardStorage.cs
Custom data source storage allows you to specify which data sources are available to the user.
API: IDataSourceStorage Interface
Files to review: CustomDataSourceStorage.cs
A custom data source schema provider allows you to filter the data source for different users to show only a part of the data source.
Files to review: CustomDBSchemaProvider.cs
A custom connection string provider allows you to specify connection strings depending on the user's access rights.
API: IDataSourceWizardConnectionStringsProvider Interface
Files to review: CustomConnectionStringProvider.cs
The Web Dashboard control can operate in ViewerOnly
mode for unauthorized users. To do this, handle the DashboardConfigurator.VerifyClientTrustLevel event and set the e.ClientTrustLevel
property to Restricted
. This setting prevents inadvertent or unauthorized modifications of dashboards stored on a server. You can find more information in the following help section: Security Considerations - Working Mode Access Rights.
API: DashboardConfigurator.VerifyClientTrustLevel Event
Files to review: Dashboard.razor and MultiTenantDashboardConfigurator.cs
- Create an ASP.NET Core Dashboard Application
- Manage Multi-Tenancy
- ASP.NET Core Blazor authentication and authorization
- Dashboard for ASP.NET Core - How to implement multi-tenant Dashboard architecture
- Dashboard for ASP.NET Core - How to load different data based on the current user
- Dashboard for ASP.NET Core - How to implement authentication
- Dashboard for MVC - How to implement multi-tenant Dashboard architecture
- Dashboard for MVC - How to load and save dashboards from/to a database
- Dashboard for MVC - How to load different data based on the current user
(you will be redirected to DevExpress.com to submit your response)