diff --git a/internal/oauth2/oauth2.go b/internal/oauth2/oauth2.go index be298b0..e0ad20b 100644 --- a/internal/oauth2/oauth2.go +++ b/internal/oauth2/oauth2.go @@ -9,11 +9,8 @@ import ( "log" "net/http" "net/url" - "os" - "os/signal" "strconv" "strings" - "syscall" "time" "github.com/go-jose/go-jose/v3" @@ -280,14 +277,9 @@ func WaitForCallback(clientConfig ClientConfig, serverConfig ServerConfig, hc *h } }() - signalChan := make(chan os.Signal, 1) - signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) - timeout := time.After(clientConfig.BrowserTimeout) select { - case <-signalChan: - return request, errors.New("interrupted") case <-timeout: return request, errors.New("timeout") case <-done: diff --git a/main.go b/main.go index 568c863..023da6d 100644 --- a/main.go +++ b/main.go @@ -3,10 +3,24 @@ package main import ( "fmt" "os" + "os/signal" + "syscall" "github.com/cloudentity/oauth2c/cmd" + "github.com/pterm/pterm" ) +func init() { + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) + + go func() { + <-c + pterm.Error.Println("Interrupted") + os.Exit(1) + }() +} + func main() { if err := cmd.NewOAuth2Cmd().Execute(); err != nil { fmt.Fprintln(os.Stderr, err)