feat: Implement S2A OAuth authorization using chromedp and rod browser automation, and integrate it into team processing.

This commit is contained in:
2026-02-02 05:32:40 +08:00
parent 4cd9f2b2b7
commit 74796a16dd
3 changed files with 58 additions and 21 deletions

View File

@@ -164,6 +164,7 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
var currentURL string
_ = chromedp.Run(ctx, chromedp.Location(&currentURL))
logStep(StepNavigate, "页面加载完成 | URL: %s", currentURL)
if strings.Contains(currentURL, "code=") {
logStep(StepComplete, "授权成功(快速通道)")
@@ -194,6 +195,7 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
)
if err == nil {
emailFilled = true
logStep(StepInputEmail, "邮箱已填写 | 选择器: %s", sel)
break
}
}
@@ -201,7 +203,8 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
findCancel()
if !emailFilled {
logError(StepInputEmail, "未找到邮箱输入框")
_ = chromedp.Run(ctx, chromedp.Location(&currentURL))
logError(StepInputEmail, "未找到邮箱输入框 | URL: %s", currentURL)
return "", fmt.Errorf("未找到邮箱输入框")
}
@@ -209,6 +212,7 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
buttonSelectors := []string{
`button[type="submit"]`,
`div._ctas_1alro_13 button`,
`button[data-testid="login-button"]`,
`button.continue-btn`,
`input[type="submit"]`,
@@ -235,13 +239,15 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
return ExtractCodeFromCallbackURL(currentURL), nil
}
logStep(StepInputPassword, "查找密码框 | URL: %s", currentURL)
// 密码输入框选择器
passwordSelectors := []string{
`input[name="current-password"]`,
`input[autocomplete="current-password"]`,
`input[type="password"]`,
`input[name="password"]`,
`input[name="current-password"]`,
`input[id="password"]`,
`input[autocomplete="current-password"]`,
}
// 使用短超时查找密码框10秒
@@ -257,6 +263,7 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
)
if err == nil {
passwordFilled = true
logStep(StepInputPassword, "密码已填写 | 选择器: %s", sel)
break
}
}
@@ -264,7 +271,8 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
findCancel2()
if !passwordFilled {
logError(StepInputPassword, "未找到密码输入框")
_ = chromedp.Run(ctx, chromedp.Location(&currentURL))
logError(StepInputPassword, "未找到密码输入框 | URL: %s", currentURL)
return "", fmt.Errorf("未找到密码输入框")
}
@@ -295,8 +303,14 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
}
if strings.Contains(url, "consent") {
logStep(StepConsent, "处理授权同意...")
for _, sel := range buttonSelectors {
logStep(StepConsent, "处理授权同意... | URL: %s", url)
// 同意页面的确认按钮(第二个按钮)
consentSelectors := []string{
`div._ctas_1alro_13 div:nth-child(2) button`,
`button[type="submit"]`,
`div._ctas_1alro_13 button`,
}
for _, sel := range consentSelectors {
err = chromedp.Run(ctx, chromedp.Click(sel, chromedp.ByQuery))
if err == nil {
break