summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorJason Robinson <mail@jasonrobinson.me>2021-05-17 01:10:13 +0300
committerGitHub <noreply@github.com>2021-05-17 00:10:13 +0200
commit714a2ad7303f0d7b51b8b7f6c5f86f02a99c3524 (patch)
treed86c0a9ed9c3030ac771567cd10b7e8de73c2fca /bridge
parentfa8b96dfa17caf9f67e496deb2d2363cffaad1eb (diff)
downloadmatterbridge-msglm-714a2ad7303f0d7b51b8b7f6c5f86f02a99c3524.tar.gz
matterbridge-msglm-714a2ad7303f0d7b51b8b7f6c5f86f02a99c3524.tar.bz2
matterbridge-msglm-714a2ad7303f0d7b51b8b7f6c5f86f02a99c3524.zip
Add MxId/Token login option for Matrix (#1438)
* Add possibility for using MxId/Token with Matrix Makes it possible to configure a Matrix bot to use Matrix ID + Access token instead of username/password. This makes it possible to use the bot in environments where password login is disabled (for example SSO environments). Matrix user ID's are commonly referred to as "MXID's". I thought about (ab)using "Login" here but it felt like a bad idea given it's used as "username" for the password login. None of the other configuration items felt fitting. Closes #1429 * MxId -> MxID * Add err != nil to matrix.NewClient
Diffstat (limited to 'bridge')
-rw-r--r--bridge/config/config.go5
-rw-r--r--bridge/matrix/matrix.go41
2 files changed, 29 insertions, 17 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go
index b5e03fcf..a6e3c546 100644
--- a/bridge/config/config.go
+++ b/bridge/config/config.go
@@ -120,6 +120,7 @@ type Protocol struct {
MessageQueue int // IRC, size of message queue for flood control
MessageSplit bool // IRC, split long messages with newlines on MessageLength instead of clipping
Muc string // xmpp
+ MxID string // matrix
Name string // all protocols
Nick string // all protocols
NickFormatter string // mattermost, slack
@@ -142,7 +143,7 @@ type Protocol struct {
ReplaceNicks [][]string // all protocols
RemoteNickFormat string // all protocols
RunCommands []string // IRC
- Server string // IRC,mattermost,XMPP,discord
+ Server string // IRC,mattermost,XMPP,discord,matrix
SessionFile string // msteams,whatsapp
ShowJoinPart bool // all protocols
ShowTopicChange bool // slack
@@ -157,7 +158,7 @@ type Protocol struct {
Team string // mattermost, keybase
TeamID string // msteams
TenantID string // msteams
- Token string // gitter, slack, discord, api
+ Token string // gitter, slack, discord, api, matrix
Topic string // zulip
URL string // mattermost, slack // DEPRECATED
UseAPI bool // mattermost, slack
diff --git a/bridge/matrix/matrix.go b/bridge/matrix/matrix.go
index 69d0264b..9516a4fa 100644
--- a/bridge/matrix/matrix.go
+++ b/bridge/matrix/matrix.go
@@ -75,22 +75,33 @@ func New(cfg *bridge.Config) bridge.Bridger {
func (b *Bmatrix) Connect() error {
var err error
b.Log.Infof("Connecting %s", b.GetString("Server"))
- b.mc, err = matrix.NewClient(b.GetString("Server"), "", "")
- if err != nil {
- return err
- }
- resp, err := b.mc.Login(&matrix.ReqLogin{
- Type: "m.login.password",
- User: b.GetString("Login"),
- Password: b.GetString("Password"),
- Identifier: matrix.NewUserIdentifier(b.GetString("Login")),
- })
- if err != nil {
- return err
+ if b.GetString("MxID") != "" && b.GetString("Token") != "" {
+ b.mc, err = matrix.NewClient(
+ b.GetString("Server"), b.GetString("MxID"), b.GetString("Token"),
+ )
+ if err != nil {
+ return err
+ }
+ b.UserID = b.GetString("MxID")
+ b.Log.Info("Using existing Matrix credentials")
+ } else {
+ b.mc, err = matrix.NewClient(b.GetString("Server"), "", "")
+ if err != nil {
+ return err
+ }
+ resp, err := b.mc.Login(&matrix.ReqLogin{
+ Type: "m.login.password",
+ User: b.GetString("Login"),
+ Password: b.GetString("Password"),
+ Identifier: matrix.NewUserIdentifier(b.GetString("Login")),
+ })
+ if err != nil {
+ return err
+ }
+ b.mc.SetCredentials(resp.UserID, resp.AccessToken)
+ b.UserID = resp.UserID
+ b.Log.Info("Connection succeeded")
}
- b.mc.SetCredentials(resp.UserID, resp.AccessToken)
- b.UserID = resp.UserID
- b.Log.Info("Connection succeeded")
go b.handlematrix()
return nil
}