auto update custom user access token

This commit is contained in:
zhaoYangguang 2021-09-17 18:14:34 +08:00
parent ab6dcf4313
commit 98791fb757
1 changed files with 8 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"crypto/hmac"
"crypto/sha512"
"encoding/hex"
"strings"
"time"
"github.com/pkg/errors"
@ -99,10 +100,15 @@ func (puppet *Puppet) StartCustomMXID() error {
return err
}
resp, err := intent.Whoami()
if err != nil {
if strings.Index(err.Error(), "M_UNKNOWN_TOKEN (HTTP 401)") > -1 {
err, _ = puppet.customUser.UpdateAccessToken(puppet)
}
if err != nil {
puppet.clearCustomMXID()
return err
}
}
if resp.UserID != puppet.CustomMXID {
puppet.clearCustomMXID()
return ErrMismatchingMXID