Remove embedded OAuth implementation and flatten directory structure

Simplified the repository to have a single OAuth pattern with separate auth and MCP servers at the top level. Preserved embedded OAuth documentation as an alternative pattern.
This commit is contained in:
Basil Hosmer 2025-10-06 21:07:18 -04:00
commit c03a9b4e77
No known key found for this signature in database
2 changed files with 1556 additions and 15846 deletions

View file

@ -2,23 +2,27 @@
set -e
echo "=================================================="
echo "End-to-End Test - Embedded OAuth"
echo "End-to-End Test - OAuth Flow and MCP Features"
echo "=================================================="
echo "This script tests the complete OAuth flow and MCP features"
echo "using auth server and MCP server."
echo ""
# Kill any existing servers
echo "🛑 Cleaning up existing servers..."
pkill -f "node.*dist.*index" || true
pkill -f "node.*dist/index" || true
pkill -f "tsx watch.*src/index" || true
sleep 2
# Use environment variables if available, otherwise defaults
AUTH_SERVER="${AUTH_SERVER_URL:-http://localhost:3001}"
MCP_SERVER="${BASE_URI:-http://localhost:3232}"
USER_ID="e2e-test-$(date +%s)"
echo "🔧 Configuration:"
echo " Auth Server: $AUTH_SERVER"
echo " MCP Server: $MCP_SERVER"
echo " User ID: $USER_ID"
echo " Auth Mode: ${AUTH_MODE:-integrated} (from environment)"
echo ""
# Check prerequisites
@ -32,87 +36,126 @@ if ! docker ps | grep -q redis; then
fi
echo "✅ Redis is running"
# Check if wrong mode is set
if [ "${AUTH_MODE:-integrated}" != "integrated" ]; then
echo "⚠️ AUTH_MODE is set to '${AUTH_MODE}' but this script tests integrated mode"
echo " Either run: AUTH_MODE=integrated $0"
echo " Or use: ./scripts/test-separate-e2e.sh"
fi
# Start auth server
echo "Starting auth server..."
(cd auth-server && npm start) &
AUTH_PID=$!
sleep 5
# Start MCP server with embedded OAuth
echo "Starting MCP server with embedded OAuth..."
(cd embedded-oauth && npm start) &
# Check auth server
if ! curl -s -f "$AUTH_SERVER/health" > /dev/null; then
echo "❌ Auth server failed to start at $AUTH_SERVER"
kill $AUTH_PID 2>/dev/null || true
exit 1
fi
echo "✅ Auth server is running (PID: $AUTH_PID)"
# Start MCP server with OAuth delegation..."
echo "Starting MCP server..."
(cd mcp-server && npm start) &
MCP_PID=$!
sleep 5
# Check MCP server
if ! curl -s -f "$MCP_SERVER/" > /dev/null; then
echo "❌ MCP server failed to start at $MCP_SERVER"
kill $AUTH_PID 2>/dev/null || true
kill $MCP_PID 2>/dev/null || true
exit 1
fi
echo "✅ MCP server is running (PID: $MCP_PID)"
# Clean up on exit
trap "kill $MCP_PID 2>/dev/null || true" EXIT
trap "kill $AUTH_PID $MCP_PID 2>/dev/null || true" EXIT
echo "🔐 PHASE 1: OAuth Authentication"
echo "================================"
echo ""
echo "🔐 PHASE 1: OAuth Authentication (with Auth Server)"
echo "================================================="
# OAuth Step 1: Client Registration
# Register a new OAuth client application with the authorization server
# This would typically be done once during app setup, not for each user
CLIENT_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" -d '{"client_name":"e2e-fixed","redirect_uris":["http://localhost:3000/callback"]}' "$MCP_SERVER/register")
echo "📝 Step 1: Register OAuth client with auth server"
CLIENT_RESPONSE=$(curl -s -X POST -H "Content-Type: application/json" \
-d "{\"client_name\":\"e2e-test-client\",\"redirect_uris\":[\"http://localhost:3000/callback\"]}" \
"$AUTH_SERVER/register")
CLIENT_ID=$(echo "$CLIENT_RESPONSE" | jq -r .client_id)
CLIENT_SECRET=$(echo "$CLIENT_RESPONSE" | jq -r .client_secret)
echo " Client ID: $CLIENT_ID"
# OAuth Step 2: Generate PKCE (Proof Key for Code Exchange) parameters
# PKCE adds security to the OAuth flow by preventing authorization code interception attacks
echo ""
echo "🔐 Step 2: Generate PKCE challenge"
CODE_VERIFIER=$(openssl rand -base64 32 | tr -d "=+/" | cut -c1-43)
CODE_CHALLENGE=$(echo -n "$CODE_VERIFIER" | openssl dgst -binary -sha256 | base64 | tr "+/" "-_" | tr -d "=")
echo " Code verifier generated"
# OAuth Step 3: Authorization Request
# Direct the user to the authorization server's /authorize endpoint
# Include state parameter for CSRF protection
STATE_PARAM="e2e-state-$(date +%s)"
echo ""
echo "🎫 Step 3: Get authorization code from auth server"
STATE_PARAM="e2e-test-$(date +%s)"
AUTH_URL="$AUTH_SERVER/authorize?response_type=code&client_id=$CLIENT_ID&redirect_uri=http://localhost:3000/callback&code_challenge=$CODE_CHALLENGE&code_challenge_method=S256&state=$STATE_PARAM"
AUTH_PAGE=$(curl -s "$MCP_SERVER/authorize?response_type=code&client_id=$CLIENT_ID&redirect_uri=http://localhost:3000/callback&code_challenge=$CODE_CHALLENGE&code_challenge_method=S256&state=$STATE_PARAM")
AUTH_PAGE=$(curl -s "$AUTH_URL")
# Extract the authorization code from the HTML response (normally would be in redirect URL)
AUTH_CODE=$(echo "$AUTH_PAGE" | grep -o 'state=[^"&]*' | cut -d= -f2)
AUTH_CODE=$(echo "$AUTH_PAGE" | grep -o 'state=[^"&]*' | cut -d= -f2 | head -1)
if [ -z "$AUTH_CODE" ]; then
echo " ❌ Failed to extract authorization code from auth server"
exit 1
fi
echo " Auth Code: ${AUTH_CODE:0:20}..."
# OAuth Step 4: User Authentication & Authorization
# In a real flow, the user would authenticate with the auth server here
# For testing, we simulate this with the fake upstream auth endpoint
CALLBACK_RESPONSE=$(curl -s -i "$MCP_SERVER/mock-upstream-idp/callback?state=$AUTH_CODE&code=mock-auth-code&userId=$USER_ID")
echo ""
echo "🔄 Step 4: Complete fake upstream auth with auth server"
CALLBACK_URL="$AUTH_SERVER/mock-upstream-idp/callback?state=$AUTH_CODE&code=mock-auth-code&userId=$USER_ID"
CALLBACK_RESPONSE=$(curl -s -i "$CALLBACK_URL")
# OAuth Step 5: Authorization Code Redirect
# Verify the auth server redirects back to our redirect_uri with the code and state
# The state parameter MUST match what we sent to prevent CSRF attacks
LOCATION_HEADER=$(echo "$CALLBACK_RESPONSE" | grep -i "^location:" | tr -d '\r')
if echo "$LOCATION_HEADER" | grep -q "state=$STATE_PARAM"; then
echo "✅ State parameter verified in callback"
echo " ✅ State parameter verified in callback"
else
echo "❌ State parameter mismatch or missing in callback"
echo " ❌ State parameter mismatch or missing in callback"
echo " Expected state: $STATE_PARAM"
echo " Location header: $LOCATION_HEADER"
exit 1
fi
echo " Fake upstream auth completed"
# OAuth Step 6: Token Exchange
# Exchange the authorization code for access and refresh tokens
# Include the PKCE code_verifier to prove we initiated the flow
TOKEN_RESPONSE=$(curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=authorization_code&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&code=$AUTH_CODE&redirect_uri=http://localhost:3000/callback&code_verifier=$CODE_VERIFIER" "$MCP_SERVER/token")
echo ""
echo "🎟️ Step 5: Exchange code for access token with auth server"
TOKEN_RESPONSE=$(curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&code=$AUTH_CODE&redirect_uri=http://localhost:3000/callback&code_verifier=$CODE_VERIFIER" \
"$AUTH_SERVER/token")
ACCESS_TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r .access_token)
echo "✅ OAuth complete, token: ${ACCESS_TOKEN:0:15}..."
if [ "$ACCESS_TOKEN" = "null" ] || [ -z "$ACCESS_TOKEN" ]; then
echo " ❌ Token exchange failed"
echo "Response: $TOKEN_RESPONSE"
exit 1
fi
echo " ✅ Access token from auth server: ${ACCESS_TOKEN:0:20}..."
echo ""
echo "🧪 PHASE 2: MCP Feature Testing"
echo "==============================="
echo "🧪 PHASE 2: MCP Feature Testing (with MCP Server)"
echo "=============================================="
# Step 1: Initialize MCP session (no session ID header)
# Step 1: Initialize MCP session with MCP SERVER using auth server token
echo ""
echo "📱 Step 1: Initialize MCP session"
echo "📱 Step 1: Initialize MCP session with MCP server"
INIT_RESPONSE=$(curl -i -s -H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Accept: application/json, text/event-stream" \
-X POST -H "Content-Type: application/json" \
@ -123,17 +166,17 @@ INIT_RESPONSE=$(curl -i -s -H "Authorization: Bearer $ACCESS_TOKEN" \
SESSION_ID=$(echo "$INIT_RESPONSE" | grep -i "mcp-session-id:" | cut -d' ' -f2 | tr -d '\r')
if [ -n "$SESSION_ID" ]; then
echo " ✅ Session initialized: $SESSION_ID"
echo " ✅ MCP session initialized: $SESSION_ID"
echo " ✅ Auth server token accepted by MCP server!"
else
echo " ❌ No session ID in response headers"
echo "Headers:"
echo "$INIT_RESPONSE" | head -20
echo " ❌ MCP session initialization failed"
echo "$INIT_RESPONSE"
exit 1
fi
# Step 2: Test tools with session ID
# Step 2: Test tools with MCP SERVER
echo ""
echo "🔧 Step 2: Test Tools"
echo "🔧 Step 2: Test Tools with MCP server"
TOOLS_RESPONSE=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Accept: application/json, text/event-stream" \
-H "Mcp-Session-Id: $SESSION_ID" \
@ -163,9 +206,9 @@ else
echo " ❌ Tools test failed: $TOOLS_RESPONSE"
fi
# Step 3: Test resources
# Step 3: Test resources with MCP SERVER (with pagination)
echo ""
echo "📚 Step 3: Test Resources (counting all pages)"
echo "📚 Step 3: Test Resources with MCP server (counting all pages)"
TOTAL_RESOURCES=0
CURSOR=""
PAGE=1
@ -206,9 +249,9 @@ done
RESOURCE_COUNT=$TOTAL_RESOURCES
echo " 📊 Total Resources: $RESOURCE_COUNT (README claims: 100)"
# Step 4: Test prompts
# Step 4: Test prompts with MCP SERVER
echo ""
echo "💭 Step 4: Test Prompts"
echo "💭 Step 4: Test Prompts with MCP server"
PROMPTS_RESPONSE=$(curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Accept: application/json, text/event-stream" \
-H "Mcp-Session-Id: $SESSION_ID" \
@ -225,17 +268,25 @@ else
fi
echo ""
echo "EMBEDDED OAUTH E2E TEST COMPLETE!"
echo "====================================="
echo "E2E TEST COMPLETE!"
echo "==================="
echo "✅ OAuth flow: Auth server → MCP server delegation working"
echo "✅ Token validation: MCP server accepts auth server tokens"
echo "✅ Session management: MCP server creates sessions with tokens"
echo ""
echo "📊 Verification Results:"
echo " Tools: $TOOL_COUNT (README: 7) $([ "$TOOL_COUNT" = "7" ] && echo "✅" || echo "❌")"
echo " Resources: $RESOURCE_COUNT (README: 100) $([ "$RESOURCE_COUNT" = "100" ] && echo "✅" || echo "❌")"
echo " Prompts: $PROMPT_COUNT"
echo " OAuth flow: ✅ Working"
echo " MCP features: ✅ Working"
echo ""
echo "🏗️ Architecture Verified:"
echo " ✅ Auth server provides OAuth endpoints"
echo " ✅ MCP server validates tokens via introspection"
echo " ✅ Session ownership works across server boundaries"
# Kill the server explicitly (trap might not catch npm's child process)
kill $MCP_PID 2>/dev/null || true
# Kill servers explicitly (trap might not catch npm's child processes)
kill $AUTH_PID $MCP_PID 2>/dev/null || true
pkill -P $AUTH_PID 2>/dev/null || true
pkill -P $MCP_PID 2>/dev/null || true
pkill -f "node dist/index.js" 2>/dev/null || true
sleep 1