loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit dfc3994b375e5e0a316a4d667d62813aa42f2ff4
parent fe0e370a3f12b935680de4eaea41c492568fa682
Author: Sebastian Mancke <sebastian.mancke@snabble.io>
Date:   Wed, 26 Dec 2018 23:41:23 +0100

Merge pull request #96 from magikstm/issue-94

let upstream middleware (e.g. fastcgi and cgi) know about authenticated user
Diffstat:
Mcaddy/handler.go | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/caddy/handler.go b/caddy/handler.go @@ -3,6 +3,7 @@ package caddy import ( "github.com/mholt/caddy/caddyhttp/httpserver" "github.com/tarent/loginsrv/login" + "context" "net/http" "strings" ) @@ -28,6 +29,12 @@ func (h *CaddyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, e //Fetch jwt token. If valid set a Caddy replacer for {user} userInfo, valid := h.loginHandler.GetToken(r) if valid { + // let upstream middleware (e.g. fastcgi and cgi) know about authenticated + // user; this replaces the request with a wrapped instance + r = r.WithContext(context.WithValue(r.Context(), + httpserver.RemoteUserCtxKey, userInfo.Sub)) + + // Provide username to be used in log by replacer repl := httpserver.NewReplacer(r, nil, "-") repl.Set("user", userInfo.Sub) }