Skip to content
meliora-solution edited this page Jan 31, 2024 · 17 revisions

Unified User Identity with Authp for Multitenant Blazor Applications

This project aims to establish a unified user identity for multitenant environments across multiple projects and create a simple example of the implementation of Authp. The implementation relies on the AuthPermissions.AspNetCore library developed by John P Smith, available at https://github.com/JonPSmith/AuthPermissions.AspNetCore.

Background

Initially, I just want to have single user identity database for multiple projects. "I came across the Authp library and explored its potential for my use case. After working with it for some time, I discovered its capabilities extending beyond single identity, even embracing multitenancy.

But After working with it for quite sometime, it turns out that not only that this library can be use for single identity for multiple projects but also can be use for multitenancy.

There is one field that I really want to add to base Identity user class, DateCreated. So I can know when is the user first join as a user. There are two databases I created.

  • IdentityUser100. This database is a customize AspNetCore IdentityUser.
  • EasyStock. The EasyStock database serves as the implementation ground for the multitenancy feature in the stock application example.

Create Databases

I already migrate for those two databases. To create databases, just use update-database command. Please do not apply migration for IdentityUser100DbContext because this database will be created automatically along with Authp tables when running UserManagement project.

Create EasyStockDb.

  • Select EasyStockDb for default project.
  • on package manager console enter this command PM> update-database -context "EasyStockDbContext"

List Image 1: Create EasyStock Database

image

  • I am using https://www.fluentui-blazor.net/ template for this project.
  • Choose Authentication Type : Invidual Accounts.
  • Interactive Render Mode = None

List Image 2 : UserManagement Project

image

Run Application

  • UserManagement is single startup project. The purpose of the project is mainly for management, creating tenant, inviteuser, create roles.
  • BlazorServerEasyStock is multiple startup projects. It needs web api project to run. As the name implies, this project is related to EasyStock, create contact, product.

Initially UserManagement Project should be run first to create IdentityUser database. This will create IdentityUserDb100Authp SqlServer database in (localdb).

List Image 3 : Multiple Startup Project

image

Web Api project should run before BlazorServerEasyStock.

Clone this wiki locally