Skip to content

feat: support discovery config for lazy metadata fetching#44

Merged
xiaoyijun merged 2 commits intomasterfrom
xiaoyijun-feat-lazy-auth-config
Jan 20, 2026
Merged

feat: support discovery config for lazy metadata fetching#44
xiaoyijun merged 2 commits intomasterfrom
xiaoyijun-feat-lazy-auth-config

Conversation

@xiaoyijun
Copy link
Copy Markdown
Contributor

@xiaoyijun xiaoyijun commented Jan 19, 2026

Summary

Add support for discovery config (AuthServerDiscoveryConfig) that allows lazy metadata fetching. This is especially useful for edge runtimes like Cloudflare Workers where top-level async fetch is not allowed.

Changes

  • New types: ResolvedAuthServerConfig (with metadata) and AuthServerDiscoveryConfig (issuer + type only), unified as AuthServerConfig
  • New class: AuthServerMetadataCache with two-layer caching (valueCache + promiseCache) to prevent duplicate concurrent requests
  • Updated handlers: TokenVerifier and AuthorizationServerHandler now support both config types
  • Validation: Discovery configs are validated after metadata is fetched

Usage

// Discovery config - metadata fetched on-demand
const mcpAuth = new MCPAuth({
  protectedResources: [{
    metadata: {
      resource: 'https://api.example.com',
      authorizationServers: [{ issuer: 'https://auth.logto.io/oidc', type: 'oidc' }],
    },
  }],
});

// Resolved config - pre-fetched metadata (existing behavior)
const authServerConfig = await fetchServerConfig('https://auth.logto.io/oidc', { type: 'oidc' });
const mcpAuth = new MCPAuth({
  protectedResources: [{
    metadata: {
      resource: 'https://api.example.com',
      authorizationServers: [authServerConfig],
    },
  }],
});

Testing

unit tests

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@xiaoyijun xiaoyijun force-pushed the xiaoyijun-feat-lazy-auth-config branch 2 times, most recently from 5d2cc35 to cdfb215 Compare January 19, 2026 13:41
@xiaoyijun xiaoyijun requested a review from a team January 19, 2026 13:43
@xiaoyijun xiaoyijun self-assigned this Jan 19, 2026
@xiaoyijun xiaoyijun force-pushed the xiaoyijun-feat-lazy-auth-config branch from cdfb215 to 57dfe56 Compare January 20, 2026 04:03
@xiaoyijun xiaoyijun requested a review from gao-sun January 20, 2026 04:03
@xiaoyijun xiaoyijun merged commit f722a3b into master Jan 20, 2026
5 checks passed
@xiaoyijun xiaoyijun deleted the xiaoyijun-feat-lazy-auth-config branch January 20, 2026 07:38
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