auth_handler.go: only inject oauth store into handler

Previously we were injecting the whole oauth handler chain into this function,
which meant we were essentially writing unit tests to test our tests. Let's push
some of this logic into the source code.

Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
Andrew Keesler
2020-11-04 10:35:26 -05:00
parent 4f95e6a372
commit e8f433643f
2 changed files with 16 additions and 17 deletions
+14 -2
View File
@@ -8,7 +8,7 @@ import (
"fmt"
"net/http"
"github.com/ory/fosite"
"github.com/ory/fosite/compose"
"golang.org/x/oauth2"
"k8s.io/klog/v2"
@@ -26,11 +26,23 @@ type IDPListGetter interface {
func NewHandler(
issuer string,
idpListGetter IDPListGetter,
oauthHelper fosite.OAuth2Provider,
oauthStore interface{},
generateState func() (state.State, error),
generatePKCE func() (pkce.Code, error),
generateNonce func() (nonce.Nonce, error),
) http.Handler {
oauthHelper := compose.Compose(
&compose.Config{},
oauthStore,
&compose.CommonStrategy{
// Shouldn't need any of this - we aren't doing auth code stuff, issuing ID tokens, or signing
// anything yet.
},
nil, // hasher, shouldn't need this - we aren't doing any client auth...yet?
compose.OAuth2AuthorizeExplicitFactory,
compose.OpenIDConnectExplicitFactory,
compose.OAuth2PKCEFactory,
)
return httperr.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
if r.Method != http.MethodPost && r.Method != http.MethodGet {
// https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest