2023-06-30 11:05:33 +00:00
|
|
|
package libgm
|
2023-06-30 09:54:08 +00:00
|
|
|
|
|
|
|
import (
|
2023-07-16 10:33:51 +00:00
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/rand"
|
|
|
|
"crypto/sha256"
|
2023-07-09 11:16:52 +00:00
|
|
|
"fmt"
|
2023-06-30 09:54:08 +00:00
|
|
|
"io"
|
2024-03-05 17:14:02 +00:00
|
|
|
"net"
|
2023-06-30 09:54:08 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2024-04-03 14:21:48 +00:00
|
|
|
"sync"
|
2023-06-30 09:54:08 +00:00
|
|
|
"time"
|
|
|
|
|
2023-07-16 10:23:44 +00:00
|
|
|
"github.com/google/uuid"
|
2023-06-30 09:54:08 +00:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
|
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/crypto"
|
2023-07-09 11:16:52 +00:00
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/events"
|
2023-07-17 13:51:31 +00:00
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/gmproto"
|
2023-06-30 09:54:08 +00:00
|
|
|
"go.mau.fi/mautrix-gmessages/libgm/util"
|
|
|
|
)
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
type AuthData struct {
|
2023-07-16 11:36:13 +00:00
|
|
|
// Keys used to encrypt communication with the phone
|
|
|
|
RequestCrypto *crypto.AESCTRHelper `json:"request_crypto,omitempty"`
|
|
|
|
// Key used to sign requests to refresh the tachyon auth token from the server
|
|
|
|
RefreshKey *crypto.JWK `json:"refresh_key,omitempty"`
|
|
|
|
// Identity of the paired phone and browser
|
2023-07-17 13:51:31 +00:00
|
|
|
Browser *gmproto.Device `json:"browser,omitempty"`
|
|
|
|
Mobile *gmproto.Device `json:"mobile,omitempty"`
|
2023-07-16 11:36:13 +00:00
|
|
|
// Key used to authenticate with the server
|
|
|
|
TachyonAuthToken []byte `json:"tachyon_token,omitempty"`
|
|
|
|
TachyonExpiry time.Time `json:"tachyon_expiry,omitempty"`
|
|
|
|
TachyonTTL int64 `json:"tachyon_ttl,omitempty"`
|
|
|
|
// Unknown encryption key, not used for anything
|
|
|
|
WebEncryptionKey []byte `json:"web_encryption_key,omitempty"`
|
2024-02-22 20:37:49 +00:00
|
|
|
|
|
|
|
SessionID uuid.UUID `json:"session_id,omitempty"`
|
2024-02-23 14:32:12 +00:00
|
|
|
DestRegID uuid.UUID `json:"dest_reg_id,omitempty"`
|
|
|
|
PairingID uuid.UUID `json:"pairing_id,omitempty"`
|
2024-02-22 20:37:49 +00:00
|
|
|
Cookies map[string]string `json:"cookies,omitempty"`
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
2023-07-16 11:36:13 +00:00
|
|
|
|
2024-02-23 12:53:19 +00:00
|
|
|
func (ad *AuthData) AuthNetwork() string {
|
|
|
|
if ad.Cookies != nil {
|
|
|
|
return util.GoogleNetwork
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-07-16 11:36:13 +00:00
|
|
|
const RefreshTachyonBuffer = 1 * time.Hour
|
|
|
|
|
2023-06-30 09:54:08 +00:00
|
|
|
type Proxy func(*http.Request) (*url.URL, error)
|
2023-07-15 22:45:19 +00:00
|
|
|
type EventHandler func(evt any)
|
2023-07-16 11:36:13 +00:00
|
|
|
|
2023-07-19 19:29:30 +00:00
|
|
|
type updateDedupItem struct {
|
|
|
|
id string
|
|
|
|
hash [32]byte
|
|
|
|
}
|
|
|
|
|
2023-06-30 09:54:08 +00:00
|
|
|
type Client struct {
|
|
|
|
Logger zerolog.Logger
|
|
|
|
evHandler EventHandler
|
|
|
|
sessionHandler *SessionHandler
|
|
|
|
|
2023-07-19 11:12:23 +00:00
|
|
|
longPollingConn io.Closer
|
|
|
|
listenID int
|
|
|
|
skipCount int
|
|
|
|
disconnecting bool
|
|
|
|
|
2024-04-05 09:54:49 +00:00
|
|
|
pingShortCircuit chan struct{}
|
|
|
|
nextDataReceiveCheck time.Time
|
|
|
|
nextDataReceiveCheckLock sync.Mutex
|
2023-07-19 21:58:39 +00:00
|
|
|
|
2023-07-19 19:29:30 +00:00
|
|
|
recentUpdates [8]updateDedupItem
|
2023-07-19 11:12:23 +00:00
|
|
|
recentUpdatesPtr int
|
|
|
|
|
2023-07-18 21:59:51 +00:00
|
|
|
conversationsFetchedOnce bool
|
|
|
|
|
2023-07-16 12:55:30 +00:00
|
|
|
AuthData *AuthData
|
2024-02-22 20:37:49 +00:00
|
|
|
cfg *gmproto.Config
|
2023-06-30 09:54:08 +00:00
|
|
|
|
2024-03-05 17:14:02 +00:00
|
|
|
httpTransport *http.Transport
|
|
|
|
http *http.Client
|
|
|
|
lphttp *http.Client
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 11:36:13 +00:00
|
|
|
func NewAuthData() *AuthData {
|
|
|
|
return &AuthData{
|
|
|
|
RequestCrypto: crypto.NewAESCTRHelper(),
|
|
|
|
RefreshKey: crypto.GenerateECDSAKey(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
func NewClient(authData *AuthData, logger zerolog.Logger) *Client {
|
2023-06-30 09:54:08 +00:00
|
|
|
sessionHandler := &SessionHandler{
|
2023-07-17 23:01:06 +00:00
|
|
|
responseWaiters: make(map[string]chan<- *IncomingRPCMessage),
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
2024-03-05 17:14:02 +00:00
|
|
|
transport := &http.Transport{
|
|
|
|
DialContext: (&net.Dialer{Timeout: 10 * time.Second}).DialContext,
|
|
|
|
TLSHandshakeTimeout: 10 * time.Second,
|
|
|
|
ResponseHeaderTimeout: 20 * time.Second,
|
|
|
|
}
|
2023-06-30 09:54:08 +00:00
|
|
|
cli := &Client{
|
2023-07-16 12:55:30 +00:00
|
|
|
AuthData: authData,
|
2023-06-30 09:54:08 +00:00
|
|
|
Logger: logger,
|
2023-07-09 11:16:52 +00:00
|
|
|
sessionHandler: sessionHandler,
|
2024-03-05 17:31:12 +00:00
|
|
|
|
|
|
|
httpTransport: transport,
|
|
|
|
http: &http.Client{Transport: transport, Timeout: 2 * time.Minute},
|
|
|
|
lphttp: &http.Client{Transport: transport, Timeout: 30 * time.Minute},
|
2023-07-19 21:58:39 +00:00
|
|
|
|
|
|
|
pingShortCircuit: make(chan struct{}),
|
2023-06-30 09:54:08 +00:00
|
|
|
}
|
|
|
|
sessionHandler.client = cli
|
2024-02-22 20:37:49 +00:00
|
|
|
var err error
|
|
|
|
cli.cfg, err = cli.FetchConfig()
|
2023-09-04 21:34:22 +00:00
|
|
|
if err != nil {
|
2024-02-22 20:37:49 +00:00
|
|
|
cli.Logger.Err(err).Msg("Failed to fetch web config")
|
|
|
|
} else if deviceID := cli.cfg.GetDeviceInfo().GetDeviceID(); deviceID != "" {
|
|
|
|
authData.SessionID, err = uuid.Parse(deviceID)
|
|
|
|
if err != nil {
|
|
|
|
cli.Logger.Err(err).Str("device_id", deviceID).Msg("Failed to parse device ID")
|
|
|
|
}
|
2023-09-04 21:34:22 +00:00
|
|
|
}
|
2023-06-30 09:54:08 +00:00
|
|
|
return cli
|
|
|
|
}
|
|
|
|
|
2023-08-02 12:07:02 +00:00
|
|
|
func (c *Client) CurrentSessionID() string {
|
|
|
|
return c.sessionHandler.sessionID
|
|
|
|
}
|
|
|
|
|
2023-06-30 09:54:08 +00:00
|
|
|
func (c *Client) SetEventHandler(eventHandler EventHandler) {
|
|
|
|
c.evHandler = eventHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) SetProxy(proxy string) error {
|
|
|
|
proxyParsed, err := url.Parse(proxy)
|
|
|
|
if err != nil {
|
|
|
|
c.Logger.Fatal().Err(err).Msg("Failed to set proxy")
|
|
|
|
}
|
2024-03-05 17:14:02 +00:00
|
|
|
c.httpTransport.Proxy = http.ProxyURL(proxyParsed)
|
2023-06-30 09:54:08 +00:00
|
|
|
c.Logger.Debug().Any("proxy", proxyParsed.Host).Msg("SetProxy")
|
|
|
|
return nil
|
|
|
|
}
|
2023-07-16 12:55:30 +00:00
|
|
|
|
2023-07-09 11:16:52 +00:00
|
|
|
func (c *Client) Connect() error {
|
2023-07-16 12:55:30 +00:00
|
|
|
if c.AuthData.TachyonAuthToken == nil {
|
|
|
|
return fmt.Errorf("no auth token")
|
|
|
|
} else if c.AuthData.Browser == nil {
|
|
|
|
return fmt.Errorf("not logged in")
|
|
|
|
}
|
|
|
|
|
2023-07-16 13:18:45 +00:00
|
|
|
err := c.refreshAuthToken()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to refresh auth token: %w", err)
|
2023-07-16 12:55:30 +00:00
|
|
|
}
|
2024-04-05 09:54:49 +00:00
|
|
|
c.bumpNextDataReceiveCheck(10 * time.Minute)
|
2023-07-16 12:55:30 +00:00
|
|
|
|
2024-02-22 20:37:49 +00:00
|
|
|
//webEncryptionKeyResponse, err := c.GetWebEncryptionKey()
|
|
|
|
//if err != nil {
|
|
|
|
// return fmt.Errorf("failed to get web encryption key: %w", err)
|
|
|
|
//}
|
|
|
|
//c.updateWebEncryptionKey(webEncryptionKeyResponse.GetKey())
|
2024-03-05 11:11:27 +00:00
|
|
|
go c.doLongPoll(true, c.postConnect)
|
2023-07-16 12:55:30 +00:00
|
|
|
c.sessionHandler.startAckInterval()
|
2023-07-19 21:58:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-07-16 12:55:30 +00:00
|
|
|
|
2023-07-19 21:58:39 +00:00
|
|
|
func (c *Client) postConnect() {
|
2024-03-05 11:11:27 +00:00
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
if c.skipCount > 0 {
|
2024-03-11 13:06:23 +00:00
|
|
|
c.Logger.Warn().Int("skip_count", c.skipCount).Msg("Skip count is non-zero in postConnect, waiting longer")
|
2024-03-13 16:11:18 +00:00
|
|
|
for i := 0; i < 3 && c.skipCount > 0; i++ {
|
2024-03-11 13:06:23 +00:00
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
}
|
|
|
|
if c.skipCount > 0 {
|
|
|
|
c.Logger.Warn().Int("skip_count", c.skipCount).Msg("Skip count is still non-zero")
|
|
|
|
}
|
2024-03-13 16:11:18 +00:00
|
|
|
c.triggerEvent(&events.HackySetActiveMayFail{})
|
2024-02-26 14:53:36 +00:00
|
|
|
}
|
2024-03-11 13:06:23 +00:00
|
|
|
c.Logger.Debug().Msg("Sending acks before get updates request")
|
2024-03-05 11:11:27 +00:00
|
|
|
c.sessionHandler.sendAckRequest()
|
|
|
|
time.Sleep(1 * time.Second)
|
2024-02-24 22:18:17 +00:00
|
|
|
c.Logger.Debug().Msg("Sending get updates request")
|
2023-07-19 21:58:39 +00:00
|
|
|
err := c.SetActiveSession()
|
|
|
|
if err != nil {
|
|
|
|
c.Logger.Err(err).Msg("Failed to set active session")
|
2023-09-04 11:24:45 +00:00
|
|
|
c.triggerEvent(&events.PingFailed{
|
|
|
|
Error: fmt.Errorf("failed to set active session: %w", err),
|
|
|
|
})
|
2023-07-19 21:58:39 +00:00
|
|
|
return
|
2023-07-16 12:55:30 +00:00
|
|
|
}
|
2024-02-23 20:44:06 +00:00
|
|
|
c.Logger.Debug().Msg("Sent set active session/get updates request")
|
2023-07-19 21:58:39 +00:00
|
|
|
|
|
|
|
doneChan := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case <-time.After(5 * time.Second):
|
|
|
|
c.Logger.Warn().Msg("Checking bugle default on connect is taking long")
|
|
|
|
case <-doneChan:
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
bugleRes, err := c.IsBugleDefault()
|
|
|
|
close(doneChan)
|
|
|
|
if err != nil {
|
|
|
|
c.Logger.Err(err).Msg("Failed to check bugle default")
|
|
|
|
return
|
2023-07-16 12:55:30 +00:00
|
|
|
}
|
2023-07-19 21:58:39 +00:00
|
|
|
c.Logger.Debug().Bool("bugle_default", bugleRes.Success).Msg("Got is bugle default response on connect")
|
2023-07-16 12:55:30 +00:00
|
|
|
}
|
|
|
|
|
2023-07-01 15:19:57 +00:00
|
|
|
func (c *Client) Disconnect() {
|
2023-07-19 11:12:23 +00:00
|
|
|
c.closeLongPolling()
|
2023-07-01 15:19:57 +00:00
|
|
|
c.http.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) IsConnected() bool {
|
2023-07-19 11:12:23 +00:00
|
|
|
// TODO add better check (longPollingConn is set to nil while the polling reconnects)
|
|
|
|
return c.longPollingConn != nil
|
2023-07-01 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) IsLoggedIn() bool {
|
2023-07-16 12:55:30 +00:00
|
|
|
return c.AuthData != nil && c.AuthData.Browser != nil
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Reconnect() error {
|
2023-07-19 11:12:23 +00:00
|
|
|
c.closeLongPolling()
|
2023-07-09 11:16:52 +00:00
|
|
|
err := c.Connect()
|
|
|
|
if err != nil {
|
2023-07-17 13:43:34 +00:00
|
|
|
c.Logger.Err(err).Msg("Failed to reconnect")
|
2023-07-09 11:16:52 +00:00
|
|
|
return err
|
|
|
|
}
|
2023-07-17 13:43:34 +00:00
|
|
|
c.Logger.Debug().Msg("Successfully reconnected to server")
|
2023-07-09 11:16:52 +00:00
|
|
|
return nil
|
2023-07-01 15:19:57 +00:00
|
|
|
}
|
|
|
|
|
2023-06-30 09:54:08 +00:00
|
|
|
func (c *Client) triggerEvent(evt interface{}) {
|
|
|
|
if c.evHandler != nil {
|
|
|
|
c.evHandler(evt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-22 20:37:49 +00:00
|
|
|
func (c *Client) FetchConfig() (*gmproto.Config, error) {
|
2023-09-04 21:34:22 +00:00
|
|
|
req, err := http.NewRequest(http.MethodGet, util.ConfigURL, nil)
|
|
|
|
if err != nil {
|
2024-02-22 20:37:49 +00:00
|
|
|
return nil, fmt.Errorf("failed to prepare request: %w", err)
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
2024-02-22 20:37:49 +00:00
|
|
|
util.BuildRelayHeaders(req, "", "*/*")
|
|
|
|
req.Header.Set("sec-fetch-site", "same-origin")
|
|
|
|
req.Header.Del("x-user-agent")
|
|
|
|
req.Header.Del("origin")
|
|
|
|
c.AddCookieHeaders(req)
|
2023-07-09 11:16:52 +00:00
|
|
|
|
2024-02-22 21:19:00 +00:00
|
|
|
resp, err := c.http.Do(req)
|
|
|
|
if resp != nil {
|
|
|
|
c.HandleCookieUpdates(resp)
|
|
|
|
}
|
|
|
|
config, err := typedHTTPResponse[*gmproto.Config](resp, err)
|
2023-09-04 21:34:22 +00:00
|
|
|
if err != nil {
|
2024-02-22 20:37:49 +00:00
|
|
|
return nil, err
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 20:37:49 +00:00
|
|
|
version, parseErr := config.ParsedClientVersion()
|
2023-07-09 11:16:52 +00:00
|
|
|
if parseErr != nil {
|
2024-02-22 20:37:49 +00:00
|
|
|
return nil, fmt.Errorf("failed to parse client version: %w", err)
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-16 12:55:30 +00:00
|
|
|
currVersion := util.ConfigMessage
|
2023-07-15 13:25:54 +00:00
|
|
|
if version.Year != currVersion.Year || version.Month != currVersion.Month || version.Day != currVersion.Day {
|
2023-07-09 11:16:52 +00:00
|
|
|
toLog := c.diffVersionFormat(currVersion, version)
|
2023-07-19 23:03:50 +00:00
|
|
|
c.Logger.Trace().Any("version", toLog).Msg("Messages for web version is not latest")
|
2023-07-09 11:16:52 +00:00
|
|
|
} else {
|
2023-07-19 23:03:50 +00:00
|
|
|
c.Logger.Debug().Any("version", currVersion).Msg("Using latest messages for web version")
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
2024-02-22 20:37:49 +00:00
|
|
|
|
|
|
|
return config, nil
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 13:51:31 +00:00
|
|
|
func (c *Client) diffVersionFormat(curr *gmproto.ConfigVersion, latest *gmproto.ConfigVersion) string {
|
2023-07-15 13:25:54 +00:00
|
|
|
return fmt.Sprintf("%d.%d.%d -> %d.%d.%d", curr.Year, curr.Month, curr.Day, latest.Year, latest.Month, latest.Day)
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) updateWebEncryptionKey(key []byte) {
|
2023-07-17 13:43:34 +00:00
|
|
|
c.Logger.Debug().Msg("Updated WebEncryptionKey")
|
2023-07-16 12:55:30 +00:00
|
|
|
c.AuthData.WebEncryptionKey = key
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 20:37:49 +00:00
|
|
|
func (c *Client) updateTachyonAuthToken(data *gmproto.TokenData) {
|
|
|
|
c.AuthData.TachyonAuthToken = data.GetTachyonAuthToken()
|
|
|
|
validForDuration := time.Duration(data.GetTTL()) * time.Microsecond
|
2023-07-16 11:36:13 +00:00
|
|
|
if validForDuration == 0 {
|
|
|
|
validForDuration = 24 * time.Hour
|
|
|
|
}
|
2024-02-22 20:37:49 +00:00
|
|
|
c.AuthData.TachyonExpiry = time.Now().UTC().Add(validForDuration)
|
2023-07-16 12:55:30 +00:00
|
|
|
c.AuthData.TachyonTTL = validForDuration.Microseconds()
|
2023-07-17 13:43:34 +00:00
|
|
|
c.Logger.Debug().
|
|
|
|
Time("tachyon_expiry", c.AuthData.TachyonExpiry).
|
2024-02-22 20:37:49 +00:00
|
|
|
Int64("valid_for", data.GetTTL()).
|
2023-07-17 13:43:34 +00:00
|
|
|
Msg("Updated tachyon token")
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) refreshAuthToken() error {
|
2023-07-16 12:55:30 +00:00
|
|
|
if c.AuthData.Browser == nil || time.Until(c.AuthData.TachyonExpiry) > RefreshTachyonBuffer {
|
2023-07-16 11:36:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
2023-07-17 13:43:34 +00:00
|
|
|
c.Logger.Debug().
|
|
|
|
Time("tachyon_expiry", c.AuthData.TachyonExpiry).
|
|
|
|
Msg("Refreshing auth token")
|
2023-07-16 12:55:30 +00:00
|
|
|
jwk := c.AuthData.RefreshKey
|
2023-07-16 10:23:44 +00:00
|
|
|
requestID := uuid.NewString()
|
2023-07-09 11:16:52 +00:00
|
|
|
timestamp := time.Now().UnixMilli() * 1000
|
|
|
|
|
2023-07-16 10:33:51 +00:00
|
|
|
signBytes := sha256.Sum256([]byte(fmt.Sprintf("%s:%d", requestID, timestamp)))
|
|
|
|
sig, err := ecdsa.SignASN1(rand.Reader, jwk.GetPrivateKey(), signBytes[:])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 10:58:53 +00:00
|
|
|
payload := &gmproto.RegisterRefreshRequest{
|
2023-07-17 13:51:31 +00:00
|
|
|
MessageAuth: &gmproto.AuthMessage{
|
2023-07-16 11:36:13 +00:00
|
|
|
RequestID: requestID,
|
2023-07-16 12:55:30 +00:00
|
|
|
TachyonAuthToken: c.AuthData.TachyonAuthToken,
|
2024-02-23 12:53:19 +00:00
|
|
|
Network: c.AuthData.AuthNetwork(),
|
2023-07-16 12:55:30 +00:00
|
|
|
ConfigVersion: util.ConfigMessage,
|
2023-07-16 11:36:13 +00:00
|
|
|
},
|
2023-07-16 12:55:30 +00:00
|
|
|
CurrBrowserDevice: c.AuthData.Browser,
|
2023-07-16 11:36:13 +00:00
|
|
|
UnixTimestamp: timestamp,
|
|
|
|
Signature: sig,
|
2023-07-17 23:57:20 +00:00
|
|
|
EmptyRefreshArr: &gmproto.RegisterRefreshRequest_NestedEmptyArr{EmptyArr: &gmproto.EmptyArr{}},
|
2023-07-16 11:36:13 +00:00
|
|
|
MessageType: 2, // hmm
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 10:58:53 +00:00
|
|
|
resp, err := typedHTTPResponse[*gmproto.RegisterRefreshResponse](
|
|
|
|
c.makeProtobufHTTPRequest(util.RegisterRefreshURL, payload, ContentTypePBLite),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 20:37:49 +00:00
|
|
|
if resp.GetTokenData().GetTachyonAuthToken() == nil {
|
2023-07-19 10:58:53 +00:00
|
|
|
return fmt.Errorf("no tachyon auth token in refresh response")
|
2023-07-09 11:16:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-22 20:37:49 +00:00
|
|
|
c.updateTachyonAuthToken(resp.GetTokenData())
|
2023-07-16 12:55:30 +00:00
|
|
|
c.triggerEvent(&events.AuthTokenRefreshed{})
|
2023-07-09 11:16:52 +00:00
|
|
|
return nil
|
|
|
|
}
|