@@ -41,7 +41,8 @@ const (
4141 codexScope = "openid profile email offline_access"
4242 codexAuthClaim = "https://api.openai.com/auth"
4343
44- loginTimeout = 10 * time .Minute
44+ loginTimeout = 10 * time .Minute
45+ tokenExchangeTimeout = 45 * time .Second
4546)
4647
4748// claudeTokenURL is a var (not const) so tests can point it at a local server.
@@ -127,7 +128,9 @@ func loginClaude(ctx context.Context, openBrowser bool) (string, error) {
127128 if err != nil {
128129 return authURL , err
129130 }
130- creds , err := exchangeClaudeCode (ctx , cb .Code , cb .State , pkce .Verifier , redirectURI )
131+ exchangeCtx , exchangeCancel := context .WithTimeout (ctx , tokenExchangeTimeout )
132+ defer exchangeCancel ()
133+ creds , err := exchangeClaudeCode (exchangeCtx , cb .Code , cb .State , pkce .Verifier , redirectURI )
131134 if err != nil {
132135 return authURL , err
133136 }
@@ -178,7 +181,9 @@ func loginCodex(ctx context.Context, openBrowser bool) (string, error) {
178181 if err != nil {
179182 return authURL , err
180183 }
181- creds , err := exchangeCodexCode (ctx , cb .Code , pkce .Verifier , redirectURI )
184+ exchangeCtx , exchangeCancel := context .WithTimeout (ctx , tokenExchangeTimeout )
185+ defer exchangeCancel ()
186+ creds , err := exchangeCodexCode (exchangeCtx , cb .Code , pkce .Verifier , redirectURI )
182187 if err != nil {
183188 return authURL , err
184189 }
0 commit comments