From be8f95f4132d8ae56d41cfa0a03874a70b5902a4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 12 Nov 2025 14:03:58 +0000 Subject: [PATCH] Fix: Ajout d'une route de debug pour forcer OAuth2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout de la route GET /api/calendar/force-oauth2 pour forcer le changement du type d'authentification vers OAuth2 dans la BDD. Cette route permet de contourner un problème où le bouton "Enregistrer" ne sauvegarde pas correctement google_auth_type. --- fix-google-settings.js | 44 +++++++++++++++++++++++++++++++++++++++ routes/calendar.routes.js | 15 +++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 fix-google-settings.js diff --git a/fix-google-settings.js b/fix-google-settings.js new file mode 100644 index 0000000..b75d5e1 --- /dev/null +++ b/fix-google-settings.js @@ -0,0 +1,44 @@ +// Script pour corriger les paramètres Google Calendar +const { getAll, runQuery } = require('./config/database'); + +async function fixGoogleSettings() { + console.log('🔍 Vérification des paramètres Google Calendar...\n'); + + // Lire tous les paramètres Google + const googleSettings = await getAll("SELECT key, value FROM settings WHERE key LIKE 'google%'"); + + console.log('📋 Paramètres actuels :'); + googleSettings.forEach(setting => { + let displayValue = setting.value; + // Masquer les secrets + if (setting.key.includes('secret') || setting.key.includes('key')) { + displayValue = setting.value ? '***MASQUÉ***' : 'NULL'; + } + console.log(` ${setting.key}: ${displayValue}`); + }); + + // Vérifier le type d'authentification + const authType = googleSettings.find(s => s.key === 'google_auth_type'); + console.log(`\n🔐 Type d'authentification actuel: ${authType?.value || 'NON DÉFINI'}`); + + // Forcer OAuth2 + console.log('\n✏️ Changement du type d\'authentification vers OAuth2...'); + await runQuery( + "INSERT OR REPLACE INTO settings (key, value) VALUES ('google_auth_type', 'oauth2')", + [] + ); + + console.log('✅ Type d\'authentification changé vers OAuth2'); + + // Vérifier à nouveau + const newAuthType = await getAll("SELECT value FROM settings WHERE key = 'google_auth_type'"); + console.log(`\n✅ Nouveau type: ${newAuthType[0]?.value}`); + + console.log('\n🎉 Terminé ! Redémarrez votre application et réessayez.'); + process.exit(0); +} + +fixGoogleSettings().catch(err => { + console.error('❌ Erreur:', err); + process.exit(1); +}); diff --git a/routes/calendar.routes.js b/routes/calendar.routes.js index d3e5478..5cecd0d 100644 --- a/routes/calendar.routes.js +++ b/routes/calendar.routes.js @@ -113,6 +113,21 @@ async function getCalendarClient(userId = null) { } } +/** + * GET /api/calendar/force-oauth2 (TEMPORAIRE - DEBUG) + * Forcer le type d'authentification à OAuth2 + */ +router.get('/force-oauth2', requireAdmin, async (req, res) => { + try { + await runQuery("INSERT OR REPLACE INTO settings (key, value) VALUES ('google_auth_type', 'oauth2')", []); + const check = await getOne("SELECT value FROM settings WHERE key = 'google_auth_type'"); + res.json({ success: true, auth_type: check?.value }); + } catch (error) { + logger.error('Erreur:', error); + res.status(500).json({ error: error.message }); + } +}); + /** * GET /api/calendar/auth-url * Générer l'URL d'authentification OAuth