Skip to content
Einar Ingebrigtsen edited this page Oct 26, 2015 · 6 revisions

Multi Tenants

Power BI is on its own a multi-tenant solution, meaning that there is one entry point for all organizations using the solution. This however raises a few challenges for applications wanting to utilize Power BI as its visualization engine, especially for data in transit - typically real time analytics. The main challenge sits in maintenance and how to deal with all this in a good way. Primary objective being that one deployment in a SaaS solution should be capable of pushing to the specific tenants Power BI dashboard.

Authentication

The key to being able to do this is how authentication is done for the Power BI APIs. Authentication is the thing that governs which tenant you're working with, and we can use this to our advantage. When using the REST APIs, Power BI needs there to be a authorization bearer token in the request header. This token is something we need to get from Azure Active Directory.

For every tenant we need to collect the necessary information in order for our system to asynchronously in the background be able to publish to the tenants Power BI dashboard. It is probably a good idea to let this collection of information be done by a user representing the tenant itself in an account setting page inside your system. This way you delegate the setup to the end users. The information in the form of access tokens and refresh tokens can then be saved in a data store for each tenant.

To keep your solution scalable, it is recommended that you use something like the Azure EventHub where you can then just publish events either from a part of your system that is able to aggregate / do analysis of data and publish to this instead of publishing directly to Power BI. This enables you to deal with scale and also making your core system less vulnerable. Besides, this is good practice in general for decoupling your system into specific responsibilities. You would then have something like an EventProcessor that will then take on the responsibility of dealing with sending the events to the correct Power BI dashboard based on tenant information in the events coming in.

Below shows an image of such a flow: ![](Multi Tenant Images/1.png)

In the repository, you will find a working sample that works exactly like this.

Topology

The topology of a multi tenant solution would be something like below: ![](Multi Tenant Images/2.png)

Tenancy Storage

In the library you'll find ConfigurationForTenants. This is an implementation for saving relevant configuration data for a tenant into Azure Table Storage. All you need to do is provide it with a StorageConfiguration object with relevant AccountName and AccessKey for your storage account.

var storageConfiguration = new StorageConfiguration {
	AccountName = "[Your Storage AccountName]",
	AccessKey = "[Your Storage AccessKey]"
}

Once you have this you can use it for getting configuration for a tenant :

var configurationForTenants = new ConfigurationForTenants(storageConfiguration);
var configuration = configurationForTenants.GetFor("Tenant Name");

The TenantConfiguration object contains amongst other things the different tokens. So after authentication you would stick the tokens into this and save it:

configuration.AccessToken = "{The access token returned from authentication}";
configuration.RefreshToken = "{The refresh token returned from authentication}";

configurationForTenants.Save(configuration);

If you want to get all the tenants and their configuration, you simply call the GetAll() method:

var tenantsConfiguration = configurationForTenants.GetAll();