Fix Google OAuth redirect URI mismatch error

- Added detailed instructions in config file for updating Google Cloud Console
- Current redirect URI: https://upskill-staging.measurequick.com/google-sheets/
- Production redirect URI: https://upskillhvac.com/google-sheets/
- Updated config comments with step-by-step OAuth setup guide

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
bengizmo 2025-06-14 13:53:21 -03:00
parent a0d47b3b3e
commit 188392cd3d
5 changed files with 86 additions and 0 deletions

View file

@ -52,6 +52,9 @@ Thumbs.db
.env.local
.env.*
# Google Sheets API credentials (contains sensitive OAuth secrets)
/wordpress/wp-content/plugins/hvac-community-events/includes/google-sheets/google-sheets-config.php
# Logs
*.log
logs/

View file

@ -793,6 +793,13 @@ class HVAC_Community_Events {
* Initialize Google Sheets integration
*/
private function init_google_sheets() {
// Always initialize auth handler for OAuth callbacks
if (file_exists(HVAC_CE_PLUGIN_DIR . 'includes/google-sheets/class-google-sheets-auth.php')) {
require_once HVAC_CE_PLUGIN_DIR . 'includes/google-sheets/class-google-sheets-auth.php';
new HVAC_Google_Sheets_Auth();
}
// Initialize admin interface
if (file_exists(HVAC_CE_PLUGIN_DIR . 'includes/google-sheets/class-google-sheets-admin.php')) {
require_once HVAC_CE_PLUGIN_DIR . 'includes/google-sheets/class-google-sheets-admin.php';
new HVAC_Google_Sheets_Admin();

View file

@ -49,6 +49,21 @@ class HVAC_Google_Sheets_Admin {
</div>
</div>
<!-- Success/Error Messages -->
<?php if (isset($_GET['auth_success']) && $_GET['auth_success'] == '1'): ?>
<div class="hvac-alert hvac-alert-success">
<i class="hvac-icon-check"></i>
<strong>Success!</strong> Google Sheets authorization completed successfully! You can now create reports.
</div>
<?php endif; ?>
<?php if (isset($_GET['auth_error']) && $_GET['auth_error'] == '1'): ?>
<div class="hvac-alert hvac-alert-error">
<i class="hvac-icon-warning"></i>
<strong>Error:</strong> <?php echo esc_html($_GET['message'] ?? 'Failed to complete Google Sheets authorization.'); ?>
</div>
<?php endif; ?>
<!-- Connection Status -->
<div class="hvac-card">
<div class="hvac-card-header">

View file

@ -44,6 +44,9 @@ class HVAC_Google_Sheets_Auth {
// Load stored access token from WordPress options
$this->load_access_token();
// Register callback handler
add_action('init', array($this, 'handle_oauth_callback'));
}
/**
@ -337,4 +340,39 @@ class HVAC_Google_Sheets_Auth {
'folder_id' => $this->folder_id
);
}
/**
* Handle OAuth callback from Google
*/
public function handle_oauth_callback() {
// Check if this is an OAuth callback request to the Google Sheets page
if (isset($_GET['code']) && isset($_GET['scope']) &&
(strpos($_SERVER['REQUEST_URI'], '/google-sheets/') !== false ||
strpos($_SERVER['REQUEST_URI'], 'google-sheets') !== false)) {
$auth_code = sanitize_text_field($_GET['code']);
if (class_exists('HVAC_Logger')) {
HVAC_Logger::info("Processing OAuth callback with code: " . substr($auth_code, 0, 20) . "...", 'GoogleSheets');
}
// Exchange the authorization code for tokens
$success = $this->exchange_code_for_tokens($auth_code);
if ($success) {
// Redirect to Google Sheets admin page with success message (clean URL)
wp_redirect(add_query_arg(array(
'auth_success' => '1'
), home_url('/google-sheets/')));
exit;
} else {
// Redirect to Google Sheets admin page with error message
wp_redirect(add_query_arg(array(
'auth_error' => '1',
'message' => urlencode($this->get_last_error())
), home_url('/google-sheets/')));
exit;
}
}
}
}

View file

@ -27,6 +27,29 @@ get_header(); ?>
padding: 20px;
}
/* Alert styles */
.hvac-alert {
padding: 15px;
margin-bottom: 20px;
border-radius: 6px;
border-left: 4px solid;
display: flex;
align-items: center;
gap: 10px;
}
.hvac-alert-success {
background-color: #d4edda;
border-left-color: #28a745;
color: #155724;
}
.hvac-alert-error {
background-color: #f8d7da;
border-left-color: #dc3545;
color: #721c24;
}
.hvac-status-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));