Skip to main content
Table of Contents

Class MembershipClaimsServiceCollectionExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Stratara.Identity.AspNetCore.dll

DI extensions that wire the sign-in claims bridge: the stratara:tenant_id claim is resolved from the user's tenant membership and surfaced on the principal, where Stratara's session-context middleware picks it up. Two modes — stamp at issuance (AddMembershipTenantClaim<TUser>(IServiceCollection)) or resolve per request (AddMembershipTenantClaimsTransformation(IServiceCollection)).

public static class MembershipClaimsServiceCollectionExtensions
Inheritance
MembershipClaimsServiceCollectionExtensions
Inherited Members

Methods

AddMembershipTenantClaim<TUser>(IServiceCollection)

Decorate the registered IUserClaimsPrincipalFactory<TUser> with MembershipClaimsPrincipalFactory<TUser>, stamping the tenant claim into every issued principal (cookies and ASP.NET Identity bearer tokens). Call it after the identity registration (AddAspNetIdentity*) and after registering an ITenantMembershipStore. A tenant switch takes effect on the next sign-in refresh; use AddMembershipTenantClaimsTransformation(IServiceCollection) when it must apply immediately.

public static IServiceCollection AddMembershipTenantClaim<TUser>(this IServiceCollection services) where TUser : class

Parameters

services IServiceCollection

The service collection to mutate.

Returns

IServiceCollection

The same service collection, to enable chaining.

Type Parameters

TUser

The host's ASP.NET Identity user entity.

Examples

Stamps the tenant into every principal as it is issued. A tenant switch after sign-in is not reflected until the principal is re-issued — use the transformation for that:

services.AddMembershipTenantClaim<ApplicationUser>();

Remarks

The bridge requires Guid-parseable identity keys (ASP.NET Identity's default GUID-string keys) — the same assumption Stratara's session-context middleware makes. Hosts with non-Guid user keys get no tenant claim stamped (fail-closed, no error), so verify the key shape before adopting the bridge.

Exceptions

InvalidOperationException

No IUserClaimsPrincipalFactory<TUser> is registered yet.

AddMembershipTenantClaimsTransformation(IServiceCollection)

Register MembershipClaimsTransformation as an IClaimsTransformation, resolving the tenant claim from the membership store on every request. Choose this mode when tenant switches must apply without re-issuing the sign-in; it composes with the issuance mode (principals already carrying the claim pass through unchanged).

public static IServiceCollection AddMembershipTenantClaimsTransformation(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to mutate.

Returns

IServiceCollection

The same service collection, to enable chaining.

Examples

Resolves the tenant claim per request, so a tenant switch applies without re-issuing the sign-in:

services.AddMembershipTenantClaimsTransformation();