@marcel91200 / caddy Mirror · read-only / commits / 397e04eb
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

caddyauth: Add Metadata field to caddyauth.User (#3174)

* caddyauth: Add Metadata field to caddyauth.User * Apply gofmt * Tidy it up a bit Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>

Robin Lambertz committed Mar 27, 2020 at 18:10 UTC 397e04ebd9802d711a109822c3304bdf87b3a1ce
1 file changed +12 -1
modules/caddyhttp/caddyauth/caddyauth.go
+12 -1
@@ -77,7 +77,10 @@ func (a Authentication) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
77 }
78
79 repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
80 - repl.Set("http.authentication.user.id", user.ID)
80 + repl.Set("http.auth.user.id", user.ID)
81 + for k, v := range user.Metadata {
82 + repl.Set("http.auth.user."+k, v)
83 + }
84
85 return next.ServeHTTP(w, r)
86 }
@@ -92,7 +95,15 @@ type Authenticator interface {
95
96 // User represents an authenticated user.
97 type User struct {
98 + // The ID of the authenticated user.
99 ID string
100 +
101 + // Any other relevant data about this
102 + // user. Keys should be adhere to Caddy
103 + // conventions (snake_casing), as all
104 + // keys will be made available as
105 + // placeholders.
106 + Metadata map[string]string
107 }
108
109 // Interface guards