Update mautrix-go to add auth type to register requests

This commit is contained in:
Tulir Asokan 2021-03-04 19:35:07 +02:00
parent e043788037
commit 0b5eeef689
4 changed files with 13 additions and 6 deletions

View file

@ -125,14 +125,14 @@ func (helper *CryptoHelper) loginBot() (*mautrix.Client, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get supported login flows: %w", err) return nil, fmt.Errorf("failed to get supported login flows: %w", err)
} }
if !flows.HasFlow(mautrix.AuthTypeAppservice) { if !flows.HasFlow(mautrix.AuthTypeHalfyAppservice) {
return nil, fmt.Errorf("homeserver does not support appservice login") return nil, fmt.Errorf("homeserver does not support appservice login")
} }
// We set the API token to the AS token here to authenticate the appservice login // We set the API token to the AS token here to authenticate the appservice login
// It'll get overridden after the login // It'll get overridden after the login
client.AccessToken = helper.bridge.AS.Registration.AppToken client.AccessToken = helper.bridge.AS.Registration.AppToken
resp, err := client.Login(&mautrix.ReqLogin{ resp, err := client.Login(&mautrix.ReqLogin{
Type: mautrix.AuthTypeAppservice, Type: mautrix.AuthTypeHalfyAppservice,
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())}, Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())},
DeviceID: deviceID, DeviceID: deviceID,
InitialDeviceDisplayName: "WhatsApp Bridge", InitialDeviceDisplayName: "WhatsApp Bridge",

2
go.mod
View file

@ -13,7 +13,7 @@ require (
gopkg.in/yaml.v2 v2.3.0 gopkg.in/yaml.v2 v2.3.0
maunium.net/go/mauflag v1.0.0 maunium.net/go/mauflag v1.0.0
maunium.net/go/maulogger/v2 v2.2.4 maunium.net/go/maulogger/v2 v2.2.4
maunium.net/go/mautrix v0.8.6 maunium.net/go/mautrix v0.8.7-0.20210304173449-b87e026581a5
) )
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.4.0-rc.3 replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.4.0-rc.3

4
go.sum
View file

@ -488,5 +488,9 @@ maunium.net/go/mautrix v0.8.5 h1:GNW8mde745M6H54Bpw9TJBAgME+iphS0kGvO+Vx1J0Q=
maunium.net/go/mautrix v0.8.5/go.mod h1:W3yDq9H5qSqo14Gu6rWF9uE5NXLIcmqF7oY0pv5lZs8= maunium.net/go/mautrix v0.8.5/go.mod h1:W3yDq9H5qSqo14Gu6rWF9uE5NXLIcmqF7oY0pv5lZs8=
maunium.net/go/mautrix v0.8.6 h1:JhiA8I+JE3+X8d/JqCIeweDA9lOVwbUlj86Y8RtvDMg= maunium.net/go/mautrix v0.8.6 h1:JhiA8I+JE3+X8d/JqCIeweDA9lOVwbUlj86Y8RtvDMg=
maunium.net/go/mautrix v0.8.6/go.mod h1:mckyHSKKyI0PQF2K9MgWMMDUWH1meCNggE28ILTLuMg= maunium.net/go/mautrix v0.8.6/go.mod h1:mckyHSKKyI0PQF2K9MgWMMDUWH1meCNggE28ILTLuMg=
maunium.net/go/mautrix v0.8.7-0.20210304173149-2ab811a476a6 h1:Nsoc66dDiB/PDwqFmh3MgsJtaG+0AzMzCNS4qRKKqRU=
maunium.net/go/mautrix v0.8.7-0.20210304173149-2ab811a476a6/go.mod h1:mckyHSKKyI0PQF2K9MgWMMDUWH1meCNggE28ILTLuMg=
maunium.net/go/mautrix v0.8.7-0.20210304173449-b87e026581a5 h1:Tbx+LMN+PkJBRdHPxfWh0CVicxrAgkKPF5KGIbdJT1g=
maunium.net/go/mautrix v0.8.7-0.20210304173449-b87e026581a5/go.mod h1:mckyHSKKyI0PQF2K9MgWMMDUWH1meCNggE28ILTLuMg=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=

View file

@ -752,9 +752,12 @@ func (user *User) UpdateDirectChats(chats map[id.UserID][]id.RoomID) {
var err error var err error
if user.bridge.Config.Homeserver.Asmux { if user.bridge.Config.Homeserver.Asmux {
urlPath := intent.BuildBaseURL("_matrix", "client", "unstable", "net.maunium.asmux", "dms") urlPath := intent.BuildBaseURL("_matrix", "client", "unstable", "net.maunium.asmux", "dms")
_, err = intent.MakeFullRequest(method, urlPath, http.Header{ _, err = intent.MakeFullRequest(mautrix.FullRequest{
"X-Asmux-Auth": {user.bridge.AS.Registration.AppToken}, Method: method,
}, chats, nil) URL: urlPath,
Headers: http.Header{"X-Asmux-Auth": {user.bridge.AS.Registration.AppToken}},
RequestJSON: chats,
})
} else { } else {
existingChats := make(map[id.UserID][]id.RoomID) existingChats := make(map[id.UserID][]id.RoomID)
err = intent.GetAccountData(event.AccountDataDirectChats.Type, &existingChats) err = intent.GetAccountData(event.AccountDataDirectChats.Type, &existingChats)