forked from baron/baron-sso
fix: SSO 팝업 로그인 시 postMessage 흐름 보장 및 콜백 페이지 팝업 대응 #243
This commit is contained in:
@@ -10,8 +10,15 @@ function AuthCallbackPage() {
|
|||||||
const token = searchParams.get("token");
|
const token = searchParams.get("token");
|
||||||
if (token) {
|
if (token) {
|
||||||
window.localStorage.setItem("admin_session", token);
|
window.localStorage.setItem("admin_session", token);
|
||||||
// Redirect to home after a short delay or immediately
|
|
||||||
|
// 만약 팝업창에서 실행 중이라면 부모 창에 알리고 닫기
|
||||||
|
if (window.opener) {
|
||||||
|
window.opener.postMessage({ type: "LOGIN_SUCCESS", token }, "*");
|
||||||
|
window.close();
|
||||||
|
} else {
|
||||||
|
// 일반 리다이렉트 방식인 경우 홈으로 이동
|
||||||
navigate("/", { replace: true });
|
navigate("/", { replace: true });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error("No token found in callback URL");
|
console.error("No token found in callback URL");
|
||||||
navigate("/login", { replace: true });
|
navigate("/login", { replace: true });
|
||||||
|
|||||||
@@ -32,7 +32,11 @@ function LoginPage() {
|
|||||||
const handleSSOLogin = (mode: "popup" | "redirect" = "popup") => {
|
const handleSSOLogin = (mode: "popup" | "redirect" = "popup") => {
|
||||||
const userfrontUrl = import.meta.env.USERFRONT_URL || "https://sso.hmac.kr";
|
const userfrontUrl = import.meta.env.USERFRONT_URL || "https://sso.hmac.kr";
|
||||||
const callbackUrl = `${window.location.origin}/auth/callback`;
|
const callbackUrl = `${window.location.origin}/auth/callback`;
|
||||||
const loginUrl = `${userfrontUrl}/signin?source=adminfront&redirect_uri=${encodeURIComponent(callbackUrl)}`;
|
|
||||||
|
// 팝업 방식일 때는 redirect_uri를 보내지 않아야 postMessage 로직이 작동함
|
||||||
|
const loginUrl = mode === "redirect"
|
||||||
|
? `${userfrontUrl}/signin?source=adminfront&redirect_uri=${encodeURIComponent(callbackUrl)}`
|
||||||
|
: `${userfrontUrl}/signin?source=adminfront`;
|
||||||
|
|
||||||
if (mode === "redirect") {
|
if (mode === "redirect") {
|
||||||
window.location.href = loginUrl;
|
window.location.href = loginUrl;
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
|||||||
|
|
||||||
if (uri.queryParameters.containsKey('redirect_url')) {
|
if (uri.queryParameters.containsKey('redirect_url')) {
|
||||||
_redirectUrl = uri.queryParameters['redirect_url'];
|
_redirectUrl = uri.queryParameters['redirect_url'];
|
||||||
|
} else if (uri.queryParameters.containsKey('redirect_uri')) {
|
||||||
|
_redirectUrl = uri.queryParameters['redirect_uri'];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1124,14 +1126,15 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
|||||||
if (WebAuthIntegration.isPopup()) {
|
if (WebAuthIntegration.isPopup()) {
|
||||||
debugPrint("[Auth] Popup detected. Notifying opener and attempting to close.");
|
debugPrint("[Auth] Popup detected. Notifying opener and attempting to close.");
|
||||||
WebAuthIntegration.sendLoginSuccess(token);
|
WebAuthIntegration.sendLoginSuccess(token);
|
||||||
} else {
|
return; // Stop here for popups
|
||||||
|
}
|
||||||
|
|
||||||
if (_redirectUrl != null && _redirectUrl!.isNotEmpty) {
|
if (_redirectUrl != null && _redirectUrl!.isNotEmpty) {
|
||||||
debugPrint("[Auth] Redirecting standalone window to: $_redirectUrl");
|
debugPrint("[Auth] Redirecting standalone window to: $_redirectUrl");
|
||||||
final target = "$_redirectUrl?token=$token";
|
final target = "$_redirectUrl?token=$token";
|
||||||
launchUrlString(target, webOnlyWindowName: '_self');
|
launchUrlString(target, webOnlyWindowName: '_self');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
debugPrint("[Auth] Login success. Navigating to root.");
|
debugPrint("[Auth] Login success. Navigating to root.");
|
||||||
AuthNotifier.instance.notify();
|
AuthNotifier.instance.notify();
|
||||||
|
|||||||
Reference in New Issue
Block a user