Skip to content
Wallet and Entity Collection draft updates
Documentation menu

15.8. Describe OAuth clients, servers, and resources

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

Research API exposes an API protected by its authorization service. The resource, authorization server, and requesting client have different metadata even when one organization operates them.

The Research API and its client are supplementary OAuth examples under the academic federation. They are not services attributed to the organizations in Appendix A.

How to use it

OAuthClientRole, OAuthAuthorizationServerRole, and OAuthResourceRole compose with federation hosts and expose independent metadata parsers. Select the RFC 9728 profile when validating a protected-resource discovery document; ordinary Federation resource metadata has its own optionality. OAuth entity types; AS metadata; Resource metadata.

import { OAuthClientRole, OAuthAuthorizationServerRole, OAuthResourceRole } from "@oidfed/oidc";

export function validateOAuthInputs(client: unknown, server: unknown, resourceDocument: unknown) {
  return {
    client: OAuthClientRole.parseMetadata(client),
    server: OAuthAuthorizationServerRole.parseMetadata(server),
    resource: OAuthResourceRole.parseMetadata(resourceDocument, { profile: "rfc9728" }),
  };
}

Register a Research API client

Research API can use both Federation registration methods without OpenID Connect. Its client publishes oauth_client; its authorization service publishes oauth_authorization_server. The roles select those blocks even if an entity also publishes OIDC metadata.

For an OAuthClientRole already attached to its federation host:

import { type OAuthClientRole } from "@oidfed/oidc";

export async function startOAuthAuthorization(researchClient: OAuthClientRole) {
  const request = await researchClient.automaticallyRegister({
    authorizationServerEntityId: "https://auth.research-api.example",
    redirect_uri: "https://research-client.example/callback",
    scope: "datasets.read",
  });
  if (!request.ok) return request;
  // Deliver request.value using its selected delivery method.
  return request;
}

The receiving OAuthAuthorizationServerRole calls processAutomaticRegistration(requestObjectJwt), with its host's replay store and registration hooks configured. For registration in advance, call researchClient.explicitlyRegister(serverId); the AS host serves the mounted registration endpoint, or delegates to processExplicitRegistration(request).

Superior metadata and policy can complete missing publication fields before either flow uses them. Request Objects use the client's protocol keys. Explicit registration uses Federation keys and returns its client metadata under oauth_client. Neither flow requires OpenID scope or ID Token metadata. Shared-anchor selection, peer chains, accreditation, and expiry checks work as in the OIDC flows, following Federation §12.

What your application owns

The application runs OAuth authorization/token/resource endpoints and enforces scopes and token checks. A resource metadata parser does not protect an API route. The AS role's installed federation registration endpoint requires explicit registration support; the host supplies protocol behavior beyond the federation exchange. Unknown extension metadata remains available, but publication validation and effective validation have different completeness requirements.

Use the OAuth profile explicitly

Research API can be an OAuth client, authorization server, and protected resource without publishing OIDC role metadata. Choose the corresponding role class so registration selects the OAuth metadata names and schemas. Co-publishing OIDC metadata does not implicitly switch the chosen profile.

A resource's federation metadata is also distinct from a standalone protected-resource discovery document. Validate the document with its own required fields when serving or consuming that protocol endpoint. The federation role does not implement authorization grants, token issuance, or resource access control for the application.

Register an OAuth client

Federation §12 permits both registration methods for OAuth profiles. OAuthClientRole offers automaticallyRegister(), explicitlyRegister(), createAuthorizationRequest(), and instance createClientAssertion() alongside its metadata parsers. OAuthAuthorizationServerRole offers processAutomaticRegistration() and processExplicitRegistration() with the same replay-store, accreditation, adapter, and persistence hooks as the OIDC provider role.

For roles already attached to federation hosts:

import type { OAuthClientRole, OAuthAuthorizationServerRole } from "@oidfed/oidc";

async function registerOAuthClient(client: OAuthClientRole, server: OAuthAuthorizationServerRole) {
  const request = await client.automaticallyRegister({
    authorizationServerEntityId: "https://auth.research-api.example",
    redirect_uri: "https://research-client.example/callback",
    scope: "datasets.read",
  });
  if (!request.ok) return request;
  // At the authorization server, after receiving the Request Object:
  return server.processAutomaticRegistration(request.value.requestObjectJwt);
}

async function registerInAdvance(client: OAuthClientRole) {
  return client.explicitlyRegister("https://auth.research-api.example");
}

Each flow validates oauth_client and oauth_authorization_server after Superior metadata and policies have completed them. It uses OAuth protocol keys for Request Objects and Federation keys for explicit-registration statements. It does not require OpenID scopes, ID Token algorithms, or OIDC subject metadata. Explicit responses carry credentials under metadata.oauth_client; OAuthClientRegistrationResponseMetadata describes that block. Existing result names such as resolvedRpMetadata and rpEntityId also represent the OAuth client in this flow.

For automatic registration and PAR, supply storage.replay on the AS role’s host. Both profiles honor host chain selection and shared fetch budgets, validate peer chains against the matching provider type, and run accreditation before registration side effects. Registration-management credentials remain disabled unless the host enables read-only registration access. The host still implements authorization, tokens, consent, and storage.

When requestDelivery: "request_uri" is used, OP metadata that explicitly sets request_uri_parameter_supported: false blocks delivery before an authorization URL is produced.

For OIDC query, form-post, and hosted Request Object delivery, the authorization URL or form fields include the supplied scope and response_type alongside client_id. These values match the signed claims, as required by OpenID Connect Core §§6.1 and 6.2 and permitted by JAR §5. OAuth-only delivery uses the existing JAR parameters. With PAR, authorization parameters stay inside the JWT and client authentication stays outside it, per RFC 9126 §3.

import { createTrustAnchorSet, isOk } from "@oidfed/core";
import { type JWK } from "@oidfed/core";
import { type OidcRelyingPartyRole } from "@oidfed/oidc";

export async function startSignIn(taKey: JWK, rpRole: OidcRelyingPartyRole, sessionState: string, sessionNonce: string) {
  const trustAnchors = createTrustAnchorSet([
    { entityId: "https://ta.example.org", jwks: { keys: [taKey] } }
  ]);

  const authzResult = await rpRole.automaticallyRegister(
    {
      opEntityId: "https://op.example.com",
      redirect_uri: "https://rp.example.com/callback",
      scope: "openid profile",
      state: sessionState,
      nonce: sessionNonce,
      requestDelivery: "query"
    },
    { trustAnchors, httpClient: fetch }
  );

  if (isOk(authzResult) && authzResult.value.delivery === "query") {
    const { authorizationUrl } = authzResult.value;
    console.log("Redirect user to:", authorizationUrl);
  }
  return authzResult;
}

Next: 16. Wallet workflows

View source on GitHub