Skip to content
Wallet and Entity Collection draft updates
Documentation menu

1.1. Choose a federation host and compose protocol roles

Feature guides / 1. Federation participants · Example context

Umeå University operates an Intermediate and an OP Leaf as separate entities. The LIGO Wiki is an RP Leaf under InCommon. A federation host describes an entity's position in the trust infrastructure; an attached role describes its protocol function.

How to use it

Choose one host per Entity Identifier. Attach fresh protocol-role instances to it; the host initializes them, combines their metadata, and routes their endpoints. This bootstrap constructs the Appendix A hierarchy using reserved addresses. Keys and storage are temporary, suitable for one controlled example process. Event storage is enabled for the annotated updates used in later guides. Federation architecture; Entity types.

import { generateSoftwareKey, softwareCrypto } from "../examples/software-crypto.js";
import { Intermediate, TrustAnchor } from "@oidfed/authority";
import { Leaf } from "@oidfed/leaf";
import { OidcProviderRole, OidcRelyingPartyRole, type OidcProviderRoleConfig } from "@oidfed/oidc";
import { createTrustAnchorSet, MemoryFederationStorage, type BoundFederationOptions } from "@oidfed/core";

export async function createAcademicFederation(
  onRegistration: NonNullable<OidcProviderRoleConfig["onRegistration"]>,
  options: BoundFederationOptions = {},
) {
  async function keys() {
    return softwareCrypto((await generateSoftwareKey("ES256")).privateKey);
  }
  function authorityMetadata(id: string) {
    return { federation_entity: {
      federation_fetch_endpoint: `${id}/fetch`, federation_list_endpoint: `${id}/list`,
    } };
  }
  const eduGainKeys = await keys();
  const eduGain = await TrustAnchor.create({
    entityId: "https://edugain.example", crypto: eduGainKeys, options,
    storage: new MemoryFederationStorage({ namespace: "https://edugain.example" }),
    metadata: authorityMetadata("https://edugain.example"),
  });
  // These pins come from the example's controlled setup, not an untrusted fetched EC.
  const trustAnchors = createTrustAnchorSet([{
    entityId: eduGain.entityId, jwks: (await eduGainKeys.keyring.entry("federation")).publishedJwks,
  }]);
  async function enrollAuthority(id: string, superior: TrustAnchor | Intermediate) {
    const crypto = await keys();
    const host = await Intermediate.create({
      entityId: id, authorityHints: [superior.entityId], crypto, trustAnchors, options,
      storage: new MemoryFederationStorage({ namespace: id }), metadata: authorityMetadata(id),
    });
    await superior.registerSubordinate({
      entityId: host.entityId, jwks: (await crypto.keyring.entry("federation")).publishedJwks,
      entityTypes: ["federation_entity"], isIntermediate: true,
    });
    return host;
  }
  const swamid = await enrollAuthority("https://swamid.example", eduGain);
  const umu = await enrollAuthority("https://umu.example", swamid);
  const inCommon = await enrollAuthority("https://incommon.example", eduGain);
  const opProtocol = await generateSoftwareKey("RS256"), rpProtocol = await generateSoftwareKey("ES256");
 const opKeys = await keys();
 const rpKeys = softwareCrypto((await generateSoftwareKey("ES256")).privateKey, rpProtocol.privateKey);
  const opRole = new OidcProviderRole({
    onRegistration,
    metadata: {
      issuer: "https://op.umu.example", authorization_endpoint: "https://op.umu.example/auth",
      token_endpoint: "https://op.umu.example/token", jwks: { keys: [opProtocol.publicKey] },
      response_types_supported: ["code"], subject_types_supported: ["public"],
      id_token_signing_alg_values_supported: ["RS256"], request_object_signing_alg_values_supported: ["ES256"],
      token_endpoint_auth_methods_supported: ["private_key_jwt"],
      client_registration_types_supported: ["automatic", "explicit"],
    },
  });
  const op = await Leaf.create({
    storage: new MemoryFederationStorage({ namespace: "https://op.umu.example", capabilities: ["replay"] }),
    entityId: "https://op.umu.example", authorityHints: [umu.entityId], crypto: opKeys,
    trustAnchors, options, metadata: { federation_entity: { organization_name: "Umeå University OP" } }, roles: [opRole],
  });
  const rpRole = new OidcRelyingPartyRole({
    signing: {requestObject:"request_object", clientAssertion:"client_assertion"},
    metadata: {
      redirect_uris: ["https://wiki.ligo.example/callback"], response_types: ["code"], grant_types: ["authorization_code"],
      scope: "openid profile email", client_registration_types: ["automatic", "explicit"], token_endpoint_auth_method: "private_key_jwt",
    },
  });
  const rp = await Leaf.create({
    entityId: "https://wiki.ligo.example", authorityHints: [inCommon.entityId], crypto: rpKeys,
    trustAnchors, options, metadata: { federation_entity: { organization_name: "LIGO Wiki" } }, roles: [rpRole],
  });
  await umu.registerSubordinate({ entityId: op.entityId, jwks: (await opKeys.keyring.entry("federation")).publishedJwks, entityTypes: ["openid_provider"] });
  await inCommon.registerSubordinate({ entityId: rp.entityId, jwks: (await rpKeys.keyring.entry("federation")).publishedJwks, entityTypes: ["openid_relying_party"] });
  return { eduGain, swamid, umu, inCommon, op, rp, opRole, rpRole, trustAnchors };
}

What your application owns

The host application provides HTTPS serving and durable state. A role is not a complete OP, OAuth server, wallet, or credential engine. Mount its host handler in your server and connect the protocol engine separately. Use a new role instance for each host so one entity's configuration cannot become another's context.

Choose the host before the protocol role

For a new participant, decide first whether that Entity Identifier issues Subordinate Statements. Its OP role does not answer that question. A Leaf can publish the OP's metadata and receive federation trust without becoming an authority. An Intermediate can host the same OP role while enrolling participants below it. A TrustAnchor can also have Superiors when it anchors one federation and participates in another.

Before exposing the host, obtain its Entity Configuration and inspect the published identifier and metadata blocks. Enroll that exact identifier with its Superior. If construction rejects conflicting routes or metadata, fix the configuration before mounting the handler; a reverse proxy cannot repair an inconsistent signed publication.

Validate Entity Identifiers

Use entityId() to validate and brand an HTTPS Entity Identifier without credentials, a query, or a fragment. The helper preserves the supplied spelling and applies a library limit of 2,048 characters. Per Section 3.1.2 of the OpenID Federation 1.0 specification, the authority_hints list of immediate superiors must not be empty [] and must not be present in the configurations of Trust Anchors with no superiors.

import { entityId, isValidEntityId } from "@oidfed/core";
import type { EntityId } from "@oidfed/core";

// Safely brand a string as an EntityId (throws TypeError on invalid formats)
const id: EntityId = entityId("https://op.example.com");

// Check validity without throwing exceptions
if (!isValidEntityId("https://client.example.com?query=true")) {
  // Reject this identifier because it contains a query component.
}

Authority configuration ownership

A TrustAnchor or Intermediate copies its metadata at construction. Each role initializes once, then contributes its metadata in configuration order. Role parameters replace matching host parameters, and later roles win conflicts. Neither composition nor later changes to the caller's object modify another host's metadata.

To change general metadata, construct a replacement host with the new configuration. Existing methods for Trust Marks, anchor policy, and subordinate records remain the supported ways to update those specific resources. Keyrings and storage adapters retain their identity, so their normal lifecycle operations continue to work.

Entity Configuration and Subordinate Statement TTLs must be positive safe integers. Trust Mark and Subordinate Events response TTLs must be positive finite numbers and may contain fractions. Invalid configured values fail during construction, before an endpoint needs to sign a response.

When implementing storage, follow the transaction and snapshot contract. Use the repositories supplied to a transaction callback; awaiting a write through the parent adapter inside that callback can wait on the transaction itself.

Next: 1.2. Configure the anchors your application trusts

View source on GitHub