feat: Implement S2A OAuth authorization using chromedp and introduce new files for browser automation and team processing.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"codex-pool/internal/proxyutil"
|
||||
|
||||
"github.com/chromedp/cdproto/cdp"
|
||||
"github.com/chromedp/cdproto/fetch"
|
||||
"github.com/chromedp/cdproto/network"
|
||||
"github.com/chromedp/cdproto/page"
|
||||
@@ -226,22 +227,7 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(1500 * time.Millisecond)
|
||||
|
||||
if callbackURL != "" {
|
||||
logStep(StepComplete, "授权成功")
|
||||
return ExtractCodeFromCallbackURL(callbackURL), nil
|
||||
}
|
||||
|
||||
_ = chromedp.Run(ctx, chromedp.Location(¤tURL))
|
||||
if strings.Contains(currentURL, "code=") {
|
||||
logStep(StepComplete, "授权成功")
|
||||
return ExtractCodeFromCallbackURL(currentURL), nil
|
||||
}
|
||||
|
||||
logStep(StepInputPassword, "查找密码框 | URL: %s", currentURL)
|
||||
|
||||
// 密码输入框选择器
|
||||
// 等待页面跳转(等待 URL 变化或密码框出现,最多 10 秒)
|
||||
passwordSelectors := []string{
|
||||
`input[name="current-password"]`,
|
||||
`input[autocomplete="current-password"]`,
|
||||
@@ -250,6 +236,41 @@ func CompleteWithChromedpLogged(authURL, email, password, teamID string, headles
|
||||
`input[id="password"]`,
|
||||
}
|
||||
|
||||
var passwordFound bool
|
||||
for i := 0; i < 20; i++ {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
if callbackURL != "" {
|
||||
logStep(StepComplete, "授权成功")
|
||||
return ExtractCodeFromCallbackURL(callbackURL), nil
|
||||
}
|
||||
|
||||
_ = chromedp.Run(ctx, chromedp.Location(¤tURL))
|
||||
if strings.Contains(currentURL, "code=") {
|
||||
logStep(StepComplete, "授权成功")
|
||||
return ExtractCodeFromCallbackURL(currentURL), nil
|
||||
}
|
||||
|
||||
// 检查是否有密码输入框(页面已跳转)
|
||||
for _, sel := range passwordSelectors {
|
||||
var nodes []*cdp.Node
|
||||
if err := chromedp.Run(ctx, chromedp.Nodes(sel, &nodes, chromedp.ByQuery)); err == nil && len(nodes) > 0 {
|
||||
passwordFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if passwordFound {
|
||||
break
|
||||
}
|
||||
|
||||
// 如果 URL 已经变化(包含 password),也跳出
|
||||
if strings.Contains(currentURL, "password") {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
logStep(StepInputPassword, "查找密码框 | URL: %s", currentURL)
|
||||
|
||||
// 使用短超时查找密码框(10秒)
|
||||
findCtx2, findCancel2 := context.WithTimeout(ctx, 10*time.Second)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user