Appearance
Remote identity consumer
The authority owns login, refresh, identities, membership, permission administration, signing keys, revocation and identity migrations. An application consuming identity must not register the authority's controllers or access its database.
The revised AddGrydAuthTokenValidator now delegates to AddGrydAuthRemoteConsumer. This is a breaking registration change for applications relying on its former full infrastructure. Authority hosts continue to use AddGrydAuth; consumers reference GrydAuth.Infrastructure only. These APIs require the release containing this change; they are not available in historical 5.0.2.
csharp
builder.Services.AddGrydAuthRemoteConsumer(builder.Configuration);
var app = builder.Build();
app.UseRouting();
app.UseAuthentication();
app.UseGrydAuthRemoteConsumer(); // required: after UseAuthentication, before UseAuthorization
app.UseAuthorization();Tenant of the request
UseGrydAuthRemoteConsumer() makes the tenant of the validated session — the tenant_id claim built from the authority's response — the ambient tenant of the request, so every Gryd DbContext (GrydFiles, GrydNotifications, GrydJobs, GrydReports, or an application context using ApplyTenantQueryFilters) filters by it. It is the only source of the tenant: an X-Tenant-ID header, a query string or a route value never selects one. Anonymous requests, and sessions without a valid tenant claim, run without a tenant. The previous ambient tenant is restored when the request ends, also when it throws.
Ordering matters:
- It must come after
UseAuthentication(). The ambient tenant is async-local, and a value set inside the authentication handler does not flow back to the endpoint; only a middleware that wraps the rest of the pipeline can carry it. Placed beforeUseAuthentication(), every request fails with anInvalidOperationExceptioninstead of being served without a tenant. - Left out, the host logs an error at startup and tenant reads return no rows.
Tenant reads fail closed, in consumer mode as everywhere (ADR 0011, D19): a read that reaches a DbContext without a tenant returns no tenant-owned rows. It is not an option, so there is nothing to turn off. Background code in a consumer host must set the tenant explicitly for the work it does.
json
{
"GrydAuth": {
"Consumer": {
"Authority": "https://identity.example.com",
"Issuer": "GrydAuth",
"Audience": "Nexio",
"TimeoutSeconds": 5,
"AllowLoopbackHttp": false
}
}
}The consumer sends the bearer to POST /api/v1/consumer-identity over HTTPS for each authenticated request. Redirects and cookies are disabled. The authority validates the signature, issuer, audience, expiry, revocation, token version, active user and current tenant membership. Tenant permissions use committed authority data as described below. The consumer validates the returned contract and identity scope. It does not locally verify the signature; trust relies on the configured authority and TLS. No private key, identity connection string, identity repository or periodic identity job is registered.
The authority endpoint requires GrydAuth:TokenValidation:CacheFailureMode=FailSecure, a valid tenant access token and active membership. Failure of required verification never grants access. The consumer bounds response size to 64 KiB, claim count to 512 and network time to 1–30 seconds. It never logs tokens or response bodies. Authentication tickets carry the authority's expiry; long-lived transports must also implement their expiration and revocation lifecycle.
Committed tenant permissions
The authority captures the original subject, generation, tenant and response metadata before awaiting. Exactly one raw sub or mapped ClaimTypes.NameIdentifier is accepted; duplicate or ambiguous claims are refused. ICommittedCallerPermissionReader reads an independent primary RepeatableRead, READ ONLY view through the existing pool. It binds subject, original generation, origin and calculation tenant before exporting Permissions; calculation uses the authenticated tenant. There is no cached or latest-generation fallback. A complete empty set returns 200.
Invalidated, ineligible (including locked) or mismatched evidence returns simple 401; refusing a locked user is an intentional tightening. Null, unknown, partial or unavailable reader evidence returns simple 503. Existing FailSecure-configuration 503, token-validation statuses and user/membership checks remain. This 503 mapping covers the reader boundary, not every database failure elsewhere in the endpoint.
Roles still copies the token; PlatformPermissions uses its separate resolver. The eight-field DTO is not one atomic snapshot or a fence against later revocation. Downstream caches and other permission decisions are outside this change.
HTTP is allowed only for an explicit loopback development configuration. There is no fallback to self-issued tokens, cached success or caller-supplied tenant IDs. Availability and request volume of the authority must be measured as part of the consuming application's deployment.
Integration tests run the authority with PostgreSQL and Redis and cover tampered signature, wrong issuer/audience, expiry, revoked token and removed membership. Consumer tests cover registration without identity storage, malformed responses and unavailable authority, and a consumer host whose tenant-filtered reads return only the session tenant's rows — and none without the middleware or a tenant. Business company grants remain the consumer's responsibility in addition to the platform permission ceiling.
Browser session validation
The authority's GET /api/v1/auth/validate is a read: it validates an access token or a tenant selector without consuming the selector. Its authorization handler is registered independently of MultiTenancy:IsEnabled. Active user/membership, token types, revocation and prior-use checks still apply. Mutation endpoints retain mandatory consumption; Redis uses an atomic conditional write with expiry, while the memory fallback protects only one process. A cache failure cannot grant access. Integration regressions cover repeated validation followed by switch, absent/false multi-tenancy configuration, revoked identity/membership and simultaneous attempts to consume the same selector.