|
@@ -2,7 +2,9 @@ package httplistener
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
4
|
"bytes"
|
|
5
|
+ "fmt"
|
5
|
6
|
"github.com/irccloud/irccat/dispatcher"
|
|
7
|
+ "github.com/spf13/viper"
|
6
|
8
|
"net/http"
|
7
|
9
|
)
|
8
|
10
|
|
|
@@ -17,6 +19,18 @@ func (hl *HTTPListener) genericHandler(w http.ResponseWriter, request *http.Requ
|
17
|
19
|
return
|
18
|
20
|
}
|
19
|
21
|
|
|
22
|
+ // Optional simple auth via token
|
|
23
|
+ secret := viper.GetString("http.listeners.generic.secret")
|
|
24
|
+ if secret != "" {
|
|
25
|
+ auth := request.Header.Get("Authorization")
|
|
26
|
+ expecting := fmt.Sprintf("Bearer %s", secret)
|
|
27
|
+ if auth != expecting {
|
|
28
|
+ http.Error(w, "Invalid Authorization", http.StatusUnauthorized)
|
|
29
|
+ log.Warningf("%s - Invalid Authorization!", request.RemoteAddr)
|
|
30
|
+ return
|
|
31
|
+ }
|
|
32
|
+ }
|
|
33
|
+
|
20
|
34
|
body := new(bytes.Buffer)
|
21
|
35
|
body.ReadFrom(request.Body)
|
22
|
36
|
message := body.String()
|