mirror of
https://github.com/gomods/athens
synced 2026-02-03 14:20:31 +00:00
* Allow Athens to Propagate Authentication to Mod Download * update readme * add pattern matching to auth propagation * Propagate authentication to pre declared static host * quote redis test * fix flaky redis error message * fix config tests * fix config tests * Update config.dev.toml Co-authored-by: Ted Wexler <ted@stuckinacan.com> * gofmt Co-authored-by: Ted Wexler <ted@stuckinacan.com>
23 lines
492 B
Go
23 lines
492 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gomods/athens/pkg/auth"
|
|
)
|
|
|
|
type authkey struct{}
|
|
|
|
// WithAuth inserts the Authorization header
|
|
// into the request context
|
|
func WithAuth(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
user, password, ok := r.BasicAuth()
|
|
if ok {
|
|
ctx := auth.SetAuthInContext(r.Context(), auth.BasicAuth{User: user, Password: password})
|
|
r = r.WithContext(ctx)
|
|
}
|
|
h.ServeHTTP(w, r)
|
|
})
|
|
}
|