Add hidden option to use appservice login for double puppeting
This commit is contained in:
parent
a87bb67be9
commit
e5ca572811
|
@ -65,19 +65,26 @@ func (puppet *Puppet) SwitchCustomMXID(accessToken string, mxid id.UserID) error
|
||||||
func (puppet *Puppet) loginWithSharedSecret(mxid id.UserID) (string, error) {
|
func (puppet *Puppet) loginWithSharedSecret(mxid id.UserID) (string, error) {
|
||||||
_, homeserver, _ := mxid.Parse()
|
_, homeserver, _ := mxid.Parse()
|
||||||
puppet.log.Debugfln("Logging into %s with shared secret", mxid)
|
puppet.log.Debugfln("Logging into %s with shared secret", mxid)
|
||||||
mac := hmac.New(sha512.New, []byte(puppet.bridge.Config.Bridge.LoginSharedSecretMap[homeserver]))
|
loginSecret := puppet.bridge.Config.Bridge.LoginSharedSecretMap[homeserver]
|
||||||
mac.Write([]byte(mxid))
|
|
||||||
client, err := puppet.bridge.newDoublePuppetClient(mxid, "")
|
client, err := puppet.bridge.newDoublePuppetClient(mxid, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to create mautrix client to log in: %v", err)
|
return "", fmt.Errorf("failed to create mautrix client to log in: %v", err)
|
||||||
}
|
}
|
||||||
resp, err := client.Login(&mautrix.ReqLogin{
|
req := mautrix.ReqLogin{
|
||||||
Type: mautrix.AuthTypePassword,
|
|
||||||
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(mxid)},
|
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: string(mxid)},
|
||||||
Password: hex.EncodeToString(mac.Sum(nil)),
|
|
||||||
DeviceID: "WhatsApp Bridge",
|
DeviceID: "WhatsApp Bridge",
|
||||||
InitialDeviceDisplayName: "WhatsApp Bridge",
|
InitialDeviceDisplayName: "WhatsApp Bridge",
|
||||||
})
|
}
|
||||||
|
if loginSecret == "appservice" {
|
||||||
|
client.AccessToken = puppet.bridge.AS.Registration.AppToken
|
||||||
|
req.Type = mautrix.AuthTypeAppservice
|
||||||
|
} else {
|
||||||
|
mac := hmac.New(sha512.New, []byte(loginSecret))
|
||||||
|
mac.Write([]byte(mxid))
|
||||||
|
req.Password = hex.EncodeToString(mac.Sum(nil))
|
||||||
|
req.Type = mautrix.AuthTypePassword
|
||||||
|
}
|
||||||
|
resp, err := client.Login(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue