@@ -11,13 +11,13 @@ import (
1111 "log/slog"
1212 "net/http"
1313 "net/url"
14- "os/exec"
1514 "regexp"
16- "runtime"
1715 "strings"
1816 "time"
1917
2018 "golang.org/x/oauth2"
19+
20+ "github.com/docker/cagent/pkg/browser"
2121)
2222
2323// resourceMetadataFromWWWAuth extracts resource metadata URL from WWW-Authenticate header
@@ -221,7 +221,7 @@ func exchangeCodeForToken(ctx context.Context, tokenEndpoint, code, codeVerifier
221221
222222// requestAuthorizationCode requests the user to open the authorization URL and waits for the callback
223223func requestAuthorizationCode (ctx context.Context , authURL string , callbackServer * CallbackServer , expectedState string ) (string , string , error ) {
224- if err := openBrowser (ctx , authURL ); err != nil {
224+ if err := browser . Open (ctx , authURL ); err != nil {
225225 return "" , "" , err
226226 }
227227
@@ -237,32 +237,6 @@ func requestAuthorizationCode(ctx context.Context, authURL string, callbackServe
237237 return code , state , nil
238238}
239239
240- func openBrowser (ctx context.Context , urlToOpen string ) error {
241- var cmd string
242- var args []string
243-
244- switch runtime .GOOS {
245- case "windows" :
246- cmd = "rundll32"
247- args = []string {"url.dll,FileProtocolHandler" , urlToOpen }
248- case "darwin" :
249- cmd = "open"
250- args = []string {urlToOpen }
251- case "linux" :
252- cmd = "xdg-open"
253- args = []string {urlToOpen }
254- default :
255- return fmt .Errorf ("unsupported platform: %s" , runtime .GOOS )
256- }
257-
258- err := exec .CommandContext (ctx , cmd , args ... ).Start ()
259- if err != nil {
260- return fmt .Errorf ("failed to open browser: %w" , err )
261- }
262-
263- return nil
264- }
265-
266240// registerClient performs dynamic client registration
267241func registerClient (ctx context.Context , authMetadata * authorizationServerMetadata , redirectURI string , scopes []string ) (clientID , clientSecret string , err error ) {
268242 if authMetadata .RegistrationEndpoint == "" {
0 commit comments