feat: Implement S2A OAuth authorization using chromedp and rod browser automation, and integrate it into team processing.
This commit is contained in:
@@ -218,6 +218,11 @@ func (r *RodAuth) CompleteOAuthLogged(authURL, email, password, teamID string, l
|
||||
|
||||
page.MustWaitDOMStable()
|
||||
|
||||
// 获取当前URL
|
||||
info, _ := page.Info()
|
||||
currentURL := info.URL
|
||||
logStep(StepNavigate, "页面加载完成 | URL: %s", currentURL)
|
||||
|
||||
if code := r.checkForCode(page); code != "" {
|
||||
logStep(StepComplete, "授权成功(快速通道)")
|
||||
return code, nil
|
||||
@@ -226,14 +231,17 @@ func (r *RodAuth) CompleteOAuthLogged(authURL, email, password, teamID string, l
|
||||
// 使用10秒超时查找邮箱输入框
|
||||
emailInput, err := page.Timeout(10 * time.Second).Element("input[name='email'], input[type='email'], input[name='username'], input[id='email'], input[autocomplete='email']")
|
||||
if err != nil {
|
||||
logError(StepInputEmail, "未找到邮箱输入框")
|
||||
info, _ := page.Info()
|
||||
logError(StepInputEmail, "未找到邮箱输入框 | URL: %s", info.URL)
|
||||
return "", fmt.Errorf("未找到邮箱输入框")
|
||||
}
|
||||
|
||||
logStep(StepInputEmail, "邮箱已填写")
|
||||
emailInput.MustSelectAllText().MustInput(email)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
if btn, _ := page.Timeout(2 * time.Second).Element("button[type='submit'], button[name='action']"); btn != nil {
|
||||
// 点击提交按钮
|
||||
if btn, _ := page.Timeout(2 * time.Second).Element("button[type='submit'], div._ctas_1alro_13 button, button[name='action']"); btn != nil {
|
||||
btn.MustClick()
|
||||
}
|
||||
|
||||
@@ -244,18 +252,24 @@ func (r *RodAuth) CompleteOAuthLogged(authURL, email, password, teamID string, l
|
||||
return code, nil
|
||||
}
|
||||
|
||||
// 使用10秒超时查找密码输入框
|
||||
passwordInput, err := page.Timeout(10 * time.Second).Element("input[type='password'], input[name='password'], input[id='password']")
|
||||
// 获取当前URL用于调试
|
||||
info, _ = page.Info()
|
||||
logStep(StepInputPassword, "查找密码框 | URL: %s", info.URL)
|
||||
|
||||
// 使用10秒超时查找密码输入框(优先使用 current-password)
|
||||
passwordInput, err := page.Timeout(10 * time.Second).Element("input[name='current-password'], input[autocomplete='current-password'], input[type='password'], input[name='password'], input[id='password']")
|
||||
if err != nil {
|
||||
logError(StepInputPassword, "未找到密码输入框")
|
||||
info, _ := page.Info()
|
||||
logError(StepInputPassword, "未找到密码输入框 | URL: %s", info.URL)
|
||||
return "", fmt.Errorf("未找到密码输入框")
|
||||
}
|
||||
|
||||
logStep(StepInputPassword, "密码已填写")
|
||||
passwordInput.MustSelectAllText().MustInput(password)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
logStep(StepSubmitPassword, "正在登录...")
|
||||
if btn, _ := page.Timeout(2 * time.Second).Element("button[type='submit'], button[name='action']"); btn != nil {
|
||||
if btn, _ := page.Timeout(2 * time.Second).Element("button[type='submit'], div._ctas_1alro_13 button, button[name='action']"); btn != nil {
|
||||
btn.MustClick()
|
||||
}
|
||||
|
||||
@@ -272,8 +286,9 @@ func (r *RodAuth) CompleteOAuthLogged(authURL, email, password, teamID string, l
|
||||
currentURL := info.URL
|
||||
|
||||
if strings.Contains(currentURL, "consent") {
|
||||
logStep(StepConsent, "处理授权同意...")
|
||||
if btn, _ := page.Timeout(500 * time.Millisecond).Element("button[type='submit']"); btn != nil {
|
||||
logStep(StepConsent, "处理授权同意... | URL: %s", currentURL)
|
||||
// 同意页面的确认按钮(第二个按钮)
|
||||
if btn, _ := page.Timeout(500 * time.Millisecond).Element("div._ctas_1alro_13 div:nth-child(2) button, button[type='submit'], div._ctas_1alro_13 button"); btn != nil {
|
||||
btn.Click(proto.InputMouseButtonLeft, 1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user