Skip to content

Commit 28ae8d8

Browse files
committed
Add verbose debug logging for GarminConnect responses
Introduces a DEBUG_GARMIN_VERBOSE flag to enable detailed logging of HTTP responses and ticket extraction attempts in the GarminConnect authentication flow. This aids in troubleshooting login and MFA issues by providing more insight into response contents and extraction logic.
1 parent 753548c commit 28ae8d8

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

.claude/settings.local.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(git log:*)"
5+
]
6+
}
7+
}

src/garminconnect.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ bool GarminConnect::performLogin(const QString &email, const QString &password,
585585
responseUrl = reply->url();
586586
}
587587

588+
if (DEBUG_GARMIN_VERBOSE) {
589+
qDebug() << "GarminConnect: Response URL:" << responseUrl.toString();
590+
qDebug() << "GarminConnect: Response length:" << response.length();
591+
qDebug() << "GarminConnect: Full response body:" << response;
592+
}
593+
588594
QUrlQuery responseQuery(responseUrl);
589595
QString ticket = responseQuery.queryItemValue("ticket");
590596

@@ -602,6 +608,8 @@ bool GarminConnect::performLogin(const QString &email, const QString &password,
602608
if (match.hasMatch()) {
603609
ticket = match.captured(1);
604610
qDebug() << "GarminConnect: Found ticket with fallback pattern:" << ticket.left(20) << "...";
611+
} else if (DEBUG_GARMIN_VERBOSE) {
612+
qDebug() << "GarminConnect: No ticket patterns matched in response body";
605613
}
606614
}
607615
}
@@ -611,6 +619,9 @@ bool GarminConnect::performLogin(const QString &email, const QString &password,
611619
if (ticket.isEmpty()) {
612620
m_lastError = "Failed to extract ticket from login response";
613621
qDebug() << "GarminConnect:" << m_lastError;
622+
if (DEBUG_GARMIN_VERBOSE) {
623+
qDebug() << "GarminConnect: Response snippet:" << response.left(1000);
624+
}
614625
return false;
615626
}
616627

@@ -711,8 +722,12 @@ void GarminConnect::handleMfaReplyFinished()
711722
qDebug() << "GarminConnect: MFA response status code:" << statusCode;
712723
qDebug() << "GarminConnect: MFA response redirect URL:" << responseUrl.toString();
713724

714-
// If no redirect, log response body to understand what happened
715-
if (responseUrl.isEmpty()) {
725+
// Log detailed response information
726+
if (DEBUG_GARMIN_VERBOSE) {
727+
qDebug() << "GarminConnect: MFA response length:" << response.length();
728+
qDebug() << "GarminConnect: Full MFA response body:" << response;
729+
} else if (responseUrl.isEmpty()) {
730+
// If no redirect, log response body to understand what happened (non-verbose)
716731
qDebug() << "GarminConnect: MFA response body (first 500 chars):" << response.left(500);
717732
}
718733

@@ -751,6 +766,9 @@ void GarminConnect::handleMfaReplyFinished()
751766

752767
// If not found in redirect URL, try response body
753768
if (ticket.isEmpty() && !response.isEmpty()) {
769+
if (DEBUG_GARMIN_VERBOSE) {
770+
qDebug() << "GarminConnect: Attempting to extract ticket from MFA response body";
771+
}
754772
// Try multiple patterns for ticket extraction
755773
QRegularExpression ticketRegex1("embed\\?ticket=([^\"]+)\"");
756774
QRegularExpression ticketRegex2("ticket=([^&\"']+)");
@@ -764,6 +782,16 @@ void GarminConnect::handleMfaReplyFinished()
764782
if (match.hasMatch()) {
765783
ticket = match.captured(1);
766784
qDebug() << "GarminConnect: Found ticket in response body (pattern 2):" << ticket.left(20) << "...";
785+
} else if (DEBUG_GARMIN_VERBOSE) {
786+
qDebug() << "GarminConnect: No MFA ticket patterns matched. Checking for other patterns...";
787+
// Check for JSON format
788+
if (response.contains("ticket")) {
789+
qDebug() << "GarminConnect: Response contains 'ticket' keyword, may be JSON or different format";
790+
}
791+
// Check for common response patterns
792+
if (response.contains("\"")) {
793+
qDebug() << "GarminConnect: Response contains quoted strings (may be JSON)";
794+
}
767795
}
768796
}
769797
}
@@ -773,6 +801,9 @@ void GarminConnect::handleMfaReplyFinished()
773801
if (ticket.isEmpty()) {
774802
m_lastError = "Failed to extract ticket after MFA";
775803
qDebug() << "GarminConnect:" << m_lastError;
804+
if (DEBUG_GARMIN_VERBOSE) {
805+
qDebug() << "GarminConnect: Response snippet:" << response.left(1000);
806+
}
776807
emit authenticationFailed(m_lastError);
777808
return;
778809
}

src/garminconnect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class GarminConnect : public QObject
176176
static constexpr const char* SSO_URL_PATH = "/sso/signin";
177177
static constexpr const char* SSO_EMBED_PATH = "/sso/embed";
178178
static constexpr const char* OAUTH_CONSUMER_URL = "https://thegarth.s3.amazonaws.com/oauth_consumer.json";
179+
static constexpr bool DEBUG_GARMIN_VERBOSE = true; // Set to true for detailed response logging (may contain sensitive data)
179180

180181
// Private methods
181182
QString ssoUrl() const { return QString("https://sso.%1").arg(m_domain); }

0 commit comments

Comments
 (0)