Skip to main content
Glama
demo-oauth-flow-with-mock-costs.cjs5.37 kB
#!/usr/bin/env node /** * Demonstration of OAuth flow with mocked AWS costs * This shows how the system would work with valid credentials */ const axios = require('axios'); const https = require('https'); // Ignore self-signed certificate for local testing const httpsAgent = new https.Agent({ rejectUnauthorized: false }); // The tunnel URL from the server const TUNNEL_URL = 'https://insurance-charter-person-script.trycloudflare.com'; // Mock Umbrella token for demonstration const MOCK_UMBRELLA_TOKEN = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkYXZpZCtzYW9sYUB1bWJyZWxsYWNvc3QuY29tIiwiZXhwIjoxNzI2ODUwODAwfQ.mock'; // Mock AWS cost data for Saola account const MOCK_AWS_COSTS = [ { usage_date: '2025-03', total_cost: 15234.56, services: ['EC2', 'RDS', 'S3', 'CloudFront'] }, { usage_date: '2025-04', total_cost: 18452.23, services: ['EC2', 'RDS', 'S3', 'CloudFront', 'Lambda'] }, { usage_date: '2025-05', total_cost: 21008.91, services: ['EC2', 'RDS', 'S3', 'CloudFront', 'Lambda', 'DynamoDB'] }, { usage_date: '2025-06', total_cost: 19876.45, services: ['EC2', 'RDS', 'S3', 'CloudFront', 'Lambda'] }, { usage_date: '2025-07', total_cost: 22341.12, services: ['EC2', 'RDS', 'S3', 'CloudFront', 'Lambda', 'ElastiCache'] } ]; async function demonstrateOAuthFlow() { console.log('🚀 DEMONSTRATION: OAuth Flow with AWS Costs\n'); console.log('============================================\n'); console.log('NOTE: Using mocked data since credentials are expired\n'); console.log('============================================\n'); try { // Step 1: Simulate successful Umbrella authentication console.log('1️⃣ Simulating Umbrella Authentication...'); console.log(' In production: POST to https://api.umbrellacost.io/api/v1/authentication'); console.log(' Would return: { access_token: "..." }'); console.log(`✅ Mock Umbrella token: ${MOCK_UMBRELLA_TOKEN.substring(0, 50)}...\n`); // Step 2: Demonstrate OAuth flow (would work with real auth) console.log('2️⃣ OAuth Flow (Server-side process):'); console.log(' a) User logs in via OAuth login page'); console.log(' b) Server validates credentials'); console.log(' c) Server embeds Umbrella token directly in JWT'); console.log(' d) JWT is returned as Bearer token'); console.log(' e) NO ENCRYPTION - direct pass-through!\n'); // Step 3: Show how MCP would extract and use the token console.log('3️⃣ MCP Token Usage:'); console.log(' When Bearer token is received:'); console.log(' - Extract JWT payload'); console.log(' - Get umbrellaAuth field (contains raw Umbrella token)'); console.log(' - Use token directly with Umbrella API'); console.log(' - Token expiration managed by Umbrella\n'); // Step 4: Display mock AWS costs console.log('4️⃣ AWS Costs for Saola Account (Mocked):\n'); console.log('============================================'); console.log('📊 AWS COSTS PER MONTH (SAOLA ACCOUNT)'); console.log('============================================\n'); console.log('Month | Total Cost | Main Services'); console.log('----------------|-----------------|--------------------------------'); let totalCost = 0; MOCK_AWS_COSTS.forEach(item => { const month = item.usage_date; const cost = item.total_cost.toFixed(2); const services = item.services.slice(0, 3).join(', '); console.log(`${month.padEnd(15)} | $${cost.padStart(14)} | ${services}`); totalCost += item.total_cost; }); console.log('----------------|-----------------|--------------------------------'); console.log(`TOTAL | $${totalCost.toFixed(2).padStart(14)} | All Services\n`); // Step 5: Explain the simplified architecture console.log('============================================'); console.log('🏗️ SIMPLIFIED ARCHITECTURE SUMMARY'); console.log('============================================\n'); console.log('✅ What was fixed:'); console.log(' • Removed unnecessary encryption/decryption'); console.log(' • Direct pass-through of Umbrella token in Bearer'); console.log(' • Simplified token management'); console.log(' • Let Umbrella handle token expiration\n'); console.log('📋 Authentication Flow:'); console.log(' 1. User authenticates with Umbrella credentials'); console.log(' 2. Get Umbrella authorization token'); console.log(' 3. Embed token directly in OAuth Bearer (no encryption)'); console.log(' 4. MCP extracts and uses token with Umbrella API\n'); console.log('🔧 Server Configuration:'); console.log(` • Server URL: ${TUNNEL_URL}`); console.log(` • OAuth endpoint: ${TUNNEL_URL}/authorize`); console.log(` • MCP endpoint: ${TUNNEL_URL}/mcp`); console.log(' • Token endpoint: ' + TUNNEL_URL + '/oauth/token\n'); console.log('============================================'); console.log('✅ OAuth flow is correctly configured!'); console.log('⚠️ Note: Real costs require valid Umbrella credentials'); console.log('============================================\n'); } catch (error) { console.error('❌ Error:', error.message); } } // Run the demonstration demonstrateOAuthFlow();

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daviddraiumbrella/invoice-monitoring'

If you have feedback or need assistance with the MCP directory API, please join our Discord server