diff --git a/conf/configuration.go b/conf/configuration.go index 49d356f87..20d222ce5 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -63,6 +63,7 @@ type configOptions struct { // DevFlags. These are used to enable/disable debugging and incomplete features DevLogSourceLine bool DevAutoCreateAdminPassword string + DevAutoLoginUsername string DevPreCacheAlbumArtwork bool DevFastAccessCoverArt bool DevOldCacheLayout bool @@ -220,6 +221,7 @@ func init() { // DevFlags. These are used to enable/disable debugging and incomplete features viper.SetDefault("devlogsourceline", false) viper.SetDefault("devautocreateadminpassword", "") + viper.SetDefault("devautologinusername", "") viper.SetDefault("devprecachealbumartwork", false) viper.SetDefault("devoldcachelayout", false) viper.SetDefault("devFastAccessCoverArt", false) diff --git a/server/auth.go b/server/auth.go index 1fb3dca2a..65c202d0f 100644 --- a/server/auth.go +++ b/server/auth.go @@ -207,6 +207,10 @@ func UsernameFromReverseProxyHeader(r *http.Request) string { return username } +func UsernameFromConfig(r *http.Request) string { + return conf.Server.DevAutoLoginUsername +} + func contextWithUser(ctx context.Context, ds model.DataStore, username string) (context.Context, error) { user, err := ds.User(ctx).FindByUsername(username) if err == nil { @@ -235,7 +239,7 @@ func authenticateRequest(ds model.DataStore, r *http.Request, findUsernameFns .. func Authenticator(ds model.DataStore) func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx, err := authenticateRequest(ds, r, UsernameFromToken, UsernameFromReverseProxyHeader) + ctx, err := authenticateRequest(ds, r, UsernameFromConfig, UsernameFromToken, UsernameFromReverseProxyHeader) if err != nil { _ = rest.RespondWithError(w, http.StatusUnauthorized, "Not authenticated") return @@ -268,9 +272,12 @@ func JWTRefresher(next http.Handler) http.Handler { } func handleLoginFromHeaders(ds model.DataStore, r *http.Request) map[string]interface{} { - username := UsernameFromReverseProxyHeader(r) + username := UsernameFromConfig(r) if username == "" { - return nil + username = UsernameFromReverseProxyHeader(r) + if username == "" { + return nil + } } userRepo := ds.User(r.Context())