mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 21:00:52 +08:00
fix(sdk/auth): prevent OAuth manual prompt goroutine leak,Use timer-based manual prompt per provider and remove oauth_callback helper.
This commit is contained in:
@@ -99,20 +99,54 @@ func (AntigravityAuthenticator) Login(ctx context.Context, cfg *config.Config, o
|
||||
fmt.Println("Waiting for antigravity authentication callback...")
|
||||
|
||||
var cbRes callbackResult
|
||||
manualCh, manualErrCh := promptForOAuthCallback(opts.Prompt, "antigravity")
|
||||
select {
|
||||
case res := <-cbChan:
|
||||
cbRes = res
|
||||
case manual := <-manualCh:
|
||||
cbRes = callbackResult{
|
||||
Code: manual.Code,
|
||||
State: manual.State,
|
||||
Error: manual.Error,
|
||||
timeoutTimer := time.NewTimer(5 * time.Minute)
|
||||
defer timeoutTimer.Stop()
|
||||
|
||||
var manualPromptTimer *time.Timer
|
||||
var manualPromptC <-chan time.Time
|
||||
if opts.Prompt != nil {
|
||||
manualPromptTimer = time.NewTimer(15 * time.Second)
|
||||
manualPromptC = manualPromptTimer.C
|
||||
defer manualPromptTimer.Stop()
|
||||
}
|
||||
|
||||
waitForCallback:
|
||||
for {
|
||||
select {
|
||||
case res := <-cbChan:
|
||||
cbRes = res
|
||||
break waitForCallback
|
||||
case <-manualPromptC:
|
||||
manualPromptC = nil
|
||||
if manualPromptTimer != nil {
|
||||
manualPromptTimer.Stop()
|
||||
}
|
||||
select {
|
||||
case res := <-cbChan:
|
||||
cbRes = res
|
||||
break waitForCallback
|
||||
default:
|
||||
}
|
||||
input, errPrompt := opts.Prompt("Paste the antigravity callback URL (or press Enter to keep waiting): ")
|
||||
if errPrompt != nil {
|
||||
return nil, errPrompt
|
||||
}
|
||||
parsed, errParse := misc.ParseOAuthCallback(input)
|
||||
if errParse != nil {
|
||||
return nil, errParse
|
||||
}
|
||||
if parsed == nil {
|
||||
continue
|
||||
}
|
||||
cbRes = callbackResult{
|
||||
Code: parsed.Code,
|
||||
State: parsed.State,
|
||||
Error: parsed.Error,
|
||||
}
|
||||
break waitForCallback
|
||||
case <-timeoutTimer.C:
|
||||
return nil, fmt.Errorf("antigravity: authentication timed out")
|
||||
}
|
||||
case err = <-manualErrCh:
|
||||
return nil, err
|
||||
case <-time.After(5 * time.Minute):
|
||||
return nil, fmt.Errorf("antigravity: authentication timed out")
|
||||
}
|
||||
|
||||
if cbRes.Error != "" {
|
||||
|
||||
Reference in New Issue
Block a user