|
|
@@ -103,6 +103,8 @@ function parseCookies(setCookieHeaders) {
|
|
|
// 生成跳转 HTML
|
|
|
function generateRedirectHTML(cookieData, targetHost, targetDomain, requestId = '', customUrl = null) {
|
|
|
const targetUrl = customUrl || `http://${targetHost}/`;
|
|
|
+ const isHomeAssistant = targetUrl.includes('/auth/authorize');
|
|
|
+
|
|
|
return `
|
|
|
<!DOCTYPE html>
|
|
|
<html lang="zh-CN">
|
|
|
@@ -154,6 +156,7 @@ function generateRedirectHTML(cookieData, targetHost, targetDomain, requestId =
|
|
|
const cookies = ${JSON.stringify(cookieData)};
|
|
|
const targetUrl = '${targetUrl}';
|
|
|
const targetDomain = '${targetDomain}';
|
|
|
+ const isHomeAssistant = ${isHomeAssistant};
|
|
|
|
|
|
console.log('========================================');
|
|
|
console.log('[浏览器端] 自动登录脚本开始执行');
|
|
|
@@ -162,6 +165,7 @@ function generateRedirectHTML(cookieData, targetHost, targetDomain, requestId =
|
|
|
console.log('[浏览器端] 目标域名:', targetDomain);
|
|
|
console.log('[浏览器端] Cookie 数量:', cookies.length);
|
|
|
console.log('[浏览器端] Cookie 详情:', cookies);
|
|
|
+ console.log('[浏览器端] 是否为 Home Assistant 授权流程:', isHomeAssistant);
|
|
|
|
|
|
// 方法1: 尝试直接设置 Cookie(可能因为跨域限制而失败)
|
|
|
if (cookies.length > 0) {
|
|
|
@@ -214,6 +218,17 @@ function generateRedirectHTML(cookieData, targetHost, targetDomain, requestId =
|
|
|
console.log('[浏览器端] 没有 Cookie 需要设置,直接跳转');
|
|
|
}
|
|
|
|
|
|
+ // 对于 Home Assistant 授权流程,直接跳转(不需要 iframe)
|
|
|
+ if (isHomeAssistant) {
|
|
|
+ console.log('[浏览器端] Home Assistant 授权流程,直接跳转到授权端点');
|
|
|
+ console.log('[浏览器端] 授权 URL:', targetUrl);
|
|
|
+ console.log('[浏览器端] 浏览器将处理授权流程并设置 Cookie');
|
|
|
+ console.log('========================================');
|
|
|
+ // 立即跳转,让浏览器处理授权流程
|
|
|
+ window.location.href = targetUrl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 方法2: 使用隐藏的 iframe 加载目标站点,让服务器设置 Cookie
|
|
|
// 然后跳转到目标站点
|
|
|
console.log('[浏览器端] 创建隐藏 iframe 加载目标站点...');
|