@@ -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 }
0 commit comments