15.3. Register explicitly with an OP
Feature guides / 15. OIDC and OAuth workflows · Example context
Research Portal registers with Umeå University OP before starting a user authorization request. It sends federation evidence to the OP's dedicated registration endpoint and receives a signed registration result.
How to use it
explicitlyRegister() on an initialized RP discovers the OP and performs the exchange. OidcProviderRole exposes the mounted registration handler through its host and through processExplicitRegistration(). Both sides validate the relevant effective metadata and policy. Explicit registration; Registration lifetime.
import type { OidcRelyingPartyRole } from "@oidfed/oidc";
export async function registerLibrary(rp: OidcRelyingPartyRole) {
const result = await rp.explicitlyRegister("https://op.umu.example");
if (!result.ok) return result;
const useUntil = Math.min(result.value.expiresAt, result.value.trustChainExpiresAt);
return { registration: result.value, useUntil };
}
Choose an eligible federation path
Umeå University OP can set options.chainSelection on its provider role to choose among validated RP chains. The default is the shortest eligible chain. The same option applies to automatic registration. If discovery is incomplete, a custom selector is not called and registration stops before signing or persistence. Discovery and validation share maxTotalFetches, including any accreditation issuer discovery.
The registration request belongs to Research Portal. Its aud and submitted Entity Configuration are not reused when validating a separate Trust Mark issuer. An accreditation issuer can follow its own chain without implementing the RP's protocol role.
Let the RP read its registered metadata
Umeå University OP normally omits registration-management credentials. If it already operates a read-only registration endpoint, it can opt into the exception in Federation §12.2.2:
import type { OidcProviderRoleConfig } from "@oidfed/oidc";
const readOnlyRegistration = {
registrationManagement: "read-only",
} satisfies Pick<OidcProviderRoleConfig, "registrationManagement">;
Include this setting in the provider role configuration. The existing registration adapter supplies registration_access_token and registration_client_uri together. The library validates the pair and checks federation policy before signing. Research Portal receives them in registeredMetadata.
Umeå University OP must issue and store the token, serve the HTTPS registration URI, and handle revocation. That token MUST NOT allow changes to the registration. The option does not create an endpoint or restrict token permissions for you.
What your application owns
Persist the returned metadata and any secret securely, together with expiry. Advertise explicit support and serve the endpoint when using the provider role. A registration response is not a user session or an access token. A client_secret_expires_at of 0 means the secret has no expiry; the registration still expires and needs renewal. Re-register when the applicable lifetime ends; do not preserve an older successful result indefinitely after a failed refresh.
Require accreditation before registration
Configure trustMarkRequirements: { requiredTypes: [type] } on the provider role. An optional beforeRegistration callback can add host policy using immutable authenticated chain evidence. Requirements run first; both must pass before registration persistence, response signing, or replay consumption. Callback exceptions and malformed results reject registration. Evidence lifetime is checked again after an asynchronous callback returns.
Issuer verification can use independent accreditation anchors through options.trustMarkVerification. Current active-status checks remain the host's policy choice. See Trust Mark validation and the provider API.
Retain the accepted registration lifetime
Research Portal sends an explicit registration request and verifies the signed OP response before saving the effective client configuration. Preserve the registration's evidence lifetime with that record, including any applicable client-secret limit.
The default response omits registration-management credentials. If the provider explicitly enables read-only management, its adapter must return the paired token and URI, and the host must enforce the token's read-only behavior at the endpoint. The library checks the returned shape; it does not implement the host's management endpoint or grant broader permission to mutate registration.
Provider validation and response processing
The example assumes pinned taPublicKey and an RSA opProtocolPublicKey used by the existing OP for RS256 signatures. Compose opRole into the parent entity to initialize and route it. If confidential clients need secrets, provide generateClientSecret backed by your credential store and a cryptographically secure generator.
For explicit registration, OPs serve a /registration endpoint. RPs post their self-signed Entity Configuration or trust chains, and OPs reply with a signed explicit registration response whose sub is the RP Entity Identifier and whose registered client credentials are under metadata.openid_relying_party.
The OP validates a supplied trust_chain header or application/trust-chain+json body. Without a supplied chain, it starts discovery from the submitted Entity Configuration and its authority hints. Each candidate must authenticate that request with the RP federation keys attested by its Immediate Superior before the OP selects a path. Explicit and automatic processing both honor options.chainSelection; without it they choose the shortest eligible chain. Explicit processing calls the selector only after request, metadata, and entity-type checks. Incomplete discovery with a custom selector fails before selection or registration side effects. Discovery, candidate validation, peer evidence, and accreditation issuer discovery share maxTotalFetches (50 by default). A zero budget permits supplied or cached evidence that needs no transport. Invalid supplied chains fail registration. Request media types are parameter-free and matched exactly. See Federation §12.2.2.
The submitted metadata is resolved through the selected chain's superior metadata, constraints, and metadata policy. The adapter receives that resolved metadata, and its final output must satisfy the same federation policy (§12.2.2, §6.1.4.2). Registration hooks run after response preparation.
Unchanged resolved values retain their policy result. Adapters may change fields governed by standard operators or custom check operators when the result passes those policies. Fields governed by a custom modifying operator must retain their resolved value, including an omission. This is the library's registration contract: custom operators may transform values without being idempotent under §6.1.3.2. The RP applies the same rule when checking response metadata.
Optional response defaults are included when federation policy permits them; a value: null removal remains omitted. See §12.2.3 and §6.1.3.1.1.
The RP selects a shared-anchor path that attests its current signing key and sends that path's Immediate Superior as its authority hint, as allowed by §12.2.1. Explicit registration needs an Immediate Superior because the response must name it under §12.2.3. An entity that is also a configured anchor can register through an eligible upward path.
Both sides accept finite NumericDates and validate required statement times and payload crit claims. Fractional timestamps are preserved in registration and chain deadlines. Configure understoodCriticalClaims only for extensions your application understands and processes. Unknown critical claims fail validation under §3.1.1.
RP Entity Configuration metadata under metadata.openid_relying_party must not include registration-response-only credential fields such as client_id, client_secret, client_id_issued_at, or client_secret_expires_at.
RP-side explicit registration accepts only HTTP 200 responses with exact Content-Type: application/explicit-registration-response+jwt. The RP rejects a response whose iat is later than its current time plus clockSkewSeconds (60 seconds by default), as required by Federation §12.2.5 and §3.2. The response must name the selected Trust Anchor, use the authority hint from the selected RP trust chain, and expire no later than that selected RP trust chain. It returns clientId from metadata.openid_relying_party.client_id and clientSecret from metadata.openid_relying_party.client_secret when the OP provisions one. If the OP also sends client_secret_expires_at, a positive value must not be earlier than the signed response expiry. The value 0 means the secret does not expire, as defined by OpenID Connect Registration §3.2. It does not extend the registration lifetime.
By default, OP-side explicit registration removes adapter-enriched registration_access_token and registration_client_uri before response validation, signing, and persistence hooks. Federation §12.2.2 says OPs SHOULD NOT provide them, but allows a token for reading registered metadata.
To use that exception, set registrationManagement: "read-only" on OidcProviderRole or OAuthAuthorizationServerRole. Your existing registrationProtocolAdapter.enrichResponseMetadata() can supply the pair. Both fields must be present together: a non-empty token and an HTTPS URI without a fragment. They must also satisfy the selected federation policy. The RP checks the pair and exposes it in registeredMetadata.
The option preserves those response fields; your application issues and stores the token, serves the registration URI, and handles revocation. That endpoint MUST NOT let the token modify client metadata. Enable the option only when your endpoint enforces read-only access; oidfed does not create a management endpoint or infer token permissions.
import { OidcProviderRole } from "@oidfed/oidc";
import { createTrustAnchorSet } from "@oidfed/core";
import { type JWK } from "@oidfed/core";
export async function createExplicitProvider(taPublicKey: JWK, opProtocolPublicKey: JWK) {
const trustAnchors = createTrustAnchorSet([
{
entityId: "https://ta.example.org",
jwks: { keys: [taPublicKey] }
}
]);
const opRole = new OidcProviderRole({
registrationPath: "/registration",
trustAnchors,
registrationResponseTtlSeconds: 3600,
metadata: {
issuer: "https://op.example.com",
response_types_supported: ["code"],
subject_types_supported: ["public"],
id_token_signing_alg_values_supported: ["RS256"],
authorization_endpoint: "https://op.example.com/auth",
token_endpoint: "https://op.example.com/token",
client_registration_types_supported: ["automatic", "explicit"],
jwks: { keys: [opProtocolPublicKey] }
}
});
return opRole;
}