Identity.Base.Organizations 0.7.12

dotnet add package Identity.Base.Organizations --version 0.7.12
                    
NuGet\Install-Package Identity.Base.Organizations -Version 0.7.12
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Identity.Base.Organizations" Version="0.7.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Identity.Base.Organizations" Version="0.7.12" />
                    
Directory.Packages.props
<PackageReference Include="Identity.Base.Organizations" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Identity.Base.Organizations --version 0.7.12
                    
#r "nuget: Identity.Base.Organizations, 0.7.12"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Identity.Base.Organizations@0.7.12
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Identity.Base.Organizations&version=0.7.12
                    
Install as a Cake Addin
#tool nuget:?package=Identity.Base.Organizations&version=0.7.12
                    
Install as a Cake Tool

Identity Base Organizations

For the canonical documentation (installation, endpoints, extension points) see docs/packages/identity-base-organizations/index.md. The README provides a quick-start snapshot.

Identity.Base.Organizations layers organization management on top of the core Identity Base and RBAC packages. It provides EF Core entities, services, hosted infrastructure, and minimal API endpoints so any host can manage organizations, memberships, and organization-scoped roles without custom scaffolding.

Features

  • Organization aggregate (Organization, OrganizationMetadata) with per-tenant slug/display name uniqueness.
  • Membership service with primary-organization tracking, role assignments, and helper queries for listing memberships.
  • Organization-specific role catalog and claim formatter that augments Identity Base permission claims with organization context.
  • Hosted seed services that bootstrap default roles (OrgOwner, OrgManager, OrgMember) once your migrations have been applied.
  • Minimal API modules for CRUD, membership management, role management, and user-facing endpoints.
  • Builder hooks (ConfigureOrganizationModel, AfterOrganizationSeed, AddOrganizationClaimFormatter, AddOrganizationScopeResolver) mirroring Identity Base extensibility points.

Installation

1. Add the package

dotnet add package Identity.Base.Organizations

2. Register services

Add the organizations services after AddIdentityBase (and optionally AddIdentityRoles) in Program.cs:

using Identity.Base.Extensions;
using Identity.Base.Organizations.Extensions;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

Action<IServiceProvider, DbContextOptionsBuilder> configureDbContext = (sp, options) =>
{
    var connectionString = sp.GetRequiredService<IConfiguration>().GetConnectionString("Primary")
        ?? throw new InvalidOperationException("ConnectionStrings:Primary must be set.");

    options.UseNpgsql(connectionString); // or UseSqlServer(connectionString)
};

builder.Services.AddIdentityBase(builder.Configuration, builder.Environment, configureDbContext: configureDbContext);
builder.Services.AddIdentityRoles(builder.Configuration, configureDbContext);
builder.Services.AddIdentityBaseOrganizations(configureDbContext);

var app = builder.Build();
app.UseApiPipeline(appBuilder => appBuilder.UseSerilogRequestLogging());
app.MapApiEndpoints();
app.MapIdentityRolesUserEndpoints();
app.MapIdentityBaseOrganizationEndpoints();
await app.RunAsync();

AddIdentityBaseOrganizations no longer auto-configures DbContexts. Provide the delegate shown above or register OrganizationDbContext yourself before calling the extension.

3. Apply migrations

Generate and apply migrations from your host project targeting the provider you selected:

dotnet ef migrations add InitialOrganizations --context OrganizationDbContext
dotnet ef database update --context OrganizationDbContext

4. Seed default roles

OrganizationRoleSeeder creates the default system roles after your host has applied migrations. Register additional callbacks if you need to extend the seed pipeline:

organizationsBuilder.AfterOrganizationSeed(async (sp, ct) =>
{
    // e.g. provision billing metadata, assign baseline memberships, etc.
});

5. Customize the model

Use ConfigureOrganizationModel to add indexes or shadow properties:

organizationsBuilder.ConfigureOrganizationModel(modelBuilder =>
{
    modelBuilder.Entity<Organization>().HasIndex(org => org.CreatedAtUtc);
});

API surface

Method & Route Description Permission
GET /organizations List organizations (optionally filter by tenantId query). admin.organizations.read
POST /organizations Create an organization. admin.organizations.manage
GET /organizations/{id} Retrieve one organization. admin.organizations.read
PATCH /organizations/{id} Update display name, metadata, or status. admin.organizations.manage
DELETE /organizations/{id} Archive an organization. admin.organizations.manage
GET /organizations/{id}/members List memberships + role assignments. admin.organizations.members.read
POST /organizations/{id}/members Add a user to the organization. admin.organizations.members.manage
PUT /organizations/{id}/members/{userId} Update membership roles/primary flag. admin.organizations.members.manage
DELETE /organizations/{id}/members/{userId} Remove a membership. admin.organizations.members.manage
GET /organizations/{id}/roles List organization + shared roles. admin.organizations.roles.read
POST /organizations/{id}/roles Create a custom organization role. admin.organizations.roles.manage
DELETE /organizations/{id}/roles/{roleId} Delete a custom role. admin.organizations.roles.manage

Default organization roles (Owner/Manager/Member) currently receive only the user-scoped (user.organizations.*) permissions. Create a separate role with admin.organizations.* permissions if you need a platform-wide organization administrator.

Active organization context

Tokens issued by Identity Base now include an org:memberships claim listing all organization IDs for the signed-in user. Add the middleware in your pipeline:

app.UseOrganizationContextFromHeader();

Then send the X-Organization-Id header on each request. The middleware validates the caller still belongs to that organization (admins with admin.organizations.* bypass the membership check) and loads the organization metadata into IOrganizationContextAccessor; it automatically ignores the header on the admin /organizations APIs so those remain truly global. If a membership changes (for example, the user loses access to an organization), refresh their tokens so the org:memberships claim stays up to date.

Authorization is enforced through the Identity Base RBAC package. The default IOrganizationScopeResolver verifies the caller is a member of the target organization; override it (or IPermissionClaimFormatter) via the builder extensions to compose tenant-specific or elevated administrator rules.

Options

  • OrganizationOptions
    • SlugMaxLength, DisplayNameMaxLength
    • MetadataMaxBytes, MetadataMaxKeyLength, MetadataMaxValueLength
  • OrganizationRoleOptions
    • NameMaxLength, DescriptionMaxLength
    • Default role names (OwnerRoleName, ManagerRoleName, MemberRoleName)

Bind or override using the standard options pattern:

builder.Services.Configure<OrganizationOptions>(builder.Configuration.GetSection("Organizations"));

Configuration notes

  • Auto-binding: AddIdentityBaseOrganizations binds options by default
    • OrganizationsOrganizationOptions
    • Organizations:RoleOptionsOrganizationRoleOptions
    • Organizations:AuthorizationOrganizationAuthorizationOptions
  • Role definition overrides: defaults are merged with config; definitions are de-duplicated by name (case-insensitive) and the last entry wins. This lets you override built-in OrgOwner/OrgManager/OrgMember definitions without producing duplicate roles.

Extensibility

organizationsBuilder
    .ConfigureOrganizationModel(modelBuilder => { /* custom EF configuration */ })
    .AfterOrganizationSeed(async (sp, ct) => { /* custom seeding */ })
    .AddOrganizationCreationListener<CustomOrganizationCreationListener>()
    .AddOrganizationUpdateListener<CustomOrganizationUpdateListener>()
    .AddOrganizationArchiveListener<CustomOrganizationArchiveListener>()
    .AddOrganizationClaimFormatter<CustomFormatter>()
    .AddOrganizationScopeResolver<CustomScopeResolver>();

Organization creation listeners

  • Register one or more IOrganizationCreationListener implementations via AddOrganizationCreationListener<T>().
  • Each listener runs after OrganizationService.CreateAsync persists a new organization, enabling billing, automation, or audit hooks without modifying the core service.

Organization update & archive listeners

  • AddOrganizationUpdateListener<T>() registers IOrganizationUpdateListener implementations invoked after successful updates.
  • AddOrganizationArchiveListener<T>() registers IOrganizationArchiveListener implementations invoked after an organization is archived.

Testing

Run the solution tests to execute the organizations unit suite alongside the existing Identity Base coverage:

dotnet test Identity.sln

License

MIT, consistent with the rest of the Identity Base OSS packages.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.7.12 39 12/30/2025
0.7.9 284 12/17/2025
0.7.7 195 12/3/2025
0.7.6 198 11/26/2025
0.7.5 330 11/14/2025
0.7.4 296 11/13/2025
0.7.3 293 11/10/2025
0.7.2 200 11/9/2025
0.7.1 146 11/9/2025
0.6.3 147 11/8/2025
0.6.2 144 11/8/2025
0.6.1 185 11/6/2025
0.5.10 183 11/5/2025
0.5.1 201 11/2/2025
0.2.7 133 11/1/2025
0.2.4 195 10/29/2025
0.2.3 190 10/29/2025