new login from whatsapp
This commit is contained in:
parent
ece37472c1
commit
279d9732cd
38
crypto.go
38
crypto.go
@ -121,32 +121,52 @@ func (helper *CryptoHelper) loginBot() (*mautrix.Client, error) {
|
|||||||
return nil, fmt.Errorf("failed to initialize client: %w", err)
|
return nil, fmt.Errorf("failed to initialize client: %w", err)
|
||||||
}
|
}
|
||||||
client.Logger = helper.baseLog.Sub("Bot")
|
client.Logger = helper.baseLog.Sub("Bot")
|
||||||
|
client.Client = helper.bridge.AS.HTTPClient
|
||||||
|
client.DefaultHTTPRetries = helper.bridge.AS.DefaultHTTPRetries
|
||||||
flows, err := client.GetLoginFlows()
|
flows, err := client.GetLoginFlows()
|
||||||
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) {
|
||||||
// TODO after synapse 1.22, turn this into an error
|
return nil, fmt.Errorf("homeserver does not support appservice login")
|
||||||
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.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
|
// 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: "GroupMe Bridge",
|
||||||
StoreCredentials: true,
|
StoreCredentials: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to log in as bridge bot: %w", err)
|
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
|
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() {
|
func (helper *CryptoHelper) Start() {
|
||||||
|
Loading…
Reference in New Issue
Block a user