wip: doctor/cli/docs/api to vector db consolidation; api hardening for descriptions, tenant, and scopes; migrations and conversions of all DALs to EF v10
This commit is contained in:
@@ -85,21 +85,34 @@ public sealed partial class TenantContextMiddleware
|
||||
|
||||
private TenantValidationResult ValidateTenantContext(HttpContext context)
|
||||
{
|
||||
// Extract tenant header
|
||||
// Extract tenant: header first, then canonical claim, then legacy claim fallback.
|
||||
var tenantHeader = context.Request.Headers[TenantContextConstants.TenantHeader].FirstOrDefault();
|
||||
|
||||
// POL-TEN-01: Fall back to canonical stellaops:tenant claim if header is absent.
|
||||
if (string.IsNullOrWhiteSpace(tenantHeader))
|
||||
{
|
||||
tenantHeader = context.User?.FindFirst(TenantContextConstants.CanonicalTenantClaim)?.Value;
|
||||
}
|
||||
|
||||
// POL-TEN-01: Fall back to legacy "tid" claim for backwards compatibility.
|
||||
if (string.IsNullOrWhiteSpace(tenantHeader))
|
||||
{
|
||||
tenantHeader = context.User?.FindFirst(TenantContextConstants.LegacyTenantClaim)?.Value;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(tenantHeader))
|
||||
{
|
||||
if (_options.RequireTenantHeader)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Missing required {Header} header for {Path}",
|
||||
"Missing required tenant context (header {Header} or claim {Claim}) for {Path}",
|
||||
TenantContextConstants.TenantHeader,
|
||||
TenantContextConstants.CanonicalTenantClaim,
|
||||
context.Request.Path);
|
||||
|
||||
return TenantValidationResult.Failure(
|
||||
TenantContextConstants.MissingTenantHeaderErrorCode,
|
||||
$"The {TenantContextConstants.TenantHeader} header is required.");
|
||||
$"Tenant context is required. Provide the {TenantContextConstants.TenantHeader} header or a token with the {TenantContextConstants.CanonicalTenantClaim} claim.");
|
||||
}
|
||||
|
||||
// Use default tenant ID when header is not required
|
||||
|
||||
Reference in New Issue
Block a user