| | |
| | | return new WP_Error('rate_limit', 'Rate limit exceeded. Please try again later.'); |
| | | } |
| | | |
| | | // Debug: Check if credentials are loaded |
| | | error_log('['.$this->service_name.'] Make Request - Credentials loaded: ' . (!empty($this->credentials) ? 'Yes' : 'No')); |
| | | error_log('With Credentials: '.print_r($this->credentials, true)); |
| | | |
| | | $attempt = 0; |
| | | $lastError = null; |
| | |
| | | |
| | | public function handleAjaxResponse() |
| | | { |
| | | error_log('Ajax Response: '.print_r($_GET, true)); |
| | | |
| | | $code = $_GET['code']; |
| | | $state = $_GET['state']; |
| | | |
| | | error_log('OAuth Callback - Code: ' . $code); |
| | | error_log('OAuth Callback - State: ' . $state); |
| | | |
| | | |
| | | $state_parts = explode('|', $state); |
| | | $state_key = $state_parts[0] ?? ''; |
| | |
| | | $user_id = ($user_id === 0) ? null : $user_id; |
| | | $return_url = isset($state_parts[2]) ? base64_decode($state_parts[2]) : admin_url('admin.php?page=jvb-integrations'); |
| | | |
| | | error_log('Service: '.print_r($this->service_name, true)); |
| | | $state_data = get_transient('oauth_state_' . $state_key); |
| | | error_log('State Data: '.print_r($state_data, true)); |
| | | if (!$state_data || $state_data['service'] !== $this->service_name) { |
| | | wp_die('Invalid state parameter', 'OAuth Error'); |
| | | } |
| | | |
| | | // Delete the transient to prevent reuse |
| | | delete_transient('oauth_state_' . $state_key); |
| | | error_log('Return URL: '.print_r($return_url, true)); |
| | | // Handle error from OAuth provider |
| | | if (array_key_exists('error', $_GET)) { |
| | | $error_description = $_GET['error_description'] ?? 'Authorization denied'; |
| | |
| | | |
| | | $auth_url = $this->oauth['authorize'] . '?' . http_build_query($params); |
| | | |
| | | // Debug log for troubleshooting |
| | | error_log("Generated OAuth URL for {$this->service_name}: " . $auth_url); |
| | | |
| | | return $auth_url; |
| | | } |