From 28f408755ea3a8257383856f5e606cd5b51ceb02 Mon Sep 17 00:00:00 2001
From: Fabian Seidl <fabian.seidl@h-da.de>
Date: Fri, 15 Mar 2024 08:16:23 +0100
Subject: [PATCH] fix issue with missing credentials in ctx via gRPC gateway

---
 controller/http.go | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/controller/http.go b/controller/http.go
index dae22922b..1261577ac 100644
--- a/controller/http.go
+++ b/controller/http.go
@@ -42,7 +42,9 @@ func run() error {
 
 	// Register gRPC server endpoint
 	// Note: Make sure the gRPC server is running properly and accessible
-	mux := runtime.NewServeMux()
+	mux := runtime.NewServeMux(
+		runtime.WithIncomingHeaderMatcher(customHeaderMatcher),
+	)
 
 	err := registerHttpHandler(mux)
 
@@ -162,3 +164,14 @@ func metricsHandler(mux *runtime.ServeMux) error {
 
 	return nil
 }
+
+// customHeaderMatcher passes custom key-value pairs within headers to be added to the outgoing context of gRPC-Gateway.
+// Use "authorize: token" in header for authorization after login.
+func customHeaderMatcher(key string) (string, bool) {
+	switch key {
+	case "Authorize":
+		return key, true
+	default:
+		return runtime.DefaultHeaderMatcher(key)
+	}
+}
-- 
GitLab