From 4d2ed3d5d80e3836e2757642dc493a4ae5ee1126 Mon Sep 17 00:00:00 2001 From: Manus Sandbox Date: Wed, 19 Nov 2025 08:24:59 -0500 Subject: [PATCH] =?UTF-8?q?Checkpoint:=20Correction=20de=20la=20redirectio?= =?UTF-8?q?n=20OAuth=20pour=20revenir=20=C3=A0=20l'application=20apr=C3=A8?= =?UTF-8?q?s=20authentification.=20Le=20callback=20OAuth=20d=C3=A9code=20m?= =?UTF-8?q?aintenant=20le=20state=20pour=20rediriger=20vers=20/admin=20au?= =?UTF-8?q?=20lieu=20de=20rester=20sur=20le=20tableau=20de=20bord=20Manus.?= =?UTF-8?q?=20Le=20syst=C3=A8me=20g=C3=A8re=20maintenant=20correctement=20?= =?UTF-8?q?les=20deux=20modes=20d'authentification=20(local=20+=20OAuth).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/const.ts | 5 +++-- server/_core/oauth.ts | 15 ++++++++++++++- todo.md | 7 +++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/client/src/const.ts b/client/src/const.ts index 97b8d8b..68fbec9 100644 --- a/client/src/const.ts +++ b/client/src/const.ts @@ -11,8 +11,9 @@ export const getLoginUrl = () => "/login"; export const getOAuthLoginUrl = () => { const appId = import.meta.env.VITE_APP_ID; const portalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL; - const currentUrl = window.location.href; + // Toujours rediriger vers /admin après OAuth + const redirectAfterAuth = `${window.location.origin}/admin`; const redirectUri = `${window.location.origin}/api/oauth/callback`; - const state = btoa(currentUrl); + const state = btoa(redirectAfterAuth); return `${portalUrl}?appId=${appId}&redirectUri=${encodeURIComponent(redirectUri)}&state=${encodeURIComponent(state)}&responseType=code`; }; diff --git a/server/_core/oauth.ts b/server/_core/oauth.ts index fd45373..0ae8313 100644 --- a/server/_core/oauth.ts +++ b/server/_core/oauth.ts @@ -44,7 +44,20 @@ export function registerOAuthRoutes(app: Express) { const cookieOptions = getSessionCookieOptions(req); res.cookie(COOKIE_NAME, sessionToken, { ...cookieOptions, maxAge: ONE_YEAR_MS }); - res.redirect(302, "/"); + // Décoder le state pour obtenir l'URL de redirection + let redirectUrl = "/"; + try { + redirectUrl = Buffer.from(state, 'base64').toString('utf-8'); + // Si c'est une URL complète, extraire seulement le path + if (redirectUrl.startsWith('http')) { + const url = new URL(redirectUrl); + redirectUrl = url.pathname; + } + } catch (error) { + console.warn("[OAuth] Failed to decode state, redirecting to /", error); + } + + res.redirect(302, redirectUrl); } catch (error) { console.error("[OAuth] Callback failed", error); res.status(500).json({ error: "OAuth callback failed" }); diff --git a/todo.md b/todo.md index 7876de3..6db74e4 100644 --- a/todo.md +++ b/todo.md @@ -298,3 +298,10 @@ - [x] Tester la connexion avec OAuth Manus - [x] Tester la connexion avec authentification locale - [x] Vérifier que les deux modes fonctionnent en production + +## Correction redirection OAuth + +- [x] Diagnostiquer pourquoi l'utilisateur est redirigé vers le tableau de bord Manus au lieu de l'application +- [x] Vérifier la configuration de redirectUri dans le flux OAuth +- [x] Corriger la redirection dans /api/oauth/callback pour revenir à l'application +- [x] Tester le flux OAuth complet (clic sur bouton → auth Manus → retour à l'application)