@@ -101,7 +101,7 @@ func Configure() (*ConfigureTokenResponse, error) {
101101 }
102102
103103 // Perform OAuth flow
104- tokens , err := performOAuthFlow (config )
104+ tokens , err := performOAuthFlow (config , oauthTimeout , true )
105105 if err != nil {
106106 return nil , fmt .Errorf ("OAuth flow failed: %w" , err )
107107 }
@@ -164,30 +164,29 @@ func collectOAuthCredentials() (*OAuthConfig, error) {
164164 RedirectURI string
165165 }{}
166166
167- questions = append ( questions , & survey.Question {
167+ q1 := & survey.Question {
168168 Name : "clientID" ,
169169 Prompt : & survey.Input {
170170 Message : "Jira App Client ID:" ,
171171 Help : "This is the client ID of your Jira App that you created for OAuth authentication." ,
172172 },
173- })
174-
175- questions = append (questions , & survey.Question {
173+ }
174+ q2 := & survey.Question {
176175 Name : "clientSecret" ,
177176 Prompt : & survey.Password {
178177 Message : "Jira App Client Secret:" ,
179178 Help : "This is the client secret of your Jira App that you created for OAuth authentication." ,
180179 },
181- })
182-
183- questions = append (questions , & survey.Question {
180+ }
181+ q3 := & survey.Question {
184182 Name : "redirectURI" ,
185183 Prompt : & survey.Input {
186184 Default : defaultRedirectURI ,
187185 Message : "Redirect URI:" ,
188186 Help : "The redirect URL for Jira App. Recommended to set as localhost." ,
189187 },
190- })
188+ }
189+ questions = append (questions , q1 , q2 , q3 )
191190
192191 if err := survey .Ask (questions , & answers , survey .WithValidator (survey .Required )); err != nil {
193192 return nil , err
@@ -202,7 +201,7 @@ func collectOAuthCredentials() (*OAuthConfig, error) {
202201}
203202
204203// performOAuthFlow executes the OAuth authorization flow.
205- func performOAuthFlow (config * OAuthConfig ) (* oauth2.Token , error ) {
204+ func performOAuthFlow (config * OAuthConfig , httpTimeout time. Duration , openBrowser bool ) (* oauth2.Token , error ) {
206205 s := cmdutil .Info ("Starting OAuth flow..." )
207206 defer s .Stop ()
208207
@@ -256,14 +255,17 @@ func performOAuthFlow(config *OAuthConfig) (*oauth2.Token, error) {
256255 }
257256 }()
258257
259- // Open browser for authorization
260- fmt .Printf ("Opening browser for authorization...\n " )
261- fmt .Printf ("If the browser doesn't open automatically, please visit: %s\n " , authURL )
258+ if openBrowser {
259+ // Open browser for authorization
260+ fmt .Printf ("Opening browser for authorization...\n " )
261+ fmt .Printf ("If the browser doesn't open automatically, please visit: %s\n " , authURL )
262+
263+ // Try to open browser
264+ if err := browser .OpenURL (authURL ); err != nil {
265+ fmt .Printf ("Could not open browser automatically: %v\n " , err )
266+ fmt .Printf ("Please manually visit: %s\n " , authURL )
267+ }
262268
263- // Try to open browser
264- if err := browser .OpenURL (authURL ); err != nil {
265- fmt .Printf ("Could not open browser automatically: %v\n " , err )
266- fmt .Printf ("Please manually visit: %s\n " , authURL )
267269 }
268270
269271 // Wait for authorization code
@@ -297,7 +299,7 @@ func performOAuthFlow(config *OAuthConfig) (*oauth2.Token, error) {
297299 }
298300 return nil , fmt .Errorf ("OAuth flow failed: %w" , err )
299301
300- case <- time .After (oauthTimeout ):
302+ case <- time .After (httpTimeout ):
301303 // Shutdown server
302304 ctx , cancel := context .WithTimeout (context .Background (), serverShutdownTimeout )
303305 defer cancel ()
@@ -316,7 +318,7 @@ func getCloudID(url string, accessToken string) (string, error) {
316318 // Create HTTP client with bearer token
317319 client := & http.Client {Timeout : httpClientTimeout }
318320
319- req , err := http .NewRequest ("GET" , url , nil )
321+ req , err := http .NewRequest ("GET" , url , http . NoBody )
320322 if err != nil {
321323 return "" , err
322324 }
0 commit comments