Skip to content

Commit

Permalink
Using map for multiple users/pass gianarb#33
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Bovo committed Aug 22, 2017
1 parent 2e5121d commit 59758b2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions api/basicauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
)

type AuthConfig struct {
AuthEnabled bool `split_words:"true" default:"false"`
AuthUser string `split_words:"true" default:"orbiter"`
AuthPass string `split_words:"true" default:"orbiter"`
AuthRealm string `split_words:"true" default:"Restricted"`
AuthEnabled bool `split_words:"true" default:"false"`
AuthRealm string `split_words:"true" default:"Restricted"`
AuthCredential map[string]string `split_words:"true" default:"orbiter:orbiter"`
}

func wrap(h http.HandlerFunc, funx ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc {
Expand Down Expand Up @@ -39,7 +38,7 @@ func basicAuth(h http.HandlerFunc) http.HandlerFunc {
return
}

if ac.AuthUser != u || ac.AuthPass != p {
if ac.AuthCredential[u] != p {
logrus.Warnf("Invalid username or password for user %s", u)
w.WriteHeader(401)
w.Write([]byte("Invalid username or password"))
Expand Down

0 comments on commit 59758b2

Please sign in to comment.