From 42e33f4b2b46b73540393e039af59b3dd7b8b23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Tur=C3=B3ci?= <64769322+mturoci@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:23:36 +0100 Subject: [PATCH] fix: Ignore nil token err for now. #2185 (#2246) --- app.go | 11 +++++++++-- auth.go | 7 ++++++- broker.go | 4 +++- server.go | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app.go b/app.go index fa22f4e738..8c88b441e9 100644 --- a/app.go +++ b/app.go @@ -109,9 +109,16 @@ func (app *App) send(clientID string, session *Session, data []byte) error { req.Header.Set("Wave-Subject-ID", session.subject) req.Header.Set("Wave-Username", session.username) if session.subject != anon { - req.Header.Set("Wave-Access-Token", session.token.AccessToken) - req.Header.Set("Wave-Refresh-Token", session.token.RefreshToken) req.Header.Set("Wave-Session-ID", session.id) + // TODO: Figure out how can the token be nil. + if session.token != nil { + req.Header.Set("Wave-Access-Token", session.token.AccessToken) + req.Header.Set("Wave-Refresh-Token", session.token.RefreshToken) + } else { + if app.broker.debug { + echo(Log{"t": "app_send", "error": "session token is nil"}) + } + } } resp, err := app.client.Do(req) diff --git a/auth.go b/auth.go index 5f4dd76b71..2e2cf22b27 100644 --- a/auth.go +++ b/auth.go @@ -211,7 +211,12 @@ func (auth *Auth) wrap(h http.Handler) http.Handler { } func (auth *Auth) ensureValidOAuth2Token(ctx context.Context, token *oauth2.Token) (*oauth2.Token, error) { - return auth.oauth.TokenSource(ctx, token).Token() + token, err := auth.oauth.TokenSource(ctx, token).Token() + if token == nil { + echo(Log{"t": "ensure_token_refresh", "error": "refresh token is nil"}) + echo(Log{"t": "ensure_token_refresh", "error": err.Error()}) + } + return token, err } func (auth *Auth) redirectToLogin(w http.ResponseWriter, r *http.Request) { diff --git a/broker.go b/broker.go index c1fa198a28..1586010038 100644 --- a/broker.go +++ b/broker.go @@ -66,6 +66,7 @@ type Broker struct { editable bool noStore bool noLog bool + debug bool clients map[string]map[*Client]interface{} // route => client-set publish chan Pub subscribe chan Sub @@ -78,12 +79,13 @@ type Broker struct { keepAppLive bool } -func newBroker(site *Site, editable, noStore, noLog, keepAppLive bool) *Broker { +func newBroker(site *Site, editable, noStore, noLog, keepAppLive, debug bool) *Broker { return &Broker{ site, editable, noStore, noLog, + debug, make(map[string]map[*Client]interface{}), make(chan Pub, 1024), // TODO tune make(chan Sub, 1024), // TODO tune diff --git a/server.go b/server.go index 9b8f008d31..ab4e2370e9 100644 --- a/server.go +++ b/server.go @@ -87,7 +87,7 @@ func Run(conf ServerConf) { handle := handleWithBaseURL(conf.BaseURL) - broker := newBroker(site, conf.Editable, conf.NoStore, conf.NoLog, conf.KeepAppLive) + broker := newBroker(site, conf.Editable, conf.NoStore, conf.NoLog, conf.KeepAppLive, conf.Debug) go broker.run() if conf.Debug {