Skip to content

feat(auth): DCR hooks, introspection auth, and prehandler fixes#100

Merged
mcollina merged 1 commit intoplatformatic:mainfrom
getlarge:feat/dcr-hooks-and-introspection-auth
Apr 8, 2026
Merged

feat(auth): DCR hooks, introspection auth, and prehandler fixes#100
mcollina merged 1 commit intoplatformatic:mainfrom
getlarge:feat/dcr-hooks-and-introspection-auth

Conversation

@getlarge
Copy link
Copy Markdown
Contributor

Summary

Adds DCR proxy hooks and introspection authentication support for Ory Hydra integration.

⚠️ Dependency: This PR depends on #97 (OIDC Discovery) and should be merged after it.

Changes

1. Skip /oauth/register in auth prehandler

DCR endpoint must be accessible before client has credentials.

2. Add introspectionAuth configuration

Supports bearer (API key), basic (client credentials), or none for token introspection authentication.

tokenValidation: {
  introspectionEndpoint: 'https://ory.example.com/admin/oauth2/introspect',
  introspectionAuth: { type: 'bearer', token: 'api-key' }
}

3. Add dcrHooks for DCR proxy pattern

Enables MCP server to act as a DCR proxy with request/response transformation.

dcrHooks: {
  upstreamEndpoint: 'https://ory.example.com/oauth2/register',
  onResponse: async (response) => {
    // Clean empty fields that break Claude Code's Zod validation
    if (response.client_uri === '') delete response.client_uri;
    return response;
  }
}

Breaking Change

/oauth/register returns 501 unless dcrHooks is configured. This prevents infinite loops when OIDC discovery points back to the MCP server.

Tests

  • ✅ All 45 OAuth/token-validator tests pass
  • ✅ New tests for introspectionAuth (bearer, basic, none)
  • ✅ New tests for dcrHooks (501 without config, proxy with hooks)

Related

🤖 Generated with Claude Code

@mcollina
Copy link
Copy Markdown
Member

mcollina commented Apr 8, 2026

can you rebase?

@getlarge
Copy link
Copy Markdown
Contributor Author

getlarge commented Apr 8, 2026

Happily.
That’s great to see those PRs being merged, I hope you’ll keep the dynamic going, as another PR to bring OpenTelemetry support will come at the same time. Tonight or tomorrow.
Happy JS days :)

This commit adds several OAuth/DCR improvements:

Patch 3.1: Skip /oauth/register in auth prehandler
- DCR endpoint must be accessible before client has credentials
- Fixes chicken-and-egg problem with dynamic registration

Patch 3.2: Add introspectionAuth configuration
- Supports bearer (API key), basic (client credentials), or none
- Required for Ory Hydra admin introspection endpoint
- Backwards compatible - defaults to no auth header

Patch 3.3: Pass DCR request body through to dynamicClientRegistration
- Client metadata is now merged with defaults (client wins)
- Allows clients to specify their own redirect_uris, client_name, etc.

Patch 4: Add dcrHooks for DCR proxy pattern
- upstreamEndpoint: Required, bypasses OIDC discovery to avoid loops
- onRequest: Hook to transform/enrich DCR request
- onResponse: Hook to clean/transform DCR response (e.g., remove empty fields)
- Returns 501 when not configured (prevents infinite loop)

Breaking change: /oauth/register now returns 501 unless dcrHooks is configured.
This prevents infinite loops when OIDC discovery points back to the MCP server.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@getlarge getlarge force-pushed the feat/dcr-hooks-and-introspection-auth branch from dfe6556 to 8c3d8fd Compare April 8, 2026 18:43
@mcollina mcollina merged commit 289d6c0 into platformatic:main Apr 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants