7.5. Authenticate federation endpoint clients
Feature guides / 7. Federation endpoints · Example context
Umeå University allows public listing but requires authentication for selected operations. A caller's ability to reach an endpoint must not silently grant it the authenticated path.
How to use it
Authority metadata advertises the accepted methods per endpoint. The built-in shared layer supports none and private_key_jwt; advertised methods without a built-in or registered verifier fail construction. private_key_jwt needs a replay store and a trusted client federation-key lookup, defaulting to registered subordinate keys. Endpoint authentication.
import type { CryptoEngine, RotatingKeyring } from "@oidfed/crypto";
import type { AuthorityConfig } from "@oidfed/authority";
import type { FederationStorage } from "@oidfed/core";
export function protectedUniversityConfig(
engine: CryptoEngine,
keys: RotatingKeyring,
storage: FederationStorage,
): AuthorityConfig {
return {
entityId: "https://umu.example", crypto: { engine, keyring: keys }, storage,
metadata: { federation_entity: {
federation_fetch_endpoint: "https://umu.example/fetch",
federation_fetch_endpoint_auth_methods: ["private_key_jwt"],
federation_list_endpoint: "https://umu.example/list",
} },
};
}
In this topology, LIGO Wiki is enrolled under InCommon, not under the university. For requests from that RP, configure the university's clientKeyProvider to return independently trusted client federation keys; the default subordinate-record lookup alone cannot authenticate it.
What your application owns
Supply shared replay state before using this configuration. Authenticate client keys; do not trust a request's own key declaration. Authenticated requests use the endpoint's required POST/form composition and audience. Use the shared authentication option on the endpoint clients. There is no automatic anonymous retry after invalid credentials. TLS termination and any transport-level identity belong to the host.
Register another method
Authority uses endpointAuthentication.methods; Leaf issuer hosting uses trustMarkIssuer.authentication.extensions.methods; Collection uses authentication.extensions.methods. Register credential parameter/header names and an authenticate callback returning Result<{ entityId }>. Advertise only implemented methods in endpoint metadata. The shared verifier contains callback failures, rejects ambiguous credentials, and prevents anonymous fallback after credentials are supplied.
Client authentication accepts private_key_jwt with a signer and explicit responder audience, or a custom prepare callback returning credential headers/parameters. Trust Mark retrieval, status, listing, and historical-key clients share this layer. Authenticated calls use form POST and reject redirects. Host-supplied transport evidence must come from verified infrastructure; a caller's identity header is not authentication.
Additional request parameters cannot replace protocol selectors or credentials. Unknown endpoint extensions remain ignored. A custom verifier is responsible for its method's cryptographic, audience, freshness, and replay checks.
Test both sides of authentication
Configure the server's supported methods and the client's selected method separately. For a protected university endpoint, test an accepted request, a missing credential, a wrong audience, and a repeated assertion. An application login cookie does not implement federation endpoint authentication.
A custom method needs a verifier on the host and matching request construction on the caller. Declare its parameter names so query/body and selector checks can distinguish credentials from ordinary selectors. Keep private keys and proofs out of logs. A failed authentication callback must prevent the endpoint operation, even if the host logger is unavailable.
Configure authenticated endpoint requests
Pass authentication in the client options for Fetch, Listing, Extended Listing, Resolve, Entity Collection, or Subordinate Events. The client sends private_key_jwt or your configured authentication method in a form POST. Without authentication, these clients use GET; Collection also accepts an explicit method: "POST" for anonymous requests.
import type { CryptoEngine, KeyringEntry } from "@oidfed/crypto";
import { entityId, fetchSubordinateStatement } from "@oidfed/core";
export async function fetchUmeaOpStatement(engine: CryptoEngine, signer: KeyringEntry) {
return fetchSubordinateStatement(
"https://directory.umu.example/fetch?tenant=academic",
entityId("https://op.umu.example"),
{
engine,
issuer: entityId("https://umu.example"),
authentication: {
method: "private_key_jwt",
clientId: "https://wiki.ligo.example",
audience: "https://umu.example",
signer,
},
},
);
}
The assertion audience is the responder's Entity Identifier, which can differ from its endpoint origin. Keep authentication.audience as the audience input; no separate responder parameter is needed. Fetch and Events cross-check it against their existing issuer input when available. Collection traversal also checks the authority identity before requesting its Listing endpoint, and fetchAndAttachTrustMark() checks the verified issuer before requesting its Trust Mark endpoint. A mismatch stops the request before credentials are prepared or signed. Standalone Listing, Resolve, Collection, and Extended Listing clients use the audience you supply; a requested Trust Anchor is not necessarily the resolver or collection provider. The receiver checks that the assertion targets its own Entity Identifier. Setting this value does not by itself establish ownership of the endpoint. Collection and Events still accept a caller-created clientAssertion; its audience and signature remain the caller's responsibility and are checked by the receiving endpoint. Supplying both clientAssertion and authentication returns an error.
For a standalone client, keep the endpoint and its authentication in one application configuration. LIGO Wiki might have this entry for eduGAIN, whose directory lives on another origin:
import type { CryptoEngine, KeyringEntry } from "@oidfed/crypto";
import { fetchListSubordinates, type EndpointClientAuthentication } from "@oidfed/core";
export async function listCampusProviders(engine: CryptoEngine, signer: KeyringEntry) {
// Use trusted application configuration or validated federation metadata.
const campus = {
endpoint: "https://directory.edugain.example/list",
authentication: {
method: "private_key_jwt",
clientId: "https://wiki.ligo.example",
audience: "https://umu.example",
signer,
} satisfies EndpointClientAuthentication,
};
return fetchListSubordinates(
campus.endpoint,
{ entityType: "openid_provider" },
{ engine, authentication: campus.authentication },
); // Result: the host handles success or failure as usual.
}
Here the host establishes the endpoint/identity pairing. The client signs the configured audience, and the receiving endpoint checks it against its own Entity Identifier. Supplying that audience does not independently verify the pairing. Standalone Trust Mark retrieval, Resolve, Extended Listing, and Collection follow the same rule. The client does not retry anonymously when signing, credential preparation, or endpoint authentication fails.
For requests that visit several authorities, use getEndpointAuthentication instead of static authentication. The callback receives { endpoint, responder?, signal? } and may return credentials synchronously or asynchronously. Returning undefined selects anonymous access; throwing or rejecting stops that request. It cannot be combined with authentication or a prebuilt clientAssertion.
responder is supplied when the calling operation knows the Entity Identifier, including Collection traversal, Fetch, Events with an issuer input, and evidence-aware Trust Mark operations. Standalone clients without that context leave it undefined. The library never derives it from the endpoint origin or a requested Trust Anchor. Selected credentials go through the same audience check and POST composition as static credentials, before signing or preparing them.
Use your own configured endpoint and entity allowlist when selecting credentials. The context identifies the request being made; it does not establish trust in an endpoint discovered through a remote graph. Check both values before releasing credentials. See the Collection traversal example.
The callback runs when a federation endpoint request is prepared. Entity Configuration discovery remains anonymous GET and never calls it; cached responses and requests shared within an operation can avoid a new call. Cancelling signal stops waiting for a pending callback. Callback errors become a failed Result without exposing their text or retrying anonymously. The exported EndpointAuthenticationProvider and EndpointAuthenticationContext types describe this contract.
Fixed endpoint selectors retain their meaning for GET and POST. For repeatable selectors defined by membership, such as entity_type, the same values in a different order or with identical repetitions agree with the fixed filter. The client preserves the advertised query and uses its value order in a matching POST body. Server routing and authentication wrappers accept the same equivalent filters from other clients. Different sets fail before sending a request. Scalar and unknown extension parameters keep their existing exact comparison rules. Additional parameters and authentication callbacks cannot replace protocol selectors or inject credentials into the URL. These six clients reject redirects and require HTTP 200; generic performFetch() retains its configurable transport behavior. EC discovery stays an unauthenticated GET and also requires 200. A missing EC or Subordinate Statement reported with HTTP 404 returns not_found.
These request rules follow Federation §§8.1–8.9 and Entity Collection §3.3.1. Fetching an artifact still does not establish trust in it; use the corresponding verification API.
For a custom endpoint handler, createEndpointAuthenticatedHandler(config, handler, options, nativeMethod, unorderedParameters) accepts an optional final list of parameters whose repeated values express membership. The default is exact comparison. Core exports endpointParameterValuesMatch and the frozen LIST_UNORDERED_PARAMETERS, EXTENDED_LIST_UNORDERED_PARAMETERS, RESOLVE_UNORDERED_PARAMETERS, and COLLECTION_UNORDERED_PARAMETERS lists for integrations that need the same rules. The handler captures a copy of its list; authentication credentials always retain exact handling.
Shared authentication primitives and custom methods
Core supplies the authentication primitives used by the protocol packages. The
calling profile still decides which keys and trust rules apply. For example,
Federation endpoint assertions use Federation Entity Keys; PAR assertions use
the RP's protocol keys. Both use createClientAssertion, with a 60-second
default lifetime and a fresh jti. Invalid or non-finite lifetimes fail before
signing. Fractional NumericDates are supported.
runAsyncOperation bounds asynchronous host work using signal and
httpTimeoutMs. A cancelled operation stops waiting, observes late promise
rejections, and cannot report authentication success. Host callbacks should also
honor the signal to stop their own work; cancellation cannot undo a remote side
effect that has already happened.
Custom Federation authentication methods can share a credential carrier, such as
Authorization. Set detect to identify the method that actually applies. When
present, its result takes precedence over the presence of a registered header or
parameter. A method sharing client_assertion must provide a detector. Detection
only selects a verifier: it never authenticates the request. Ambiguous or
unsupported credentials fail, including when anonymous access is allowed.
A verifier may return an EndpointAuthenticationError with an
authenticationResponse. This carries a controlled OAuth error, HTTP 400 or 401,
and the OAuth-Client-Attestation-Challenge or WWW-Authenticate headers.
endpointAuthenticationErrorResponse validates that response before rendering it;
other headers and unexpected exceptions are not exposed. A
use_attestation_challenge response must include its challenge header.
Federation §8.8 still governs Federation endpoints: authentication uses POST, with endpoint and authentication parameters in the body. The generic Client Attestation header format is not automatically installed as a Federation endpoint method. A federation choosing an additional method must define its integration with those requirements.
Host authentication and routing rules
Federation endpoint private_key_jwt authentication verifies the remote caller's assertion with keys returned by clientKeyProvider. If omitted, the authority uses the caller Entity Identifier to read the subordinate record from storage.subordinate and uses that record's jwks. Configure a custom provider when caller keys live in an external registry or key service; invalid, missing, or mismatched keys fail closed.
Each hosted federation endpoint uses its own *_auth_methods metadata, following §8.8.1:
| Methods | Access |
|---|---|
Omitted or ["none"] |
Anonymous requests |
["private_key_jwt"] |
Authenticated form POST required |
["none", "private_key_jwt"] |
Anonymous requests or authenticated form POST |
The built-in authority rejects empty lists and unsupported method names during construction, including unsupported names mixed with recognized methods. none and private_key_jwt are built in. Register other methods through endpointAuthentication.methods and advertise their names in endpoint metadata; construction rejects advertised methods without a matching implementation.
Most anonymous federation endpoints use GET. Trust Mark Status uses form POST with trust_mark whether authentication is enabled or not, as defined in §8.4.1. Under optional authentication, omitting both credential fields allows anonymous access. Supplied empty, partial, invalid, or replayed assertions are rejected. Requests containing assertions must use POST. Form reads are bounded before dispatch.
Authority endpoints using this middleware require storage.replay when private_key_jwt is configured. Assertions must include exp and a non-empty jti; iat is optional. After signature and claim validation, the authority atomically claims the assertion before dispatch. Reuse across endpoints sharing that replay store is rejected, and replay-storage failures prevent dispatch. Collection authentication uses the core service; it accepts a configured replay store or falls back to memory. Production instances must share replay state.
Entity Configuration discovery uses unauthenticated GET independently of these settings, following §9.1. Federation defines no discovery auth-method parameter or client-assertion flow for it. The specification does not explicitly prohibit profile-specific network or TLS access controls; deployments using them need matching client transport support.
Authorities remove one trailing / from their own configured entityId at construction. The resulting published identifier is used consistently by the public entityId property, composed roles, Entity Configuration claims, and hosted services. Remote identifiers and authority hints are kept unchanged.
Discovery URL construction is a separate step: remove one trailing / from the published identifier, then append /.well-known/openid-federation, as §9 specifies. For example, configuring https://ta.example.org/tenant/// publishes the identifier https://ta.example.org/tenant//, whose discovery URL is https://ta.example.org/tenant//.well-known/openid-federation. Use the host's published entityId when configuring other participants. Port numbers and encoded path components are preserved.
Role routes cannot replace Entity Configuration discovery, another role's route, or a registered federation endpoint. Construction fails with the conflicting path. Because role routes dispatch by pathname, a role also conflicts with an endpoint on that pathname when the endpoint has fixed query selectors. Choose a separate path for the role's handler.
Federation endpoint HTTP routes are derived from the paths advertised in metadata.federation_entity, not from fixed defaults. For example, advertising federation_fetch_endpoint: "https://ta.example.org/custom/fetch" mounts fetch handling at /custom/fetch. Optional endpoints are mounted only when their corresponding endpoint URL is advertised. Endpoint URLs must use HTTPS and contain no fragment. Federation endpoints may share a pathname when their fixed query selectors are disjoint. Construction rejects overlapping routes; role routes match the whole pathname and therefore need a separate path.