diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 49016bb..e5ca513 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - go: ['1.14', '1.15'] + go: ['1.14', '1.15', '1.16'] name: Go ${{ matrix.go }} test steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index 871b03d..41c5d85 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ For your convinience you can find the relevant standards linked below. | <1.13 | :x: | | 1.14 | :white_check_mark: | | 1.15 | :white_check_mark: | +| 1.16 | :white_check_mark: | ## Why another library diff --git a/go.mod b/go.mod index 5dc5249..49abf7c 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/gorilla/schema v1.2.0 github.com/gorilla/securecookie v1.1.1 github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect - github.com/sirupsen/logrus v1.8.0 + github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.7.0 golang.org/x/net v0.0.0-20200904194848-62affa334b73 // indirect golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 diff --git a/go.sum b/go.sum index 3cde192..fe24a74 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= -github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -143,8 +141,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU= -github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/pkg/client/rp/cli/cli.go b/pkg/client/rp/cli/cli.go index 6cbb364..a00f0bd 100644 --- a/pkg/client/rp/cli/cli.go +++ b/pkg/client/rp/cli/cli.go @@ -13,13 +13,14 @@ const ( loginPath = "/login" ) -func CodeFlow(relyingParty rp.RelyingParty, callbackPath, port string, stateProvider func() string) *oidc.Tokens { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() +func CodeFlow(ctx context.Context, relyingParty rp.RelyingParty, callbackPath, port string, stateProvider func() string) *oidc.Tokens { + codeflowCtx, codeflowCancel := context.WithCancel(ctx) + defer codeflowCancel() + + tokenChan := make(chan *oidc.Tokens, 1) - var token *oidc.Tokens callback := func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens, state string) { - token = tokens + tokenChan <- tokens msg := "

Success!

" msg = msg + "

You are authenticated and can now return to the CLI.

" w.Write([]byte(msg)) @@ -27,9 +28,9 @@ func CodeFlow(relyingParty rp.RelyingParty, callbackPath, port string, stateProv http.Handle(loginPath, rp.AuthURLHandler(stateProvider, relyingParty)) http.Handle(callbackPath, rp.CodeExchangeHandler(callback, relyingParty)) - utils.StartServer(ctx, port) + utils.StartServer(codeflowCtx, ":"+port) utils.OpenBrowser("http://localhost:" + port + loginPath) - return token + return <-tokenChan } diff --git a/pkg/utils/http.go b/pkg/utils/http.go index 6632053..27f96f9 100644 --- a/pkg/utils/http.go +++ b/pkg/utils/http.go @@ -97,7 +97,11 @@ func StartServer(ctx context.Context, port string) { go func() { <-ctx.Done() - err := server.Shutdown(ctx) - log.Fatalf("Shutdown(): %v", err) + ctxShutdown, cancelShutdown := context.WithTimeout(context.Background(), 5*time.Second) + defer cancelShutdown() + err := server.Shutdown(ctxShutdown) + if err != nil { + log.Fatalf("Shutdown(): %v", err) + } }() }