forked from baron/baron-sso
fix: SSO 로그인 성공 시 adminfront로의 리다이렉션 및 postMessage 흐름 강화 #243
This commit is contained in:
@@ -3,8 +3,14 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:html' as html;
|
import 'dart:html' as html;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'auth_token_store.dart';
|
||||||
|
|
||||||
void implSendLoginSuccess(String token) {
|
void implSendLoginSuccess(String token) {
|
||||||
|
var effectiveToken = token;
|
||||||
|
if (effectiveToken.isEmpty) {
|
||||||
|
effectiveToken = AuthTokenStore.getToken() ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
final uri = Uri.parse(html.window.location.href);
|
final uri = Uri.parse(html.window.location.href);
|
||||||
final redirectUri = uri.queryParameters['redirect_uri'];
|
final redirectUri = uri.queryParameters['redirect_uri'];
|
||||||
|
|
||||||
@@ -12,7 +18,7 @@ void implSendLoginSuccess(String token) {
|
|||||||
// Redirection flow
|
// Redirection flow
|
||||||
final target = Uri.parse(redirectUri);
|
final target = Uri.parse(redirectUri);
|
||||||
final query = Map<String, String>.from(target.queryParameters);
|
final query = Map<String, String>.from(target.queryParameters);
|
||||||
query['token'] = token;
|
query['token'] = effectiveToken;
|
||||||
final finalUri = target.replace(queryParameters: query);
|
final finalUri = target.replace(queryParameters: query);
|
||||||
|
|
||||||
debugPrint('Redirecting to: ${finalUri.toString()}');
|
debugPrint('Redirecting to: ${finalUri.toString()}');
|
||||||
@@ -20,7 +26,7 @@ void implSendLoginSuccess(String token) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final message = {'type': 'LOGIN_SUCCESS', 'token': token};
|
final message = {'type': 'LOGIN_SUCCESS', 'token': effectiveToken};
|
||||||
|
|
||||||
if (html.window.opener != null) {
|
if (html.window.opener != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -163,6 +163,16 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final token = AuthTokenStore.getToken();
|
||||||
|
if (token != null && token.isNotEmpty) {
|
||||||
|
if (WebAuthIntegration.isPopup() || (_redirectUrl != null && _redirectUrl!.isNotEmpty)) {
|
||||||
|
debugPrint("[Auth] Cookie session with external integration. Notifying...");
|
||||||
|
WebAuthIntegration.sendLoginSuccess(token);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
context.go('/');
|
context.go('/');
|
||||||
}
|
}
|
||||||
@@ -1123,16 +1133,9 @@ class _LoginScreenState extends ConsumerState<LoginScreen>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WebAuthIntegration.isPopup()) {
|
if (WebAuthIntegration.isPopup() || (_redirectUrl != null && _redirectUrl!.isNotEmpty)) {
|
||||||
debugPrint("[Auth] Popup detected. Notifying opener and attempting to close.");
|
debugPrint("[Auth] External integration detected (popup or redirect). Notifying...");
|
||||||
WebAuthIntegration.sendLoginSuccess(token);
|
WebAuthIntegration.sendLoginSuccess(token);
|
||||||
return; // Stop here for popups
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_redirectUrl != null && _redirectUrl!.isNotEmpty) {
|
|
||||||
debugPrint("[Auth] Redirecting standalone window to: $_redirectUrl");
|
|
||||||
final target = "$_redirectUrl?token=$token";
|
|
||||||
launchUrlString(target, webOnlyWindowName: '_self');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user