Catalog npm
PACKAGE EXPLORERView in registry

@0x-wim/mcp-oauth

npm

Platform-independent OAuth 2.1 authorization provider

Versions collected4
Direct dependencies9From release 0.2.1
Last observed20 Oct, 22:20 UTC

README

Current package documentation

@0x-wim/mcp-oauth

Platform-independent OAuth 2.1 provider, forked from @cloudflare/workers-oauth-provider with Cloudflare dependencies removed. Runs on Next.js, Node.js, and any standard fetch environment.

Installation

npm install @0x-wim/mcp-oauth

Packages

Entry pointContents
@0x-wim/mcp-oauthCore OAuthProvider, MemoryStore, StorageAdapter
@0x-wim/mcp-oauth/nextNext.js App Router helpers (createOAuthHandlers, getAuth)
@0x-wim/mcp-oauth/oidcOIDC discovery and ID token verification

Storage

Instead of Cloudflare KV, supply a StorageAdapter. MemoryStore is provided for development:

import { OAuthProvider, MemoryStore } from '@0x-wim/mcp-oauth';

const provider = new OAuthProvider({
  storage: new MemoryStore(),
  // ...
});

For production, implement the StorageAdapter interface (get, put, delete, list) backed by Redis, a database, etc.

Basic Usage

import { OAuthProvider, MemoryStore } from '@0x-wim/mcp-oauth';

const provider = new OAuthProvider({
  storage: new MemoryStore(),
  apiRoute: ['/api/'],
  apiHandler: {
    async fetch(request, env, ctx) {
      return new Response(`Hello, ${ctx.props.username}`);
    },
  },
  defaultHandler: {
    async fetch(request, env, ctx) {
      const url = new URL(request.url);
      if (url.pathname === '/authorize') {
        const oauthReqInfo = await env.OAUTH_PROVIDER.parseAuthRequest(request);
        // ... render consent UI ...
        const { redirectTo } = await env.OAUTH_PROVIDER.completeAuthorization({
          request: oauthReqInfo,
          userId: '1234',
          scope: oauthReqInfo.scope,
          props: { username: 'Alice' },
        });
        return Response.redirect(redirectTo, 302);
      }
      return new Response('Not found', { status: 404 });
    },
  },
  authorizeEndpoint: '/authorize',
  tokenEndpoint: '/oauth/token',
  clientRegistrationEndpoint: '/oauth/register',
});

Next.js App Router

// app/[...oauth]/route.ts
import { createOAuthHandlers } from '@0x-wim/mcp-oauth/next';
export const { GET, POST, OPTIONS, DELETE, PUT, PATCH } = createOAuthHandlers(provider);

The Next adapter automatically reconstructs the public request URL from Forwarded, X-Forwarded-*, and Host headers before calling the provider, so standalone/Docker deployments do not leak internal hostnames in OAuth metadata or audience checks.

Authenticate requests in route handlers:

import { getAuth } from '@0x-wim/mcp-oauth/next';

const auth = await getAuth(provider, request);
if (!auth.authenticated) return auth.error;
// auth.token.grant.props — your user data

OIDC Helpers

import { discoverOIDC, verifyIdToken, fetchUserInfo } from '@0x-wim/mcp-oauth/oidc';

const config = await discoverOIDC('https://accounts.google.com');
const payload = await verifyIdToken(idToken, {
  jwks: config.jwks_uri,
  issuer: config.issuer,
  audience: 'your-client-id',
});

Key Options

See the upstream README for full option documentation. Differences from upstream:

  • storage: StorageAdapter — required (replaces OAUTH_KV binding)
  • No Cloudflare-specific setup needed (no wrangler.jsonc, no compatibility flags)

Standards

OAuth 2.1 · RFC 8414 · RFC 9728 · RFC 7591 · RFC 8693 · RFC 8707 · MCP Authorization

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 4

Collected releases
VersionPublishedDirect dependenciesOpen version
0.2.1Registry latest8 Apr 20269
0.2.08 Apr 20269
0.1.129 Mar 20268
0.1.029 Mar 20268

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
wim-web/mcp-oauth

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:20 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:06b8ddc70979959d6af1ab595426879981c89036f4f3aa4cb993ebf854f819d8