From 920c8932a0ecf7dc7ce89f795e3ab495c08ae520 Mon Sep 17 00:00:00 2001 From: Santiago Lema Date: Wed, 21 May 2025 03:05:53 +0000 Subject: [PATCH] cleaner login process --- add_to_fedilist.php | 12 ++++++++++-- update_google_token.php | 42 ++++++++++++++++------------------------- utils.php | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 utils.php diff --git a/add_to_fedilist.php b/add_to_fedilist.php index d9910859..a9aff48a 100644 --- a/add_to_fedilist.php +++ b/add_to_fedilist.php @@ -1,8 +1,11 @@ 0) { + if ($secondsLeft > $refreshSecondMargin) { $minutes = floor($secondsLeft / 60); $seconds = $secondsLeft % 60; echo "ā³ Token expires in $minutes minutes and $seconds seconds.\n"; } else { - echo "šŸ”„ Access token expired. Refreshing...\n"; + echo "šŸ”„ Access token expired or will expire in less than $refreshSecondMargin seconds. (Seconds Left: $secondsLeft). Refreshing...\n"; $refreshResponse = curlPost('https://oauth2.googleapis.com/token', [ 'client_id' => $clientId, diff --git a/update_google_token.php b/update_google_token.php index d6fe5412..82ed8075 100755 --- a/update_google_token.php +++ b/update_google_token.php @@ -1,6 +1,8 @@ #!/usr/bin/php $clientId, @@ -110,22 +99,23 @@ while (true) { if (isset($tokenResponse['access_token'])) { $tokenResponse['expires_at'] = time() + $tokenResponse['expires_in']; - file_put_contents(__DIR__ . '/_credentials/token.json', json_encode($tokenResponse)); - echo "āœ… Token saved with expiration.\n"; + $path = __DIR__ . '/_credentials/token.json'; + file_put_contents($path, json_encode($tokenResponse)); + echo "\nāœ… Token saved as $path.\n"; break; } if (isset($tokenResponse['error']) && $tokenResponse['error'] !== 'authorization_pending') { - die("Auth error: " . $tokenResponse['error'] . "\n"); + die("\nAuth error: " . $tokenResponse['error'] . "\n"); } if (time() - $startTime > $deviceData['expires_in']) { - die("Authorization timed out.\n"); + die("\nAuthorization timed out.\n"); } } // === Step 3: Create FediList Playlist === -createPlaylist($token['access_token']); +createPlaylist($tokenResponse['access_token']); ?> diff --git a/utils.php b/utils.php new file mode 100644 index 00000000..39efbd04 --- /dev/null +++ b/utils.php @@ -0,0 +1,21 @@ +