Skip to content

Commit

Permalink
auth: add NullBackend for verify-only instances
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Nov 13, 2023
1 parent 189b1cc commit 96d4aa7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion auth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ type Backend interface {
Authenticate(username, password string) error
}

type NullBackend struct {
}

func (b *NullBackend) Authenticate(username, password string) error {
return fmt.Errorf("invalid username/password")
}

func NewBackend(conf *Config, infoLog, dbgLog *log.Logger) (Backend, error) {
if infoLog == nil {
infoLog = log.New(io.Discard, "", 0)
Expand All @@ -63,5 +70,6 @@ func NewBackend(conf *Config, infoLog, dbgLog *log.Logger) (Backend, error) {
if conf.Whawty != nil {
return NewWhawtyAuthBackend(conf.Whawty, infoLog, dbgLog)
}
return nil, fmt.Errorf("no valid authentication backend found in configuration")
infoLog.Printf("auth: no valid backend configuration found - this instance will only verify cookies")
return &NullBackend{}, nil
}

0 comments on commit 96d4aa7

Please sign in to comment.