From 251c476e170377368fa55f61baf447cb421e27cf Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Mon, 27 Sep 2021 11:57:14 +0200 Subject: [PATCH] fixes --- example/client/github/github.go | 2 +- pkg/client/rp/relaying_party.go | 5 +++-- pkg/oidc/error.go | 28 ++++++++++++++-------------- pkg/op/keys_test.go | 9 +++++---- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/example/client/github/github.go b/example/client/github/github.go index f39c40b..35c7723 100644 --- a/example/client/github/github.go +++ b/example/client/github/github.go @@ -43,7 +43,7 @@ func main() { state := func() string { return uuid.New().String() } - token := cli.CodeFlow(relyingParty, callbackPath, port, state) + token := cli.CodeFlow(ctx, relyingParty, callbackPath, port, state) client := github.NewClient(relyingParty.OAuthConfig().Client(ctx, token.Token)) diff --git a/pkg/client/rp/relaying_party.go b/pkg/client/rp/relaying_party.go index 669a910..91fa324 100644 --- a/pkg/client/rp/relaying_party.go +++ b/pkg/client/rp/relaying_party.go @@ -170,17 +170,18 @@ func NewRelyingPartyOIDC(issuer, clientID, clientSecret, redirectURI string, sco return nil, err } } - endpoints, err := Discover(rp.issuer, rp.httpClient) + config, err := client.Discover(rp.issuer, rp.httpClient) if err != nil { return nil, err } + endpoints := GetEndpoints(config) rp.oauthConfig.Endpoint = endpoints.Endpoint rp.endpoints = endpoints return rp, nil } -//DefaultRPOpts is the type for providing dynamic options to the DefaultRP +//Option is the type for providing dynamic options to the relyingParty type Option func(*relyingParty) error //WithCookieHandler set a `CookieHandler` for securing the various redirects diff --git a/pkg/oidc/error.go b/pkg/oidc/error.go index 819fbcf..f1224de 100644 --- a/pkg/oidc/error.go +++ b/pkg/oidc/error.go @@ -52,6 +52,20 @@ func (e *Error) IsRedirectDisabled() bool { return e.redirectDisabled } +type errorType string + +const ( + InvalidRequest errorType = "invalid_request" + InvalidScope errorType = "invalid_scope" + InvalidClient errorType = "invalid_client" + InvalidGrant errorType = "invalid_grant" + UnauthorizedClient errorType = "unauthorized_client" + UnsupportedGrantType errorType = "unsupported_grant_type" + ServerError errorType = "server_error" + InteractionRequired errorType = "interaction_required" + LoginRequired errorType = "login_required" +) + var ( ErrInvalidRequest = func() *Error { return &Error{ @@ -117,17 +131,3 @@ func DefaultToServerError(err error, description string) *Error { } return oauth } - -type errorType string - -const ( - InvalidRequest errorType = "invalid_request" - InvalidScope errorType = "invalid_scope" - InvalidClient errorType = "invalid_client" - InvalidGrant errorType = "invalid_grant" - UnauthorizedClient errorType = "unauthorized_client" - UnsupportedGrantType errorType = "unsupported_grant_type" - ServerError errorType = "server_error" - InteractionRequired errorType = "interaction_required" - LoginRequired errorType = "login_required" -) diff --git a/pkg/op/keys_test.go b/pkg/op/keys_test.go index b02fbff..76a04a7 100644 --- a/pkg/op/keys_test.go +++ b/pkg/op/keys_test.go @@ -7,12 +7,13 @@ import ( "net/http/httptest" "testing" - "github.com/caos/oidc/pkg/oidc" - "github.com/caos/oidc/pkg/op" - "github.com/caos/oidc/pkg/op/mock" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "gopkg.in/square/go-jose.v2" + + "github.com/caos/oidc/pkg/oidc" + "github.com/caos/oidc/pkg/op" + "github.com/caos/oidc/pkg/op/mock" ) func TestKeys(t *testing.T) { @@ -34,7 +35,7 @@ func TestKeys(t *testing.T) { args: args{ k: func() op.KeyProvider { m := mock.NewMockKeyProvider(gomock.NewController(t)) - m.EXPECT().GetKeySet(gomock.Any()).Return(nil, oidc.ErrServerError) + m.EXPECT().GetKeySet(gomock.Any()).Return(nil, oidc.ErrServerError()) return m }(), },