Skip to content

Commit

Permalink
Refactor interruption (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbilski authored Sep 29, 2023
1 parent 404f381 commit d4bda65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 0 additions & 8 deletions internal/oauth2/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import (
"log"
"net/http"
"net/url"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

"github.com/go-jose/go-jose/v3"
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d4bda65

Please sign in to comment.