diff --git a/cmd/rdpgw/common/remote.go b/cmd/rdpgw/common/remote.go
index 9e919425263883bdc680420347ae76bd4912c6fa..f835e6e12f495e4e7ebf01acfa6ba424b2af48eb 100644
--- a/cmd/rdpgw/common/remote.go
+++ b/cmd/rdpgw/common/remote.go
@@ -2,6 +2,7 @@ package common
 
 import (
 	"context"
+	"github.com/jcmturner/goidentity/v6"
 	"log"
 	"net"
 	"net/http"
@@ -44,6 +45,18 @@ func EnrichContext(next http.Handler) http.Handler {
 	})
 }
 
+func FixKerberosContext(next http.Handler) http.Handler {
+	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		ctx := r.Context()
+
+		id := goidentity.FromHTTPRequestContext(r)
+		if id != nil {
+			ctx = context.WithValue(ctx, UsernameCtx, id.UserName())
+		}
+		next.ServeHTTP(w, r.WithContext(ctx))
+	})
+}
+
 func GetClientIp(ctx context.Context) string {
 	s, ok := ctx.Value(ClientIPCtx).(string)
 	if !ok {
diff --git a/cmd/rdpgw/main.go b/cmd/rdpgw/main.go
index 6d91b79a81861b339803003568857a2a029d9376..d7a78fc77df25f4728218ac8b7b4b2216e015daf 100644
--- a/cmd/rdpgw/main.go
+++ b/cmd/rdpgw/main.go
@@ -215,7 +215,7 @@ func main() {
 		}
 		http.Handle("/remoteDesktopGateway/", common.EnrichContext(
 			spnego.SPNEGOKRB5Authenticate(
-				http.HandlerFunc(gw.HandleGatewayProtocol),
+				common.FixKerberosContext(http.HandlerFunc(gw.HandleGatewayProtocol)),
 				keytab,
 				service.Logger(log.Default()))),
 		)
diff --git a/go.mod b/go.mod
index ad14f4b98b3b4c7d61d4537463fd1c871a409a2b..01c99e0e337a4bf2dfcbf7690a355b9c3a116224 100644
--- a/go.mod
+++ b/go.mod
@@ -11,6 +11,7 @@ require (
 	github.com/gorilla/sessions v1.2.1
 	github.com/gorilla/websocket v1.5.0
 	github.com/jcmturner/gofork v1.7.6
+	github.com/jcmturner/goidentity/v6 v6.0.1
 	github.com/knadh/koanf v1.4.2
 	github.com/msteinert/pam v1.0.0
 	github.com/patrickmn/go-cache v2.1.0+incompatible
@@ -31,7 +32,6 @@ require (
 	github.com/hashicorp/go-uuid v1.0.3 // indirect
 	github.com/jcmturner/aescts/v2 v2.0.0 // indirect
 	github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
-	github.com/jcmturner/goidentity/v6 v6.0.1 // indirect
 	github.com/jcmturner/rpc/v2 v2.0.3 // indirect
 	github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
 	github.com/mitchellh/copystructure v1.2.0 // indirect