Checkpoint: Correction de la redirection OAuth pour revenir à l'application après authentification. Le callback OAuth décode maintenant le state pour rediriger vers /admin au lieu de rester sur le tableau de bord Manus. Le système gère maintenant correctement les deux modes d'authentification (local + OAuth).
This commit is contained in:
@@ -11,8 +11,9 @@ export const getLoginUrl = () => "/login";
|
|||||||
export const getOAuthLoginUrl = () => {
|
export const getOAuthLoginUrl = () => {
|
||||||
const appId = import.meta.env.VITE_APP_ID;
|
const appId = import.meta.env.VITE_APP_ID;
|
||||||
const portalUrl = import.meta.env.VITE_OAUTH_PORTAL_URL;
|
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 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`;
|
return `${portalUrl}?appId=${appId}&redirectUri=${encodeURIComponent(redirectUri)}&state=${encodeURIComponent(state)}&responseType=code`;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,7 +44,20 @@ export function registerOAuthRoutes(app: Express) {
|
|||||||
const cookieOptions = getSessionCookieOptions(req);
|
const cookieOptions = getSessionCookieOptions(req);
|
||||||
res.cookie(COOKIE_NAME, sessionToken, { ...cookieOptions, maxAge: ONE_YEAR_MS });
|
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) {
|
} catch (error) {
|
||||||
console.error("[OAuth] Callback failed", error);
|
console.error("[OAuth] Callback failed", error);
|
||||||
res.status(500).json({ error: "OAuth callback failed" });
|
res.status(500).json({ error: "OAuth callback failed" });
|
||||||
|
|||||||
7
todo.md
7
todo.md
@@ -298,3 +298,10 @@
|
|||||||
- [x] Tester la connexion avec OAuth Manus
|
- [x] Tester la connexion avec OAuth Manus
|
||||||
- [x] Tester la connexion avec authentification locale
|
- [x] Tester la connexion avec authentification locale
|
||||||
- [x] Vérifier que les deux modes fonctionnent en production
|
- [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)
|
||||||
|
|||||||
Reference in New Issue
Block a user