Skip to content
Wallet and Entity Collection draft updates
Documentation menu

15.1. Connect OP and RP roles to federation hosts

Feature guides / 15. OIDC and OAuth workflows · Example context

Umeå University OP authenticates Maya; LIGO Wiki asks Umeå University OP to sign her in. oidfed adds federation discovery, metadata, and registration around the OP and RP implementations they already run.

How to use it

Attach OidcProviderRole or OidcRelyingPartyRole to a Leaf or authority. The RP supplies protocol signing keys. The provider role installs an explicit registration route and requires explicit support in its composed metadata. Its trust anchors must be configured before host initialization. OP/RP metadata; OIDC federation registration.

import { Leaf } from "@oidfed/leaf";
import { OidcProviderRole, type OidcProviderRoleConfig } from "@oidfed/oidc";
import type { CryptoContext, FederationStorage, TrustAnchorSet } from "@oidfed/core";

export async function umeaOpProvider(
  crypto: CryptoContext, trustAnchors: TrustAnchorSet, opMetadata: Record<string, unknown>,
  storage: FederationStorage,
  onRegistration: NonNullable<OidcProviderRoleConfig["onRegistration"]>,
) {
  const op = new OidcProviderRole({
    onRegistration,
    metadata: { ...opMetadata, client_registration_types_supported: ["automatic", "explicit"] },
  });
  const umeaOp = await Leaf.create({
    entityId: "https://op.umu.example", authorityHints: ["https://umu.example"],
    crypto, trustAnchors, storage, metadata: { federation_entity: {} }, roles: [op],
  });
  return { umeaOp, op }; // Instance operations can now use UmeaOp's identity and trust options.
}

What your application owns

The returned role is already attached to its host. Use umeaOp.handleRequest() for its federation and registration routes and op.processAutomaticRegistration() for the OP engine's automatic-registration boundary. Complete effective OP metadata with the actual authorization/token/key endpoints and supported capabilities. The host still owns login, sessions, consent, token issuance, and client persistence. A role constructor is not a running OP. Keep federation and protocol signing keys separate and expose only the endpoints actually served.

Connect the role to the existing OP or RP

Umeå's OP engine still owns users, sessions, authorization responses, and tokens. Its federation role publishes metadata and processes the federation registration boundary. LIGO Wiki's RP similarly uses federation evidence to configure a protocol interaction, then hands control to its OIDC client implementation.

Before a sign-in test, inspect both effective metadata blocks and confirm the advertised endpoints reach the actual protocol engine. Keep federation route paths separate from application endpoints that use different authentication and response formats. A successful Entity Configuration request is only the first integration check.

Role metadata ownership

OIDC and OAuth roles copy constructor metadata, including nested values. OAuthResourceRole also copies separately supplied jwks. Attaching a role can generate fields such as the registration endpoint without writing them back into the caller's configuration. A host takes its own metadata snapshot after role initialization.

Use parsePublicationMetadata() while preparing metadata that a Superior may complete later. Use parseMetadata() for the effective protocol metadata you intend to consume. Both return parse results; a successful parse establishes neither signatures nor federation trust. For OAuth Resource metadata, the existing document mode also checks the requirements of a protected-resource metadata document.

Instance operations that need a host identity require an initialized role. Configuration and missing-initialization errors can throw; protocol operations otherwise retain their documented Result or HTTP error responses. Instance methods inherit the host engine. Other call settings override role and host defaults; algorithm lists intersect and crypto resource ceilings take the smallest value. Explicit trust-anchor arguments take precedence over role and host defaults.

Compose the RP with its federation host

Roles represent OIDC and OAuth functions (such as Relying Parties or OpenID Providers). They are composed directly into a parent Leaf, TrustAnchor, or Intermediate entity. The parent entity merges the role's metadata and routes standard path requests to the role's handlers automatically.

import { generateSoftwareKey, softwareCrypto, softwareEntry } from "../examples/software-crypto.js";
import { Leaf } from "@oidfed/leaf";
import { OidcRelyingPartyRole } from "@oidfed/oidc";


// 1. Setup federation keys
const fedKeyPair = await generateSoftwareKey("ES256");


// 2. Set up protocol signing purposes (used to sign Request Objects)
const protocolKeyPair = await generateSoftwareKey("ES256");
const crypto = softwareCrypto(fedKeyPair.privateKey, protocolKeyPair.privateKey);

// 3. Initialize parent Leaf with OidcRelyingPartyRole role composed
const leaf = await Leaf.create({
  entityId: "https://rp.example.com",
  authorityHints: ["https://federation.example.org"],
  crypto,
  metadata: {
    federation_entity: { organization_name: "My Org" }
  },
  roles: [
    new OidcRelyingPartyRole({
      signing: {requestObject:"request_object", clientAssertion:"client_assertion"},
      metadata: {
        client_name: "My OIDC RP",
        redirect_uris: ["https://rp.example.com/callback"],
        response_types: ["code"],
        client_registration_types: ["automatic"],
      }
    })
  ]
});

Each stateful role instance belongs to one host. Create a separate instance for another Entity Identifier. Request construction uses the final composed local metadata, including fields supplied by the host. Per-call options override supplied fields while retaining the host’s other federation options, including its HTTP client and clock.

An OidcProviderRole or OAuthAuthorizationServerRole installs an explicit-registration handler. Its final composed metadata must include "explicit" in client_registration_types_supported, as required by Federation §12.2. Supply that capability through the role or host metadata. Missing or incompatible configuration fails before publication. RP registration-method choices remain application configuration.

When publishing OP or AS metadata, a supplied issuer must exactly match the host’s Entity Identifier (§5.1.3, §5.1.4). Before sending explicit registration, the RP also checks that the discovered registration endpoint uses HTTPS and has no fragment, including a bare trailing #. Invalid endpoints return invalid_metadata without a POST. Query strings and explicit ports remain supported.

OIDCFederationPublicationMetadata describes metadata published before superior completion under Federation §5. Its protocol blocks may omit fields supplied by superiors. OIDCFederationMetadata and the protocol-specific metadata types describe effective metadata; protocol APIs validate the effective metadata before consuming it.

Client configuration precedence

OidcRelyingPartyRoleConfig also accepts trustAnchors and authorityHints. Its registration methods take trust anchors from call options, then role config, then the parent context. Authority hints come from the parent context when present.

Provider replay and persistence hooks

Both provider configurations accept onRegistration. The roles use their host’s storage.replay for automatic registration and PAR. Advertising either capability requires replay storage at startup. Explicit-only registration can run without it. onRegistration(sub, clientMetadata, clientSecret?) lets you persist the accepted registration. The selected role determines whether client metadata uses openid_relying_party or oauth_client.

On success, automatic processing returns ProcessedAutomaticRegistration inside a Result, including protocolKeys: { keys, source } from the Request Object verification. The onRegistration callback receives a detached metadata copy with those keys in jwks, including when they were resolved through jwks_uri or signed_jwks_uri. Resolution keeps the precedence in Federation §5.2.1. Explicit registration retains its existing result and metadata handling.

Explicit-registration processing errors use the §8.9 status mappings referenced by §12.2.4: invalid_trust_chain returns 400, and invalid_trust_anchor returns 404. An invalid request signature returns 400 invalid_request; internal failures receive a sanitized server error.

Assess protocol entities and accreditation issuers

Role configuration accepts options for federation defaults, including chainSelection and trustResolution. Per-call options override role options, which override host options. Existing calls keep their default behavior when these settings are omitted.

Each role exposes static and instance assessEntity(target, entityType, ...) methods. Static calls take explicit anchors before options; instance calls use configured anchors or options.trustAnchors. The role validates metadata for the requested entity type. Local assessments select only among chains with usable protocol metadata. The protocol filter applies to the requested subject. Nested Trust Mark issuer discovery uses the issuer's accreditation rules, without requiring it to publish the subject's protocol metadata. If supplied, your chainSelection callback also receives eligible issuer chains, so it should handle each candidate's entityId. See Federation §17.5. Explicit resolver assessments authenticate the resolver's assertion and keep that provenance separate from local chain validation.

Both automatic and explicit registration filter out malformed effective OP metadata before calling the selector. OIDC registration continues to validate every required statement, retain RP/OP shared-anchor rules, and verify protocol metadata before signing or sending registration requests. Existing APIs consuming DiscoveryResult can use core's discoverEntityFromChain for supplied evidence. Resolver-only assessments cannot substitute for that type.

See core trust establishment for configuration examples and the distinction between resolver acquisition and delegation.

Next: 15.2. Register through an OIDC authorization request

View source on GitHub