Add detailed logging for Subsonic authentication debugging

This commit is contained in:
2025-12-07 22:49:13 +00:00
parent 9b782c357d
commit 7f31e49e56
190 changed files with 13 additions and 2 deletions

View File

@@ -14,14 +14,18 @@ const USERS = {
// Middleware to handle Subsonic authentication
function authenticateSubsonic(req, res, next) {
const { u: username, p: password, t: token, s: salt } = req.query;
const { u: username, p: password, t: token, s: salt, c: client } = req.query;
console.log(`🔐 Subsonic auth attempt - User: ${username}, Client: ${client || 'unknown'}`);
if (!username) {
console.log('❌ Auth failed: No username provided');
return sendSubsonicError(res, 10, 'Required parameter is missing');
}
const user = USERS[username];
if (!user) {
console.log(`❌ Auth failed: User '${username}' not found`);
return sendSubsonicError(res, 40, 'Wrong username or password');
}
@@ -32,18 +36,24 @@ function authenticateSubsonic(req, res, next) {
// Token-based auth: token = md5(password + salt)
const expectedToken = crypto.createHash('md5').update(user.password + salt).digest('hex');
authenticated = token === expectedToken;
console.log(`🔑 Token auth: ${authenticated ? 'SUCCESS' : 'FAILED'}`);
} else if (password) {
// Plain password or enc: prefix
const plainPassword = password.startsWith('enc:')
? Buffer.from(password.slice(4), 'hex').toString()
: password;
authenticated = plainPassword === user.password;
console.log(`🔑 Password auth: ${authenticated ? 'SUCCESS' : 'FAILED'}`);
} else {
console.log('❌ Auth failed: No password or token provided');
}
if (!authenticated) {
console.log('❌ Authentication failed');
return sendSubsonicError(res, 40, 'Wrong username or password');
}
console.log('✅ Authentication successful');
req.subsonicUser = username;
next();
}
@@ -66,8 +76,9 @@ function sendSubsonicError(res, code, message) {
res.type('application/xml').send(xml);
}
// Ping - test connectivity
// Ping - test connectivity (no auth required for testing)
router.get('/ping.view', (req, res) => {
console.log('📡 Ping received');
sendSubsonicResponse(res, '');
});