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

Hierarchical multi-tenant - problem when using the Move feature means some logged-in users will have the wrong DataKey #22

Closed JonPSmith closed 2 years ago

JonPSmith commented 2 years ago

There is a problem when using the hierarchical Move feature with the current arrangement. The problem comes that logged-in users that are linked to tenants that have been moved will have the wrong DataKey. This could cause lots of problems.

The best solution is remove the DataKey claim and replace it with the tenant primary key (tenantId) in the claims. The tenantId doesn’t change with a move and you then use the tenantId to get the DataKey. The down side is getting the DataKey adds an extra database access to get the Parentkey from the tenant, which when combined with the tenantId will create the correct DataKey. To do this you would create a different IGetDataKeyFromUser which contains a lazy DataKey which accesses the AuthP tenant to get the DataKey.

NOTE: This is a breaking change, and needs a way to transition an already running application

JonPSmith commented 2 years ago

While replacing the DataKey with the tenant primary key (tenantId) is one way around this problem, the the 2.3.0 version of this library provides a non-breaking approach. This two features in version 2.3.0, they are

This approach has some (small) downsides: