Skip to content

This example shows how to configure the Dashboard component for Blazor so that it works in the multi-user environment.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/dashboard-blazor-server-multi-tenancy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

How to Launch

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:

  1. Apply the 00000000000000_CreateIdentitySchema migration to the aspnet-BlazorAuth-9F8F37E8-C7E8-4D29-BFE6-47204A65FA44 database. You can run the following command in the Package Manager Console for this purpose:

    PM> Update-Database
    
  2. 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.

Example Overview

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 -

Example Details

You can return the following user-specific content:

Dashboards

Custom dashboard storage allows you to specify which dashboards the user can access, edit, and save.

API: IEditableDashboardStorage Interface

Files to review: CustomDashboardStorage.cs

Data Sources

Custom data source storage allows you to specify which data sources are available to the user.

API: IDataSourceStorage Interface

Files to review: CustomDataSourceStorage.cs

Data Source Schema

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.

API: DBSchemaProviderEx Class

Files to review: CustomDBSchemaProvider.cs

Connection Strings

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

Working Mode

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

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)