Skip to content

Commit

Permalink
fix: Ignore nil token err for now. #2185 (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Jan 31, 2024
1 parent b298f21 commit 9454ff4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9454ff4

Please sign in to comment.