mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-02 06:24:14 +00:00
Option to allow auto-login during development.
This commit is contained in:
parent
7b9b4e8486
commit
8dc8b5f95b
@ -64,6 +64,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
|
||||
@ -239,6 +240,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)
|
||||
|
||||
@ -292,6 +292,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 {
|
||||
@ -320,7 +324,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
|
||||
@ -353,9 +357,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())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user