钉钉登录确认会话后再跳转

This commit is contained in:
WuYongJie 2026-11-18 18:51:07 +08:00
parent a13a6cc180
commit 8b2ec847e7
2 changed files with 5 additions and 3 deletions

View File

@ -118,6 +118,7 @@ export default function Page() {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
"X-Auth-Return-Redirect": "1",
}, },
body: new URLSearchParams({ body: new URLSearchParams({
csrfToken, csrfToken,

View File

@ -143,7 +143,7 @@
<div class="brand-mark">AI</div> <div class="brand-mark">AI</div>
<div class="loading-spinner"></div> <div class="loading-spinner"></div>
<p id="statusText" class="status-text">正在登录...</p> <p id="statusText" class="status-text">正在登录...</p>
<p class="hint-text">正在通过钉钉确认企业身份,完成后会自动回到工作台。</p> <p class="hint-text">正在通过钉钉确认企业身份,完成后会自动返回原页面。</p>
<div class="status-row"> <div class="status-row">
<span class="status-dot"></span> <span class="status-dot"></span>
安全连接已建立 安全连接已建立
@ -215,7 +215,7 @@
if (typeof callbackUrl !== 'string' || !callbackUrl) return '/'; if (typeof callbackUrl !== 'string' || !callbackUrl) return '/';
try { try {
const parsed = new URL(callbackUrl, window.location.origin); const parsed = new URL(callbackUrl, window.location.origin);
if (parsed.origin !== window.location.origin) return '/'; if (parsed.origin !== window.location.origin || parsed.pathname.startsWith('//')) return '/';
return parsed.pathname + parsed.search + parsed.hash; return parsed.pathname + parsed.search + parsed.hash;
} catch (error) { } catch (error) {
return '/'; return '/';
@ -238,6 +238,7 @@
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
'X-Auth-Return-Redirect': '1',
}, },
body: new URLSearchParams({ body: new URLSearchParams({
csrfToken: csrfToken, csrfToken: csrfToken,
@ -251,7 +252,7 @@
if (loginRes.ok || loginRes.redirected) { if (loginRes.ok || loginRes.redirected) {
statusText.textContent = '登录成功,正在跳转...'; statusText.textContent = '登录成功,正在跳转...';
console.log('[DingTalk Callback] Login successful, redirecting to home...'); console.log('[DingTalk Callback] Login successful, validating session...');
// 等待更长时间确保 cookie 被设置并同步 // 等待更长时间确保 cookie 被设置并同步
await new Promise(resolve => setTimeout(resolve, 800)); await new Promise(resolve => setTimeout(resolve, 800));