Skip to main content
Glama
by mohalmah
test-token-management.jsโ€ข4.06 kB
#!/usr/bin/env node /** * Test OAuth Token Management System * This script tests the secure token storage and refresh functionality */ import 'dotenv/config'; import { TokenManager } from './lib/tokenManager.js'; import { getOAuthAccessToken, hasValidTokens, getTokenInfo } from './lib/oauth-helper.js'; console.log('๐Ÿงช Testing OAuth Token Management System'); console.log('=========================================\n'); async function testTokenManagement() { try { console.log('1. ๐Ÿ” Checking environment variables...'); const clientId = process.env.GOOGLE_APP_SCRIPT_API_CLIENT_ID; const clientSecret = process.env.GOOGLE_APP_SCRIPT_API_CLIENT_SECRET; console.log(' - CLIENT_ID exists:', !!clientId); console.log(' - CLIENT_SECRET exists:', !!clientSecret); if (!clientId || !clientSecret) { console.error('\nโŒ Missing OAuth credentials in .env file'); console.log('๐Ÿ’ก Please update your .env file with:'); console.log(' - GOOGLE_APP_SCRIPT_API_CLIENT_ID=your_client_id'); console.log(' - GOOGLE_APP_SCRIPT_API_CLIENT_SECRET=your_client_secret'); process.exit(1); } console.log('\n2. ๐Ÿ“ Checking token storage...'); const tokenManager = new TokenManager(); const tokenInfo = tokenManager.getTokenInfo(); if (tokenInfo.hasTokens) { console.log(' โœ… Tokens found'); console.log(` ๐Ÿ“ Location: ${tokenInfo.location}`); console.log(` ๐Ÿ’พ Saved at: ${tokenInfo.savedAt}`); console.log(` โฐ Expires at: ${tokenInfo.expiresAt}`); console.log(` ๐Ÿ“Š Status: ${tokenInfo.status}`); console.log(` ๐Ÿ” Scope: ${tokenInfo.scope || 'Not specified'}`); } else { console.log(' โŒ No tokens found'); console.log(` ๐Ÿ“ Expected location: ${tokenInfo.location}`); console.log('\n๐Ÿ’ก Run "node oauth-setup.js" to set up OAuth tokens'); process.exit(0); } console.log('\n3. ๐Ÿ” Testing token validity...'); const hasTokens = hasValidTokens(); console.log(' - Has valid tokens:', hasTokens); if (hasTokens) { console.log('\n4. ๐Ÿ”„ Testing access token retrieval...'); try { const accessToken = await getOAuthAccessToken(); console.log(' โœ… Access token obtained successfully'); console.log(' ๐Ÿ”‘ Token preview:', accessToken.substring(0, 20) + '...'); console.log('\n5. โœ… All tests passed!'); console.log(' ๐ŸŽฏ Your OAuth token management is working correctly'); } catch (error) { console.error('\nโŒ Failed to get access token:', error.message); if (error.message.includes('Token refresh failed')) { console.log('\n๐Ÿ’ก This might happen if:'); console.log(' - Your OAuth credentials have been revoked'); console.log(' - Your client secret has changed'); console.log(' - There are network connectivity issues'); console.log('\n๐Ÿ”ง Try running: node oauth-setup.js --force'); } } } else { console.log('\nโŒ No valid tokens available'); console.log('๐Ÿ’ก Run "node oauth-setup.js" to set up OAuth tokens'); } } catch (error) { console.error('\n๐Ÿ’ฅ Test failed with error:', error.message); process.exit(1); } } // Command line help if (process.argv.includes('--help') || process.argv.includes('-h')) { console.log('๐Ÿ“– OAuth Token Management Test'); console.log('\nUsage:'); console.log(' node test-token-management.js # Run all tests'); console.log(' node test-token-management.js --help # Show this help'); console.log('\nThis script tests:'); console.log(' - Environment variable configuration'); console.log(' - Token storage and retrieval'); console.log(' - Access token refresh functionality'); console.log(' - Overall OAuth system health'); process.exit(0); } testTokenManagement().catch((error) => { console.error('๐Ÿ’ฅ Unexpected error:', error); process.exit(1); });

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/mohalmah/google-appscript-mcp-server'

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