fetchNewAccessToken(); }); } private function fetchNewAccessToken(): string { try { // Log the config values to debug Log::info('IGDB Auth Attempt', [ 'client_id' => config('services.igdb.credentials.client_id'), 'client_secret' => config('services.igdb.credentials.client_secret') ]); $clientId = config('igdb.credentials.client_id'); $clientSecret = config('igdb.credentials.client_secret'); if (empty($clientId) || empty($clientSecret)) { throw new \Exception("IGDB credentials are not properly configured"); } $response = Http::asForm()->post('https://id.twitch.tv/oauth2/token', [ 'client_id' => $clientId, 'client_secret' => $clientSecret, 'grant_type' => 'client_credentials', ]); if (!$response->successful()) { Log::error('IGDB Auth Response', [ 'status' => $response->status(), 'body' => $response->body() ]); throw new \Exception("Failed to get access token: " . $response->body()); } $data = $response->json(); return $data['access_token']; } catch (\Exception $e) { Log::error('Failed to fetch IGDB access token', [ 'error' => $e->getMessage() ]); throw $e; } } }