Skip to content

Commit f131063

Browse files
committed
fix: remove timeout
This doesn't work well with the browser workflow
1 parent c1421b5 commit f131063

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

cmd/login.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"strings"
7-
"time"
87

98
"github.com/numtide/nix-auth/internal/config"
109
"github.com/numtide/nix-auth/internal/provider"
@@ -50,15 +49,13 @@ var (
5049
loginProvider string
5150
loginClientID string
5251
loginForce bool
53-
loginTimeout int
5452
loginDryRun bool
5553
)
5654

5755
func init() {
5856
loginCmd.Flags().StringVar(&loginProvider, "provider", "auto", "Provider type when using a host (auto, github, gitlab, gitea, forgejo, codeberg)")
5957
loginCmd.Flags().StringVar(&loginClientID, "client-id", "", "OAuth client ID (required for GitHub Enterprise, optional for others)")
6058
loginCmd.Flags().BoolVar(&loginForce, "force", false, "Skip confirmation prompt when replacing existing tokens")
61-
loginCmd.Flags().IntVar(&loginTimeout, "timeout", 30, "Timeout in seconds for network operations")
6259
loginCmd.Flags().BoolVar(&loginDryRun, "dry-run", false, "Preview what would happen without authenticating")
6360
}
6461

@@ -70,7 +67,7 @@ func runLogin(cmd *cobra.Command, args []string) error {
7067
}
7168

7269
// Resolve provider and host
73-
prov, host, err := resolveProviderAndHost(input, loginProvider, loginTimeout)
70+
prov, host, err := resolveProviderAndHost(input, loginProvider)
7471
if err != nil {
7572
return err
7673
}
@@ -109,17 +106,11 @@ func runLogin(cmd *cobra.Command, args []string) error {
109106
}
110107

111108
// Perform authentication
112-
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(loginTimeout)*time.Second)
113-
defer cancel()
109+
ctx := context.Background()
114110
token, err := prov.Authenticate(ctx)
115111
if err != nil {
116112
errMsg := fmt.Sprintf("authentication failed: %v", err)
117-
if strings.Contains(err.Error(), "context deadline exceeded") {
118-
errMsg += fmt.Sprintf("\n\nThe operation timed out after %d seconds. Try:\n"+
119-
"- Increasing the timeout: --timeout 60\n"+
120-
"- Checking your internet connection\n"+
121-
"- Verifying the host is accessible: curl https://%s", loginTimeout, host)
122-
} else if strings.Contains(err.Error(), "client ID") {
113+
if strings.Contains(err.Error(), "client ID") {
123114
errMsg += "\n\nFor self-hosted instances, you need to create an OAuth application.\n" +
124115
"See the instructions above or use --dry-run to preview the configuration."
125116
}
@@ -151,7 +142,7 @@ func runLogin(cmd *cobra.Command, args []string) error {
151142
}
152143

153144
// resolveProviderAndHost determines the provider and host from the input
154-
func resolveProviderAndHost(input, providerFlag string, timeout int) (provider.Provider, string, error) {
145+
func resolveProviderAndHost(input, providerFlag string) (provider.Provider, string, error) {
155146
// Check if input is a provider alias
156147
if reg, ok := provider.GetRegistration(input); ok {
157148
// It's a provider alias
@@ -176,16 +167,15 @@ func resolveProviderAndHost(input, providerFlag string, timeout int) (provider.P
176167
}
177168

178169
// Input is a host
179-
return resolveProviderForHost(input, providerFlag, timeout)
170+
return resolveProviderForHost(input, providerFlag)
180171
}
181172

182173
// resolveProviderForHost handles the case where input is a host
183-
func resolveProviderForHost(host, providerFlag string, timeout int) (provider.Provider, string, error) {
174+
func resolveProviderForHost(host, providerFlag string) (provider.Provider, string, error) {
184175
if providerFlag == "auto" {
185176
// Auto-detect provider type
186177
fmt.Printf("Detecting provider type for %s by querying API...\n", host)
187-
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
188-
defer cancel()
178+
ctx := context.Background()
189179

190180
prov, err := provider.Detect(ctx, host, loginClientID)
191181
if err != nil {

internal/provider/pat_provider.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"net/http"
88
"strings"
9-
"time"
109

1110
"github.com/cli/browser"
1211
)
@@ -95,11 +94,7 @@ func (p *PersonalAccessTokenProvider) Authenticate(ctx context.Context) (string,
9594
return "", fmt.Errorf("token cannot be empty")
9695
}
9796

98-
// Use a new context with timeout only for validation
99-
validateCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
100-
defer cancel()
101-
102-
status, err := p.ValidateToken(validateCtx, token)
97+
status, err := p.ValidateToken(ctx, token)
10398
if status != ValidationStatusValid {
10499
if err != nil {
105100
return "", fmt.Errorf("invalid token: %w", err)

0 commit comments

Comments
 (0)