ZEMA.SquareOrganization
3.0.45
dotnet add package ZEMA.SquareOrganization --version 3.0.45
NuGet\Install-Package ZEMA.SquareOrganization -Version 3.0.45
<PackageReference Include="ZEMA.SquareOrganization" Version="3.0.45" />
<PackageVersion Include="ZEMA.SquareOrganization" Version="3.0.45" />
<PackageReference Include="ZEMA.SquareOrganization" />
paket add ZEMA.SquareOrganization --version 3.0.45
#r "nuget: ZEMA.SquareOrganization, 3.0.45"
#:package ZEMA.SquareOrganization@3.0.45
#addin nuget:?package=ZEMA.SquareOrganization&version=3.0.45
#tool nuget:?package=ZEMA.SquareOrganization&version=3.0.45
ZEMA.SquareOrganization
A .NET 10 library that extends ZEMA.Square.Lib to add multi-organization (multi-tenant) support to any ASP.NET Core application built on the ZEMA Square platform.
Installation
dotnet add package ZEMA.SquareOrganization --version 3.0.*
Requirements
- .NET 10.0
- ZEMA.Square.Lib 3.0.x
- PostgreSQL
Features
- Multi-organization (multi-tenant) data isolation via an
OrgIdJWT claim, enforced by an"Organization"authorization policy - User ↔ organization associations with an owner-managed/archivable rule hierarchy
- Organization "Identification" (URL slug) — unique, indexed, and returned in the user's organization list
- Session-scoped, org-aware token refresh alongside explicit org switching
- Countries, states, time zones, languages, and regions — seeded automatically
- EF Core
DbContext(PostgreSQL via Npgsql) with full entity configuration - AutoMapper profile for org DTO transformations
- Login-as (user impersonation) with full org context and a correct audit trail
Getting Started
1. Register services
builder.Services.AddOrganizationIdentitySquare<TContext, TUser, TRole, TScreen, TOrganization>(
builder.Configuration,
SupportedDBs.PostgreSQL,
connectionStringName: "DefaultConnection",
appName: "MyApp",
LogInformation: (type, msg) => logger.LogInformation("{Type}: {Msg}", type, msg),
LogDebug: (type, msg) => logger.LogDebug("{Type}: {Msg}", type, msg),
LogWarning: (type, ex, msg) => logger.LogWarning(ex, "{Type}: {Msg}", type, msg),
LogError: (type, ex, msg) => logger.LogError(ex, "{Type}: {Msg}", type, msg),
passwordOptions: new PasswordOptions { RequireDigit = true },
applicationAssemblies: [typeof(Program).Assembly]);
This registers ASP.NET Core Identity via ZEMA.Square.Lib, adds an "Organization" authorization policy that requires the OrgId claim, and registers your TContext DbContext.
2. Seed reference data
await SeedOrganizationBase.SeedDataAsync<
TDataContext, TUser, TRole, TScreen,
TAddress, TAppTimeZone, TCountry, TCountryStateTimeZone,
TLanguage, TOrganization, TRegion, TRegionLanguage, TState>(
context, userManager, roleManager, squareRoleManagement,
appName: "MyApp",
regionDataArray: regions,
languageDataArray: languages,
initUser: () => new UserData { Email = "admin@myapp.com" },
initPassword: () => "changeme",
initDefOrgData: () => new OrgData { Name = "Default Org" });
Populates countries, states, time zones, languages, regions, a default organization, and a super user on first run.
3. Protect routes
[Authorize(Policy = "Organization")]
[ApiController]
public class MyController : ControllerBase { ... }
4. Scope business rules to the current organization
Inherit from the base rule matching your entity's primary key type and deletion strategy. The base class reads OrgId from the HTTP context and automatically filters queries and stamps writes with the current organization.
public class ProductRule : OrganizationArchivableBaseGuidRule<
TDataContext, Product, ProductVm, ProductListParams, ProductM>
{
public ProductRule(ServiceFactory sf, TDataContext ctx, IHttpContextAccessor http)
: base(sf, ctx, http) { }
}
Rule hierarchy:
OrganizationBaseRule<>
└── OrganizationOwnerBaseRule<> — owner-managed entities
├── OrganizationOwnerBaseGuidRule<>
├── OrganizationOwnerBaseStringRule<>
├── OrganizationOwnerBaseValueRule<>
└── OrganizationArchivableBaseRule<> — soft-delete entities (extends Owner)
├── OrganizationArchivableBaseGuidRule<>
├── OrganizationArchivableBaseStringRule<>
└── OrganizationArchivableBaseValueRule<>
Built-in API Endpoints
OrganizationSquareAccountController<> provides:
| Method | Route | Description |
|---|---|---|
POST |
refresh |
Org-scoped session refresh. organizationId as a [FromForm] field (or X-Organization-Id header); no new refresh token is issued. |
GET |
user_organizations |
Lists the authenticated user's organizations, including each org's Identification (slug). |
POST |
set_user_organization |
Switches the current organization context; preserves the Actor claim during a login-as session. |
Login As (User Impersonation)
SquareOrganizationAccountRule<> extends the base login-as feature with organization awareness:
FindLoginUserAsynceagerly loads the target user'sUserOrganizationsandUserRolesso org context is available immediately after impersonation starts.- The JWT preserves two identity claims:
NameIdentifier(target user) andActor(original acting user). - Switching or refreshing an organization never mints a new refresh token — only the initial login does.
SetUserOrganizationcarries theActorclaim forward when the impersonator switches organizations, so identity is never lost across org switches.
Security Model
ISquareOrganizationLoggedUser— extends the base logged-user withOrganizationIdISquareOrganizationLoginData— extends login data withOrganizationIdandOrganizationIdentification- The
OrgIdclaim is propagated through the JWT and used by every rule to isolate data per tenant
Dependencies
| Package | Version |
|---|---|
| ZEMA.Square.Lib | 3.0.10 |
| AutoMapper | 16.2.0 |
| FluentValidation.AspNetCore | 11.3.1 |
| Microsoft.Extensions.Caching.Memory | 10.0.10 |
| Newtonsoft.Json | 13.0.4 |
| Npgsql | 10.0.3 |
| System.Security.Cryptography.Xml | 10.0.10 |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- AutoMapper (>= 16.2.0)
- FluentValidation.AspNetCore (>= 11.3.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.10)
- Newtonsoft.Json (>= 13.0.4)
- Npgsql (>= 10.0.3)
- System.Security.Cryptography.Xml (>= 10.0.10)
- ZEMA.Square.Lib (>= 3.0.60)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.45 | 460 | 10/15/2026 |
| 3.0.44 | 106 | 10/14/2026 |
| 3.0.43 | 108 | 10/14/2026 |
| 3.0.42 | 104 | 10/9/2026 |
| 3.0.41 | 92 | 10/8/2026 |
| 3.0.40 | 105 | 10/5/2026 |
| 3.0.39 | 110 | 9/30/2026 |
| 3.0.38 | 103 | 9/29/2026 |
| 3.0.37 | 98 | 9/28/2026 |
| 3.0.36 | 107 | 9/28/2026 |
| 3.0.35 | 120 | 9/17/2026 |
| 3.0.34 | 103 | 9/17/2026 |
| 3.0.33 | 103 | 9/17/2026 |
| 3.0.32 | 107 | 9/17/2026 |
| 3.0.31 | 95 | 9/17/2026 |
| 3.0.29 | 100 | 9/16/2026 |
| 3.0.26 | 128 | 9/16/2026 |
| 3.0.25 | 107 | 9/15/2026 |
| 3.0.24 | 131 | 9/9/2026 |
| 3.0.23 | 125 | 9/9/2026 |