Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 70bcd47a7066a847c3c9f5d4a111d2d8c8762e0d Author: Wim <wim@42.be> Date: Tue Jun 06 00:05:32 2017 +0000 Add token authentication (api) diff --git a/bridge/api/api.go b/bridge/api/api.go index d53fc3b..48715c5 100644 --- a/bridge/api/api.go +++ b/bridge/api/api.go @@ -46 +47 @@ 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" @@ -386 +3911 @@ 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 172cb10..4b3c425 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -677 +677 @@ 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 6fa9f1f..f53863a 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -6126 +61211 @@ 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 @@ -6196 +6248 @@ Buffer=1000  #OPTIONAL (default empty)  RemoteNickFormat="{NICK}"   + +  ###################################################################  #General configuration  ###################################################################