@@ -52,15 +52,15 @@ func handleAuthLogin(ctx context.Context, cmd *cli.Command) error {
5252 cc := getAPICommandContext (cmd )
5353 clientID := cmd .String ("client-id" )
5454 scope := "openapi:read project:write project:read"
55- config , err := startDeviceFlow (ctx , cc .client , clientID , scope )
55+ config , err := startDeviceFlow (ctx , cmd , cc .client , clientID , scope )
5656 if err != nil {
5757 return err
5858 }
5959 if err := SaveAuthConfig (config ); err != nil {
6060 Error ("Failed to save authentication: %v" , err )
6161 return fmt .Errorf ("authentication failed" )
6262 }
63- Success ("Authentication successful! Your credentials have been saved." )
63+ Success ("Authentication successful! Your credentials have been saved to ." )
6464 return nil
6565}
6666
@@ -179,7 +179,7 @@ func handleAuthStatus(ctx context.Context, cmd *cli.Command) error {
179179}
180180
181181// startDeviceFlow initiates the OAuth 2.0 device flow
182- func startDeviceFlow (ctx context.Context , client stainless.Client , clientID , scope string ) (* AuthConfig , error ) {
182+ func startDeviceFlow (ctx context.Context , cmd * cli. Command , client stainless.Client , clientID , scope string ) (* AuthConfig , error ) {
183183 var deviceResponse struct {
184184 DeviceCode string `json:"device_code"`
185185 UserCode string `json:"user_code"`
@@ -198,14 +198,20 @@ func startDeviceFlow(ctx context.Context, client stainless.Client, clientID, sco
198198 return nil , err
199199 }
200200
201- if err := browser .OpenURL (deviceResponse .VerificationURIComplete ); err != nil {
202- group := Info ("To authenticate, visit the verification URL" )
203- group .Property ("url" , deviceResponse .VerificationURI )
204- group .Property ("code" , deviceResponse .UserCode )
205- group .Property ("direct_url" , deviceResponse .VerificationURIComplete )
206- } else {
207- group := Info ("Browser opened" )
208- group .Property ("url" , deviceResponse .VerificationURIComplete )
201+ group := Info ("To authenticate, visit the verification URL" )
202+ group .Property ("url" , deviceResponse .VerificationURIComplete )
203+ group .Property ("code" , deviceResponse .UserCode )
204+
205+ ok , _ , err := group .Confirm (cmd , "browser" , "Open browser?" , "" , true )
206+ if err != nil {
207+ return nil , err
208+ }
209+ if ok {
210+ if err := browser .OpenURL (deviceResponse .VerificationURIComplete ); err == nil {
211+ group .Info ("Opening browser..." )
212+ } else {
213+ group .Warn ("Could not open browser" )
214+ }
209215 }
210216
211217 return pollForToken (
@@ -249,7 +255,7 @@ func pollForToken(ctx context.Context, client stainless.Client, clientID, device
249255 var apierr * stainless.Error
250256 if errors .As (err , & apierr ) {
251257 // If we got an error, check if it's "authorization_pending" and continue polling
252- errorStr := gjson .Get (apierr .RawJSON (), "error.error " ).String ()
258+ errorStr := gjson .Get (apierr .RawJSON (), "error" ).String ()
253259 // This is expected, continue polling
254260 if errorStr == "authorization_pending" {
255261 continue
0 commit comments