Skip to main content
Glama
compare-bearer-tokens.cjs5.4 kB
#!/usr/bin/env node // Direct comparison of Bearer tokens between working server and OAuth service const axios = require('axios'); async function compareBearerTokens() { console.log('🔍 Comparing Bearer Tokens: Working Server vs OAuth Service'); console.log('═'.repeat(70)); try { // Get Bearer token from working server console.log('\n1️⃣ Getting Bearer token from working server...'); const workingAuth = await axios.post('http://localhost:3000/auth', { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' }); const workingToken = workingAuth.data.bearerToken; const workingApiKey = workingAuth.data.apiKey; console.log(`✅ Working server token: ${workingToken.substring(0, 50)}...`); console.log(`✅ Working server API key: ${workingApiKey}`); // Get Bearer token from OAuth service console.log('\n2️⃣ Getting Bearer token from OAuth service...'); const sessionResponse = await axios.post('http://localhost:8080/api/session/create'); const sessionId = sessionResponse.data.sessionId; await axios.post('http://localhost:8080/oauth/callback', { sessionId: sessionId, username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' }); const oauthSession = await axios.get(`http://localhost:8080/api/session/${sessionId}`); const oauthToken = oauthSession.data.bearerToken; const oauthApiKey = oauthSession.data.apiKey; console.log(`✅ OAuth service token: ${oauthToken.substring(0, 50)}...`); console.log(`✅ OAuth service API key: ${oauthApiKey}`); // Compare token formats console.log('\n3️⃣ Comparing token formats...'); console.log(`Working token starts with: ${workingToken.substring(0, 20)}`); console.log(`OAuth token starts with: ${oauthToken.substring(0, 20)}`); console.log(`Tokens identical: ${workingToken === oauthToken}`); console.log(`API keys identical: ${workingApiKey === oauthApiKey}`); // Make direct API call with both tokens console.log('\n4️⃣ Making direct API calls to /invoices/caui...'); const apiParams = { accountId: '932213950603', startDate: '2025-08-01', endDate: '2025-08-31', groupBy: 'none', periodGranLevel: 'month', costType: ['cost', 'discount'], isUnblended: true }; console.log('Parameters:', JSON.stringify(apiParams, null, 2)); // Test working server token console.log('\n🔹 Testing with working server token...'); try { const workingResult = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', { headers: { 'Authorization': workingToken, 'apikey': workingApiKey, 'Content-Type': 'application/json' }, params: apiParams }); console.log(`✅ Working token result: ${JSON.stringify(workingResult.data).substring(0, 200)}...`); // Parse total cost let workingTotal = 0; if (workingResult.data.rows) { workingResult.data.rows.forEach(row => { if (row.cost) workingTotal += row.cost; }); } console.log(`💰 Working server total: $${workingTotal.toLocaleString()}`); } catch (error) { console.log(`❌ Working token failed: ${error.response?.status} ${error.response?.data?.message || error.message}`); } // Test OAuth token console.log('\n🔹 Testing with OAuth token...'); try { const oauthResult = await axios.get('https://api.umbrellacost.io/api/v1/invoices/caui', { headers: { 'Authorization': oauthToken, 'apikey': oauthApiKey, 'Content-Type': 'application/json' }, params: apiParams }); console.log(`✅ OAuth token result: ${JSON.stringify(oauthResult.data).substring(0, 200)}...`); // Parse total cost let oauthTotal = 0; if (oauthResult.data.rows) { oauthResult.data.rows.forEach(row => { if (row.cost) oauthTotal += row.cost; }); } console.log(`💰 OAuth service total: $${oauthTotal.toLocaleString()}`); // Compare results if (oauthTotal === 0 && workingTotal > 0) { console.log('\n❌ ISSUE FOUND: OAuth token returns $0 while working token returns data!'); console.log(' This indicates an authentication or token issue in the OAuth service.'); } else if (oauthTotal === workingTotal) { console.log('\n✅ SUCCESS: Both tokens return identical results!'); console.log(' The issue must be elsewhere (parameter handling, etc.)'); } else { console.log(`\n⚠️ PARTIAL: Different amounts - Working: $${workingTotal}, OAuth: $${oauthTotal}`); } } catch (error) { console.log(`❌ OAuth token failed: ${error.response?.status} ${error.response?.data?.message || error.message}`); if (error.response?.status === 401) { console.log(' 🔍 This is likely the root cause - invalid OAuth token!'); } } } catch (error) { console.error('❌ Comparison failed:', error.message); if (error.response && error.response.data) { console.error('Response data:', JSON.stringify(error.response.data, null, 2)); } } } compareBearerTokens().catch(console.error);

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