From ad3cb0386b72a7f9d46b4a2068ff947570fa67ff Mon Sep 17 00:00:00 2001 From: Wim Date: Tue, 6 Jun 2017 00:05:32 +0200 Subject: Add token authentication (api) --- bridge/api/api.go | 6 ++++++ bridge/config/config.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'bridge') 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 -- cgit v1.2.3