Browse Source
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>
master
Robin Lambertz
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
12 additions and
1 deletions
-
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 := 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) |
|
|
return next.ServeHTTP(w, r) |
|
|
} |
|
|
} |
|
@ -92,7 +95,15 @@ type Authenticator interface { |
|
|
|
|
|
|
|
|
// User represents an authenticated user.
|
|
|
// User represents an authenticated user.
|
|
|
type User struct { |
|
|
type User struct { |
|
|
|
|
|
// The ID of the authenticated user.
|
|
|
ID string |
|
|
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
|
|
|
// Interface guards
|
|
|