diff options
author | Wim <wim@42.be> | 2017-06-06 00:05:32 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-06-06 00:05:32 +0200 |
commit | ad3cb0386b72a7f9d46b4a2068ff947570fa67ff (patch) | |
tree | 6bd08153f66d1e46765177842e36e58edac7573a | |
parent | 3a183cb218c6812964a70d2e75884ad7071d9c0c (diff) | |
download | matterbridge-msglm-ad3cb0386b72a7f9d46b4a2068ff947570fa67ff.tar.gz matterbridge-msglm-ad3cb0386b72a7f9d46b4a2068ff947570fa67ff.tar.bz2 matterbridge-msglm-ad3cb0386b72a7f9d46b4a2068ff947570fa67ff.zip |
Add token authentication (api)
-rw-r--r-- | bridge/api/api.go | 6 | ||||
-rw-r--r-- | bridge/config/config.go | 2 | ||||
-rw-r--r-- | matterbridge.toml.sample | 7 |
3 files changed, 14 insertions, 1 deletions
diff --git a/bridge/api/api.go b/bridge/api/api.go index d53fc3b4..48715c50 100644 --- a/bridge/api/api.go +++ b/bridge/api/api.go @@ -4,6 +4,7 @@ import ( "github.com/42wim/matterbridge/bridge/config" log "github.com/Sirupsen/logrus" "github.com/labstack/echo" + "github.com/labstack/echo/middleware" "github.com/zfjagann/golang-ring" "net/http" "sync" @@ -38,6 +39,11 @@ func New(cfg config.Protocol, account string, c chan config.Message) *Api { b.Config = &cfg b.Account = account b.Remote = c + if b.Config.Token != "" { + e.Use(middleware.KeyAuth(func(key string, c echo.Context) (bool, error) { + return key == b.Config.Token, nil + })) + } e.GET("/api/messages", b.handleMessages) e.POST("/api/message", b.handlePostMessage) go func() { diff --git a/bridge/config/config.go b/bridge/config/config.go index 172cb109..4b3c4250 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -67,7 +67,7 @@ type Protocol struct { ShowJoinPart bool // all protocols SkipTLSVerify bool // IRC, mattermost Team string // mattermost - Token string // gitter, slack, discord + Token string // gitter, slack, discord, api URL string // mattermost, slack, matrix UseAPI bool // mattermost, slack UseSASL bool // IRC diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 6fa9f1f4..f53863a9 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -612,6 +612,11 @@ BindAddress="127.0.0.1:4242" #Amount of messages to keep in memory Buffer=1000 +#Bearer token used for authentication +#curl -H "Authorization: Bearer token" http://localhost:4242/api/messages +#OPTIONAL (no authorization if token is empty) +Token="mytoken" + #RemoteNickFormat defines how remote users appear on this bridge #The string "{NICK}" (case sensitive) will be replaced by the actual nick / username. #The string "{BRIDGE}" (case sensitive) will be replaced by the sending bridge @@ -619,6 +624,8 @@ Buffer=1000 #OPTIONAL (default empty) RemoteNickFormat="{NICK}" + + ################################################################### #General configuration ################################################################### |