@@ -7,10 +7,10 @@ import (
7
7
)
8
8
9
9
type AuthConfig struct {
10
- Enabled bool `default:"false"`
11
- User string `envconfig:"AUTH_USER " default:"orbiter"`
12
- Pass string `envconfig:"AUTH_PASS " default:"orbiter"`
13
- Realm string `envconfig:"AUTH_REALM " default:"Restricted"`
10
+ AuthEnabled bool `split_words:"true" default:"false"`
11
+ AuthUser string `split_words:"true " default:"orbiter"`
12
+ AuthPass string `split_words:"true " default:"orbiter"`
13
+ AuthRealm string `split_words:"true " default:"Restricted"`
14
14
}
15
15
16
16
func wrap (h http.HandlerFunc , funx ... func (http.HandlerFunc ) http.HandlerFunc ) http.HandlerFunc {
@@ -24,24 +24,30 @@ func basicAuth(h http.HandlerFunc) http.HandlerFunc {
24
24
return func (w http.ResponseWriter , r * http.Request ) {
25
25
26
26
var ac AuthConfig
27
- e := envconfig .Process ("ORBITER " , & ac )
27
+ e := envconfig .Process ("orbiter " , & ac )
28
28
if e != nil {
29
29
logrus .Fatal (e .Error ())
30
30
}
31
31
32
- w .Header ().Set ("WWW-Authenticate" , `Basic realm="` + ac .Realm + `"` )
32
+ w .Header ().Set ("WWW-Authenticate" , `Basic realm="` + ac .AuthRealm + `"` )
33
33
34
34
u , p , ok := r .BasicAuth ()
35
35
if ok == false {
36
+ logrus .Error ("No Authentication supplied" )
36
37
w .WriteHeader (401 )
37
38
w .Write ([]byte ("Not Authorized" ))
39
+ return
38
40
}
39
41
40
- if ac .User != u || ac .Pass != p {
42
+ if ac .AuthUser != u || ac .AuthPass != p {
43
+ logrus .Warnf ("Invalid username or password for user %s" , u )
41
44
w .WriteHeader (401 )
42
45
w .Write ([]byte ("Invalid username or password" ))
46
+ return
43
47
}
44
48
49
+ logrus .Infof ("Succesfully authenticated with user: %s" , u )
50
+
45
51
h .ServeHTTP (w , r )
46
52
}
47
53
0 commit comments