#!/usr/bin/env node
/**
* Test authentication directly against Umbrella API
* This will help identify why credentials are failing
*/
const axios = require('axios');
async function testDirectAuth(username, password) {
console.log('\n🔐 Testing Direct Umbrella Authentication');
console.log('=' .repeat(60));
console.log(`Username: ${username}`);
console.log(`Password: ${'*'.repeat(password.length)}`);
console.log('=' .repeat(60));
// Test 1: Try the working auth endpoint from stdio server
console.log('\n1️⃣ Testing Cognito endpoint (used by stdio server):');
try {
const response = await axios.post(
'https://api.umbrellacost.io/api/v1/authenticate',
{ username, password },
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}
);
console.log('✅ SUCCESS - Authentication worked!');
console.log('Response headers:', {
Authorization: response.headers.authorization ? 'Present' : 'Missing',
apikey: response.headers.apikey ? 'Present' : 'Missing',
});
return true;
} catch (error) {
console.log('❌ FAILED:', error.response?.status, error.response?.statusText);
if (error.response?.data) {
console.log('Error details:', JSON.stringify(error.response.data, null, 2));
}
}
// Test 2: Try Keycloak endpoint
console.log('\n2️⃣ Testing Keycloak endpoint:');
try {
const response = await axios.post(
'https://api.umbrellacost.io/api/v1/authentication/token/generate',
{ username, password },
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
}
);
console.log('✅ SUCCESS - Keycloak auth worked!');
console.log('Response:', {
token: response.data?.token ? 'Present' : 'Missing',
apiKey: response.data?.apiKey ? 'Present' : 'Missing',
});
return true;
} catch (error) {
console.log('❌ FAILED:', error.response?.status, error.response?.statusText);
if (error.response?.data) {
console.log('Error details:', JSON.stringify(error.response.data, null, 2));
}
}
// Test 3: Try user detection endpoint
console.log('\n3️⃣ Testing user detection endpoint:');
try {
const response = await axios.get(
`https://api.umbrellacost.io/api/v1/authentication/users/lookup/${encodeURIComponent(username)}`,
{
headers: {
'Accept': 'application/json'
}
}
);
console.log('✅ User lookup successful:');
console.log('Response:', JSON.stringify(response.data, null, 2));
} catch (error) {
console.log('❌ User lookup failed:', error.response?.status);
}
return false;
}
// Main execution
async function main() {
// Get credentials from command line or use test credentials
const username = process.argv[2] || 'david+saola@umbrellacost.com';
const password = process.argv[3] || process.env.UMBRELLA_PASSWORD;
if (!password) {
console.error('❌ Please provide password as second argument or set UMBRELLA_PASSWORD env var');
console.log('Usage: node test-auth-direct.cjs <username> <password>');
process.exit(1);
}
const success = await testDirectAuth(username, password);
console.log('\n' + '=' .repeat(60));
if (success) {
console.log('✅ Authentication successful! Credentials are correct.');
console.log('The issue is in the OAuth server authentication module.');
} else {
console.log('❌ Authentication failed with all methods.');
console.log('Please verify your credentials are correct.');
}
}
main().catch(err => {
console.error('Unexpected error:', err);
process.exit(1);
});