Skip to content

Creating a multi tenant app

Jon P Smith edited this page Aug 12, 2021 · 10 revisions

This page gives an overview of what you need to do to use AuthP's multi-tenant to build a multi-tenant application.

1. Turn on AuthP's multi-tenant feature

This is explained in Multi tenant configuration.

2. Create AuthP Tenants

You need to create a AuthP Tenant (see Multi tenant admin service) for each group of data. Each tenant contains a method called GetTenantDataKey that returns a string used in EF Core's query filter to only show data in the specific AuthP Tenant.

NOTE: if you are using AuthP's HierarchicalTenant, then tenants can link to a 'parent' Tenant - see Multi tenant explained.

3. Assign a AuthP Tenant to a AuthUser

When a user logs in AuthP is set up to add a DataKey claim to the logged-in user. This is automatic if you are using the authentication cookie approach, or by AuthP's ITokenBuilder service that can create the JWT Token for you.

4. Inject the user's DataKey value into you application DbContext

The typical way to do this is to create a service that which will capture the ClaimsPrincipal of the currently logged in user and extract the DataKey claim. AuthP registers the GetDataKeyFilterFromUser against the IDataKeyFilter interface.

This allows you to add a IDataKeyFilter parameter to your application's DbContext

Articles / Videos

Concepts

Setup

Usage

Admin

SupportCode

Clone this wiki locally