From 5921d76f71b969c5f476074a4a5e1cdc3b62ae81 Mon Sep 17 00:00:00 2001 From: Martin Turoci Date: Wed, 31 Jan 2024 11:33:27 +0100 Subject: [PATCH 1/2] fix: Ignore nil token err. --- app.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index fa22f4e738..854ad12fc2 100644 --- a/app.go +++ b/app.go @@ -109,9 +109,12 @@ 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) + } } resp, err := app.client.Do(req) From 72ab5fc1de4111aab075d5bde3bbcba04fe78067 Mon Sep 17 00:00:00 2001 From: Martin Turoci Date: Wed, 31 Jan 2024 18:22:31 +0100 Subject: [PATCH 2/2] chore: Add some logging. --- app.go | 4 ++++ auth.go | 7 ++++++- broker.go | 4 +++- server.go | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index 854ad12fc2..8c88b441e9 100644 --- a/app.go +++ b/app.go @@ -114,6 +114,10 @@ func (app *App) send(clientID string, session *Session, data []byte) error { 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"}) + } } } 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 5f9bed66e4..d700c132e6 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 {