Repository: avenga/couper
Pull request #492 (2022-04-27 12:18:09)

Remove uid passing
Describe your changes!

---
<details>
    <summary>Reviewer checklist</summary>
    <ul>
        <li>Read PR description: a summary about the changes is required</li>
        <li>Changelog updated</li>
        <li>Documentation: docs/{Reference, Cli, ...}, Docker and cli help/usage</li>
        <li>Pulled branch, manually tested</li>
        <li>Verified requirements are met</li>
        <li>Reviewed the code</li>
        <li>Reviewed the related tests</li>
    </ul>
</details>



Patch:
diff --git a/accesscontrol/jwk/jwks.go b/accesscontrol/jwk/jwks.go
index b59f4467..6c07ce19 100644
--- a/accesscontrol/jwk/jwks.go
+++ b/accesscontrol/jwk/jwks.go
@@ -94,7 +94,7 @@ func (j *JWKS) GetKey(kid string, alg string, use string) (*JWK, error) {
 func (j *JWKS) getKeys(kid string) ([]*JWK, error) {
 	var keys []*JWK
 
-	jwksData, err := j.Data("")
+	jwksData, err := j.Data()
 	if err != nil {
 		return nil, err
 	}
@@ -112,8 +112,8 @@ func (j *JWKS) getKeys(kid string) ([]*JWK, error) {
 	return keys, nil
 }
 
-func (j *JWKS) Data(uid string) (*JWKSData, error) {
-	data, err := j.syncedJSON.Data(uid)
+func (j *JWKS) Data() (*JWKSData, error) {
+	data, err := j.syncedJSON.Data()
 	if err != nil {
 		return nil, err
 	}
diff --git a/accesscontrol/jwt.go b/accesscontrol/jwt.go
index c116ed1a..855d514f 100644
--- a/accesscontrol/jwt.go
+++ b/accesscontrol/jwt.go
@@ -224,10 +224,9 @@ func (j *JWT) Validate(req *http.Request) error {
 		return err
 	}
 
-	ctx := req.Context()
 	if j.jwks != nil {
-		// load JWKS if needed and associate with request uid
-		j.jwks.Data(ctx.Value(request.UID).(string))
+		// load JWKS if needed
+		j.jwks.Data()
 	}
 
 	parser := newParser(j.algorithms, iss, aud)
@@ -249,6 +248,7 @@ func (j *JWT) Validate(req *http.Request) error {
 		return errors.JwtTokenInvalid.With(err)
 	}
 
+	ctx := req.Context()
 	acMap, ok := ctx.Value(request.AccessControls).(map[string]interface{})
 	if !ok {
 		acMap = make(map[string]interface{})
diff --git a/config/ac_oauth2.go b/config/ac_oauth2.go
index ff2f638c..b74a0572 100644
--- a/config/ac_oauth2.go
+++ b/config/ac_oauth2.go
@@ -100,7 +100,7 @@ func (oa *OAuth2AC) GetScope() string {
 	return *oa.Scope
 }
 
-func (oa *OAuth2AC) GetAuthorizationEndpoint(_ string) (string, error) {
+func (oa *OAuth2AC) GetAuthorizationEndpoint() (string, error) {
 	return oa.AuthorizationEndpoint, nil
 }
 
@@ -113,6 +113,6 @@ func (oa *OAuth2AC) GetTokenEndpointAuthMethod() *string {
 }
 
 // GetVerifierMethod retrieves the verifier method (ccm_s256 or state)
-func (oa *OAuth2AC) GetVerifierMethod(_ string) (string, error) {
+func (oa *OAuth2AC) GetVerifierMethod() (string, error) {
 	return oa.VerifierMethod, nil
 }
diff --git a/config/oauth2.go b/config/oauth2.go
index cbdbcb97..65d2d676 100644
--- a/config/oauth2.go
+++ b/config/oauth2.go
@@ -13,7 +13,7 @@ type OAuth2AS interface {
 // OAuth2AcAS represents the authorization server configuration for OAuth2 clients using the authorization code flow.
 type OAuth2AcAS interface {
 	OAuth2AS
-	GetAuthorizationEndpoint(uid string) (string, error)
+	GetAuthorizationEndpoint() (string, error)
 }
 
 // OidcAS represents the OIDC server configuration for OIDC clients.
@@ -38,15 +38,15 @@ type OAuth2AcClient interface {
 	GetGrantType() string
 	GetName() string
 	// GetVerifierMethod retrieves the verifier method (ccm_s256, nonce or state)
-	GetVerifierMethod(uid string) (string, error)
+	GetVerifierMethod() (string, error)
 }
 
 // OAuth2Authorization represents the configuration for the OAuth2 authorization URL function
 type OAuth2Authorization interface {
 	Inline
-	GetAuthorizationEndpoint(uid string) (string, error)
+	GetAuthorizationEndpoint() (string, error)
 	GetClientID() string
 	GetName() string
 	GetScope() string
-	GetVerifierMethod(uid string) (string, error)
+	GetVerifierMethod() (string, error)
 }
diff --git a/eval/lib/oauth2.go b/eval/lib/oauth2.go
index e31b1109..da8623e6 100644
--- a/eval/lib/oauth2.go
+++ b/eval/lib/oauth2.go
@@ -46,8 +46,7 @@ func NewOAuthAuthorizationUrlFunction(ctx *hcl.EvalContext, oauth2Configs []conf
 				return emptyStringVal, fmt.Errorf("undefined reference: %s", label)
 			}
 
-			uid := seetie.ToString(seetie.ValueToMap(ctx.Variables["request"])["id"])
-			authorizationEndpoint, err := oauth2.GetAuthorizationEndpoint(uid)
+			authorizationEndpoint, err := oauth2.GetAuthorizationEndpoint()
 			if err != nil {
 				return emptyStringVal, err
 			}
@@ -89,7 +88,7 @@ func NewOAuthAuthorizationUrlFunction(ctx *hcl.EvalContext, oauth2Configs []conf
 				query.Set("scope", scope)
 			}
 
-			verifierMethod, err := oauth2.GetVerifierMethod(uid)
+			verifierMethod, err := oauth2.GetVerifierMethod()
 			if err != nil {
 				return cty.StringVal(""), err
 			}
diff --git a/json/synced_json.go b/json/synced_json.go
index 4042a89b..ffcf6766 100644
--- a/json/synced_json.go
+++ b/json/synced_json.go
@@ -90,7 +90,7 @@ func (s *SyncedJSON) sync(ctx context.Context) {
 	}
 }
 
-func (s *SyncedJSON) Data(_ string) (interface{}, error) {
+func (s *SyncedJSON) Data() (interface{}, error) {
 	if s.fileMode {
 		return s.data, nil
 	}
diff --git a/oauth2/abstract_auth_client.go b/oauth2/abstract_auth_client.go
index 49d61eb8..156c7dca 100644
--- a/oauth2/abstract_auth_client.go
+++ b/oauth2/abstract_auth_client.go
@@ -10,7 +10,6 @@ import (
 	"strings"
 
 	"github.com/avenga/couper/config"
-	"github.com/avenga/couper/config/request"
 	"github.com/avenga/couper/errors"
 	"github.com/avenga/couper/eval"
 	"github.com/avenga/couper/eval/lib"
@@ -113,5 +112,5 @@ func getVerifierMethod(ctx context.Context, conf interface{}) (string, error) {
 	if !ok {
 		return "", fmt.Errorf("could not obtain verifier method configuration")
 	}
-	return clientConf.GetVerifierMethod(ctx.Value(request.UID).(string))
+	return clientConf.GetVerifierMethod()
 }
diff --git a/oauth2/auth_code_client.go b/oauth2/auth_code_client.go
index a1d06931..07efbbb2 100644
--- a/oauth2/auth_code_client.go
+++ b/oauth2/auth_code_client.go
@@ -36,7 +36,7 @@ func NewAuthCodeClient(acClientConf config.OAuth2AcClient, oauth2AsConf config.O
 
 	switch acClientConf.(type) {
 	case *config.OAuth2AC:
-		verifierMethod, err := acClientConf.GetVerifierMethod("")
+		verifierMethod, err := acClientConf.GetVerifierMethod()
 		if err != nil {
 			return nil, err
 		}
diff --git a/oauth2/oidc/config.go b/oauth2/oidc/config.go
index 0106e9bf..88a997b1 100644
--- a/oauth2/oidc/config.go
+++ b/oauth2/oidc/config.go
@@ -88,11 +88,11 @@ func (c *Config) Backends() map[string]http.RoundTripper {
 }
 
 // GetVerifierMethod retrieves the verifier method (ccm_s256 or nonce)
-func (c *Config) GetVerifierMethod(uid string) (string, error) {
+func (c *Config) GetVerifierMethod() (string, error) {
 	c.jmu.RLock()
 	if c.VerifierMethod == "" {
 		c.jmu.RUnlock()
-		_, err := c.Data(uid)
+		_, err := c.Data()
 		if err != nil {
 			return "", err
 		}
@@ -103,8 +103,8 @@ func (c *Config) GetVerifierMethod(uid string) (string, error) {
 	return c.VerifierMethod, nil
 }
 
-func (c *Config) GetAuthorizationEndpoint(uid string) (string, error) {
-	openidConfigurationData, err := c.Data(uid)
+func (c *Config) GetAuthorizationEndpoint() (string, error) {
+	openidConfigurationData, err := c.Data()
 	if err != nil {
 		return "", err
 	}
@@ -113,7 +113,7 @@ func (c *Config) GetAuthorizationEndpoint(uid string) (string, error) {
 }
 
 func (c *Config) GetIssuer() (string, error) {
-	openidConfigurationData, err := c.Data("")
+	openidConfigurationData, err := c.Data()
 	if err != nil {
 		return "", err
 	}
@@ -122,7 +122,7 @@ func (c *Config) GetIssuer() (string, error) {
 }
 
 func (c *Config) GetTokenEndpoint() (string, error) {
-	openidConfigurationData, err := c.Data("")
+	openidConfigurationData, err := c.Data()
 	if err != nil {
 		return "", err
 	}
@@ -131,7 +131,7 @@ func (c *Config) GetTokenEndpoint() (string, error) {
 }
 
 func (c *Config) GetUserinfoEndpoint() (string, error) {
-	openidConfigurationData, err := c.Data("")
+	openidConfigurationData, err := c.Data()
 	if err != nil {
 		return "", err
 	}
@@ -139,8 +139,8 @@ func (c *Config) GetUserinfoEndpoint() (string, error) {
 	return openidConfigurationData.UserinfoEndpoint, nil
 }
 
-func (c *Config) Data(uid string) (*OpenidConfiguration, error) {
-	data, err := c.syncedJSON.Data(uid)
+func (c *Config) Data() (*OpenidConfiguration, error) {
+	data, err := c.syncedJSON.Data()
 	if err != nil {
 		return nil, err
 	}


Test patch:
diff --git a/accesscontrol/jwk/jwks_test.go b/accesscontrol/jwk/jwks_test.go
index 67d6f2ed..f98bbfb1 100644
--- a/accesscontrol/jwk/jwks_test.go
+++ b/accesscontrol/jwk/jwks_test.go
@@ -66,7 +66,7 @@ func Test_JWKS_Load(t *testing.T) {
 		t.Run(tt.name, func(subT *testing.T) {
 			jwks, err := jwk.NewJWKS("file:"+tt.file, "", nil)
 			helper.Must(err)
-			_, err = jwks.Data("")
+			_, err = jwks.Data()
 			if err != nil && tt.expParsed {
 				subT.Error("no jwks parsed")
 			}
@@ -95,7 +95,7 @@ func Test_JWKS_GetSigKeyForToken(t *testing.T) {
 			helper := test.New(subT)
 			jwks, err := jwk.NewJWKS("file:"+tt.file, "", nil)
 			helper.Must(err)
-			_, err = jwks.Data("")
+			_, err = jwks.Data()
 			helper.Must(err)
 			token := &jwt.Token{Header: map[string]interface{}{"kid": tt.kid, "alg": tt.alg}}
 			jwk, err := jwks.GetSigKeyForToken(token)
@@ -147,7 +147,7 @@ func Test_JWKS_GetKey(t *testing.T) {
 			helper := test.New(subT)
 			jwks, err := jwk.NewJWKS("file:"+tt.file, "", nil)
 			helper.Must(err)
-			_, err = jwks.Data("")
+			_, err = jwks.Data()
 			helper.Must(err)
 			jwk, err := jwks.GetKey(tt.kid, tt.alg, tt.use)
 			if jwk == nil && tt.expFound {