JonPSmith / AuthPermissions.AspNetCore

This library provides extra authorization and multi-tenant features to an ASP.NET Core application.
https://www.thereformedprogrammer.net/finally-a-library-that-improves-role-authorization-in-asp-net-core/
MIT License
770 stars 158 forks source link

Version 2: Multi-tenant, Access the data of another tenant user #10

Closed JonPSmith closed 2 years ago

JonPSmith commented 2 years ago

In the original multi-tenant application I designed the App Admin (i.e. a user manages the whole application, not linked to tenant) needed to access the data that a tenant user to understand / fix an tenant user's data.

I will add a "Access data as another tenant user" feature which will override the DataKey of the current user with the DataKey from the selected tenant user. This provides a App Admin or an Tenant Admin to access the user's data, plus a feature useful in hierarchical multi-tenant applications.

The first thing is to find the tenant user that you want to access their data. This will use the current List AuthP's Users. The list user already has the ability to only return the users that the current user can see, e.g. App Admin can see all user, Tenant Users can only see the users in their tenant.

Once a user has been found you will call the StartAccessToUserDataAsync method with your found user. This will create a Cookie that will contain the selected user's DataKey which will override the default DataKey of the current user. This Cookie should also show a prominent display showing you are in this mode. The StopAccessToUserDataAsync method will remove the Cookie and return to normal usage.

There are two usages of this feature:

JonPSmith commented 2 years ago

Version 2.2.0 is out and the documentation for the "link to tenant data" feature can be found here.