Metadata policies and constraints
Apply policy to authenticated statements in superior order. Custom operators and constraints are synchronous host extensions with controlled failure results. Unknown non-critical extensions remain distinct from required extensions.
applyAllowedEntityTypes
Return a new outer metadata record retaining allowed Entity Types and always retaining federation_entity. The call does not mutate the input, but retained metadata blocks are shared by reference rather than deeply cloned.
applyAllowedEntityTypes(allowedEntityTypes: string[], metadata: Record<string, Record<string, unknown>>): Record<string, Record<string, unknown>>;
applyMetadataPolicy
Apply a resolved metadata policy to federation metadata, returning the transformed metadata.
applyMetadataPolicy(metadata: FederationMetadata, policy: ResolvedMetadataPolicy, superiorMetadataOverride?: FederationMetadata, options?: MetadataPolicyOptions): Result<FederationMetadata, FederationError>;
checkConstraints
Validate all constraints from a subordinate statement against the chain. position identifies the Subordinate Statement carrying the constraints. Naming constraints cover its subject and that subject's subordinates (§3.1.3). allowed_entity_types is handled separately during validation (modifies metadata, doesn't reject chain).
checkConstraints(constraints: TrustChainConstraints, position: number, chain: ParsedEntityStatement[], customChecks?: readonly ConstraintCheckDefinition[]): Result<void, FederationError>;
checkMaxPathLength
Check whether the chain path length satisfies max_path_length. Intermediates between constrainer (position i) and leaf = i - 1.
checkMaxPathLength(maxPathLength: number, constrainerPosition: number, _chainLength: number): boolean;
checkNamingConstraints
Check whether an entityId's hostname passes naming constraints. Excluded overrides permitted. No regex (ReDoS prevention).
checkNamingConstraints(namingConstraints: { permitted?: string[] | undefined; excluded?: string[] | undefined }, entityId: EntityId): boolean;
Usage example
An editor can preview a naming or entity-type restriction. Full chain validation remains responsible for applying constraints at the correct position in authenticated evidence.
import { applyAllowedEntityTypes, checkMaxPathLength, checkNamingConstraints, entityId } from "@oidfed/core";
export function previewCampusConstraint(metadata: Record<string, Record<string, unknown>>) {
return {
nameAllowed: checkNamingConstraints({ permitted: [".campus.example"] },
entityId("https://harbor.campus.example")),
pathAllowed: checkMaxPathLength(1, 2, 3),
metadata: applyAllowedEntityTypes(["openid_provider"], metadata),
};
}
MetadataPolicyOptions
Options accepted by resolveMetadataPolicy and applyMetadataPolicy for
federation-defined extension operators.
interface MetadataPolicyOptions {
/**
* Federation-defined operators in addition to the seven standard ones.
* Validated by `validateCustomOperators` on every call. Operators with
* names colliding with standard operators, duplicate names within the
* supplied set, or invalid order/action combinations are rejected.
*/
customOperators?: readonly PolicyOperatorDefinition[] | undefined;
}
Fields (including inherited fields):
| Field | Declared type | Description |
|---|---|---|
customOperators? |
readonly PolicyOperatorDefinition[] | undefined |
Federation-defined operators in addition to the seven standard ones. Validated by validateCustomOperators on every call. Operators with names colliding with standard operators, duplicate names within the supplied set, or invalid order/action combinations are rejected. |
operators
The standard metadata-policy operator definitions used for merge, combination, and application rules. Register additional operators through the options contract.
const operators: Record<string, PolicyOperatorDefinition>;
resolveMetadataPolicy
Merge metadata policies from subordinate statements in TA-to-leaf order.
Accepts statements in chain order (leaf-to-TA) and reverse-iterates so that superior policies are applied first.
resolveMetadataPolicy(subordinateStatements: ParsedEntityStatement[], options?: MetadataPolicyOptions): Result<ResolvedMetadataPolicy, FederationError>;
validateCustomOperators
Validate a set of federation-defined custom policy operators.
Rules:
- Operator name must not collide with a standard operator.
- No duplicate names within the supplied set.
action: "modify"operators must declareorder > 1so they apply after the standardvalueoperator (which has order 1).action: "check"operators must declareorder < 7so they apply before the standardessentialoperator (which has order 7).action: "both"operators must declare1 < order < 7.
validateCustomOperators(operators: readonly PolicyOperatorDefinition[]): Result<void, FederationError>;
validateMetadataPolicy
Validate a declaration without applying it or requiring extension operators to be understood.
validateMetadataPolicy(policy: unknown, options?: MetadataPolicyOptions): Result<void, FederationError>;