mirror of
https://github.com/weaveworks/scope.git
synced 2026-05-04 16:29:24 +00:00
20 lines
495 B
Go
20 lines
495 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/weaveworks/common/user"
|
|
)
|
|
|
|
// AuthenticateUser propagates the user ID from HTTP headers back to the request's context.
|
|
var AuthenticateUser = Func(func(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
_, ctx, err := user.ExtractFromHTTPRequest(r)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusUnauthorized)
|
|
return
|
|
}
|
|
next.ServeHTTP(w, r.WithContext(ctx))
|
|
})
|
|
})
|