From 279d9732cd51f1c36646a9452538472441ffd176 Mon Sep 17 00:00:00 2001 From: Annie Elequin Date: Thu, 16 Sep 2021 18:36:30 -0400 Subject: [PATCH] new login from whatsapp --- crypto.go | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/crypto.go b/crypto.go index be5447f..2a0f943 100644 --- a/crypto.go +++ b/crypto.go @@ -121,32 +121,52 @@ func (helper *CryptoHelper) loginBot() (*mautrix.Client, error) { return nil, fmt.Errorf("failed to initialize client: %w", err) } client.Logger = helper.baseLog.Sub("Bot") + client.Client = helper.bridge.AS.HTTPClient + client.DefaultHTTPRetries = helper.bridge.AS.DefaultHTTPRetries flows, err := client.GetLoginFlows() if err != nil { return nil, fmt.Errorf("failed to get supported login flows: %w", err) } - if !flows.HasFlow(mautrix.AuthTypeAppservice) { - // TODO after synapse 1.22, turn this into an error - helper.log.Warnln("Encryption enabled in config, but homeserver does not advertise appservice login") - //return nil, fmt.Errorf("homeserver does not support appservice login") + if !flows.HasFlow(mautrix.AuthTypeHalfyAppservice) { + return nil, fmt.Errorf("homeserver does not support appservice login") } + // if !flows.HasFlow(mautrix.AuthTypeAppservice) { + // // TODO after synapse 1.22, turn this into an error + // helper.log.Warnln("Encryption enabled in config, but homeserver does not advertise 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 // It'll get overridden after the login client.AccessToken = helper.bridge.AS.Registration.AppToken resp, err := client.Login(&mautrix.ReqLogin{ - Type: mautrix.AuthTypeAppservice, + Type: mautrix.AuthTypeHalfyAppservice, Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())}, DeviceID: deviceID, - InitialDeviceDisplayName: "WhatsApp Bridge", + InitialDeviceDisplayName: "GroupMe Bridge", StoreCredentials: true, }) if err != nil { return nil, fmt.Errorf("failed to log in as bridge bot: %w", err) } - if len(deviceID) == 0 { - helper.store.DeviceID = resp.DeviceID - } + helper.store.DeviceID = resp.DeviceID return client, nil + + // client.AccessToken = helper.bridge.AS.Registration.AppToken + // resp, err := client.Login(&mautrix.ReqLogin{ + // Type: mautrix.AuthTypeAppservice, + // Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(helper.bridge.AS.BotMXID())}, + // DeviceID: deviceID, + // InitialDeviceDisplayName: "GroupMe Bridge", + // StoreCredentials: true, + // }) + // if err != nil { + // return nil, fmt.Errorf("failed to log in as bridge bot: %w", err) + // } + // if len(deviceID) == 0 { + // helper.store.DeviceID = resp.DeviceID + // } + // return client, nil } func (helper *CryptoHelper) Start() {