Skip to content

feat(auth): integrate Better Auth with Cloudflare D1 for MCP & OAuth 2.1 Dynamic Client Registration - #726

Merged
codercatdev merged 1 commit into
devfrom
feat/better-auth-mcp
Oct 13, 2026
Merged

codercatdev merged 1 commit into
devfrom
feat/better-auth-mcp

Conversation

@codercatdev

Copy link
Copy Markdown
Contributor

Summary

Resolves Gemini Custom MCP connection error (Automatic registration with this server failed. Enter your OAuth client ID and client secret to connect.) by providing full RFC 7591 Dynamic Client Registration (DCR), RFC 8414 Authorization Server Metadata, RFC 9728 Protected Resource Metadata, and JWKS endpoints powered by Better Auth (better-auth, @better-auth/oauth-provider, @better-auth/mcp) backed by Cloudflare D1.

Changes

  • Better Auth Integration (apps/site/src/lib/auth.ts):
    • Configured Better Auth with jwt() and @better-auth/mcp plugin.
    • Dynamically binds Cloudflare D1 (env.DB) on Cloudflare Workers runtime with memory fallback for SSR/testing.
    • Enables unauthenticated RFC 7591 Dynamic Client Registration (allowDynamicClientRegistration: true, allowUnauthenticatedClientRegistration: true).
  • OAuth 2.1 / DCR Endpoints (apps/site/src/pages/oauth2/[...slug].ts):
    • Handles /oauth2/register, /oauth2/token, /oauth2/authorize, etc.
    • Added legacy alias rewrite in apps/site/src/pages/oauth/[...slug].ts mapping /oauth/* to /oauth2/*.
  • Discovery & Metadata:
    • /.well-known/oauth-authorization-server: RFC 8414 metadata advertising registration_endpoint, Auth.md agent_auth, and authorization/token endpoints.
    • /.well-known/openid-configuration: OpenID Connect discovery.
    • /.well-known/oauth-protected-resource: RFC 9728 metadata.
    • apps/site/src/pages/jwks.ts and apps/site/src/pages/.well-known/jwks.json.ts: Dynamic public cryptographic keys.
    • apps/site/src/middleware.ts: RFC 8288 Link header pointing to authorization server.
  • Cloudflare D1 Database Binding & Migrations:
    • Bound D1 database DB (codingcat-auth-dev top-level, codingcat-auth in env.production) in apps/site/wrangler.jsonc.
    • Added migration 0001_better_auth.sql covering core user/session, OAuth 2.1 provider (oauthClient, oauthResource, etc.), and JWKS tables. Migrations applied to remote D1 databases.
  • Testing:
    • Added E2E tests 7.11 (RFC 7591 DCR registration) and 7.12 (legacy OAuth alias rewrite). All 158 tests passing.

@github-actions

Copy link
Copy Markdown

⚡ Cloudflare Worker Preview Ready!

Environment URL
PR Preview https://90614bca-codingcatdev-dev.codingcatdev.workers.dev
Dev Custom Domain https://dev.codingcat.dev
  • Worker Version ID: 90614bca-6823-41fb-bb79-14f9366ee767
  • Protection: Restricted to @codingcat.dev accounts via Cloudflare Zero Trust Access

@codercatdev
codercatdev merged commit 862120f into dev Oct 13, 2026
2 checks passed
@codercatdev
codercatdev deleted the feat/better-auth-mcp branch October 13, 2026 19:16
codercatdev added a commit that referenced this pull request Oct 13, 2026
…gistration to main (#727)

* feat(syndication): add syndicate-post workflow and dispatch runner (#708)

* fix(syndication): update Hashnode tag shape to PublishPostTagInput (#710)

* fix(syndication): update Hashnode coverImage input to string URL (#713)

* feat(seo): add VideoObject structured data and Gemini video storyboard pipeline (#715)

* fix(video): upgrade to Gemini 2.5 Pro with native Google AI and OpenRouter support (#717)

* feat: complete Shorts story (/shorts shelf + kinetic captions + sync), Gemini 2.5/TTS upgrades, and TechArticle/Auto-FAQ AEO pack (#720)

* chore: remove legacy apps/web Next.js directory and revert Gemini/Shorts pipeline additions (keep SEO schema) (#722)

* feat(analytics): add Cloudflare Workers Analytics Engine edge telemetry, sendBeacon click tracking, and first-party PostHog /ingest proxy (#724)

* feat(site): wire sponsorships and guest booking to FlipFeeds Creator OS dev/prod APIs

* fix(ci): deploy latest Worker version before updating secrets in deploy-workers.yml

* fix(site): defer analytics_engine_datasets binding until Analytics Engine is enabled on account

* feat(auth): integrate Better Auth with Cloudflare D1 for MCP and OAuth 2.1 Dynamic Client Registration (#726)
codercatdev added a commit that referenced this pull request Oct 13, 2026
…en issuance to main (#729)

* feat(syndication): add syndicate-post workflow and dispatch runner (#708)

* fix(syndication): update Hashnode tag shape to PublishPostTagInput (#710)

* fix(syndication): update Hashnode coverImage input to string URL (#713)

* feat(seo): add VideoObject structured data and Gemini video storyboard pipeline (#715)

* fix(video): upgrade to Gemini 2.5 Pro with native Google AI and OpenRouter support (#717)

* feat: complete Shorts story (/shorts shelf + kinetic captions + sync), Gemini 2.5/TTS upgrades, and TechArticle/Auto-FAQ AEO pack (#720)

* chore: remove legacy apps/web Next.js directory and revert Gemini/Shorts pipeline additions (keep SEO schema) (#722)

* feat(analytics): add Cloudflare Workers Analytics Engine edge telemetry, sendBeacon click tracking, and first-party PostHog /ingest proxy (#724)

* feat(site): wire sponsorships and guest booking to FlipFeeds Creator OS dev/prod APIs

* fix(ci): deploy latest Worker version before updating secrets in deploy-workers.yml

* fix(site): defer analytics_engine_datasets binding until Analytics Engine is enabled on account

* feat(auth): integrate Better Auth with Cloudflare D1 for MCP and OAuth 2.1 Dynamic Client Registration (#726)

* fix(auth): handle automated MCP account linking and refresh token issuance (#728)
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.

1 participant