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/hmac"
"crypto/sha512" "crypto/sha512"
"encoding/hex" "encoding/hex"
"strings"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -100,8 +101,13 @@ func (puppet *Puppet) StartCustomMXID() error {
} }
resp, err := intent.Whoami() resp, err := intent.Whoami()
if err != nil { if err != nil {
puppet.clearCustomMXID() if strings.Index(err.Error(), "M_UNKNOWN_TOKEN (HTTP 401)") > -1 {
return err err, _ = puppet.customUser.UpdateAccessToken(puppet)
}
if err != nil {
puppet.clearCustomMXID()
return err
}
} }
if resp.UserID != puppet.CustomMXID { if resp.UserID != puppet.CustomMXID {
puppet.clearCustomMXID() puppet.clearCustomMXID()