fix(auth): avoid blocking oauth callback wait on prompt
This commit is contained in:
@@ -98,6 +98,9 @@ func (AntigravityAuthenticator) Login(ctx context.Context, cfg *config.Config, o
|
||||
defer manualPromptTimer.Stop()
|
||||
}
|
||||
|
||||
var manualInputCh <-chan string
|
||||
var manualInputErrCh <-chan error
|
||||
|
||||
waitForCallback:
|
||||
for {
|
||||
select {
|
||||
@@ -115,10 +118,22 @@ waitForCallback:
|
||||
break waitForCallback
|
||||
default:
|
||||
}
|
||||
input, errPrompt := opts.Prompt("Paste the antigravity callback URL (or press Enter to keep waiting): ")
|
||||
if errPrompt != nil {
|
||||
return nil, errPrompt
|
||||
}
|
||||
inputCh := make(chan string, 1)
|
||||
inputErrCh := make(chan error, 1)
|
||||
go func() {
|
||||
input, errPrompt := opts.Prompt("Paste the antigravity callback URL (or press Enter to keep waiting): ")
|
||||
if errPrompt != nil {
|
||||
inputErrCh <- errPrompt
|
||||
return
|
||||
}
|
||||
inputCh <- input
|
||||
}()
|
||||
manualInputCh = inputCh
|
||||
manualInputErrCh = inputErrCh
|
||||
continue
|
||||
case input := <-manualInputCh:
|
||||
manualInputCh = nil
|
||||
manualInputErrCh = nil
|
||||
parsed, errParse := misc.ParseOAuthCallback(input)
|
||||
if errParse != nil {
|
||||
return nil, errParse
|
||||
@@ -132,6 +147,8 @@ waitForCallback:
|
||||
Error: parsed.Error,
|
||||
}
|
||||
break waitForCallback
|
||||
case errManual := <-manualInputErrCh:
|
||||
return nil, errManual
|
||||
case <-timeoutTimer.C:
|
||||
return nil, fmt.Errorf("antigravity: authentication timed out")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user