summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/caddyauth
diff options
context:
space:
mode:
authorRobin Lambertz <unfiltered@roblab.la>2020-03-27 18:10:51 +0100
committerGitHub <noreply@github.com>2020-03-27 11:10:51 -0600
commit397e04ebd9802d711a109822c3304bdf87b3a1ce (patch)
tree34623c7375a590c60840779d8fc5bbb30f16afbd /modules/caddyhttp/caddyauth
parentd2c15bea1be777fabf39d2f0facbf7441e5cf1f1 (diff)
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>
Diffstat (limited to 'modules/caddyhttp/caddyauth')
-rw-r--r--modules/caddyhttp/caddyauth/caddyauth.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/modules/caddyhttp/caddyauth/caddyauth.go b/modules/caddyhttp/caddyauth/caddyauth.go
index dc1dc99..a6165d4 100644
--- a/modules/caddyhttp/caddyauth/caddyauth.go
+++ b/modules/caddyhttp/caddyauth/caddyauth.go
@@ -77,7 +77,10 @@ func (a Authentication) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
}
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
- repl.Set("http.authentication.user.id", user.ID)
+ repl.Set("http.auth.user.id", user.ID)
+ for k, v := range user.Metadata {
+ repl.Set("http.auth.user."+k, v)
+ }
return next.ServeHTTP(w, r)
}
@@ -92,7 +95,15 @@ type Authenticator interface {
// User represents an authenticated user.
type User struct {
+ // The ID of the authenticated user.
ID string
+
+ // Any other relevant data about this
+ // user. Keys should be adhere to Caddy
+ // conventions (snake_casing), as all
+ // keys will be made available as
+ // placeholders.
+ Metadata map[string]string
}
// Interface guards