Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add more debug logging. #2223

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,23 @@ 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)
// TMP. Token should never 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 {
// Should never happen.
echo(Log{
"t": "app",
"error": "missing access token in send",
"sessionID": session.id,
"subject": session.subject,
"username": session.username,
"access_url": session.successURL,
"expiry": session.expiry.String(),
})
}
}

resp, err := app.client.Do(req)
Expand Down
31 changes: 30 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ func (auth *Auth) get(key string) (*Session, bool) {
func (auth *Auth) set(session *Session) {
auth.Lock()
defer auth.Unlock()
if session == nil {
// Should not happen.
echo(Log{"t": "TMP_DBG", "error": "trying to set nil session"})
}

auth.sessions[session.id] = session
}

Expand Down Expand Up @@ -178,6 +183,11 @@ func (auth *Auth) identify(r *http.Request) *Session {
auth.set(session)
}

if session.token == nil {
// Should not happen.
echo(Log{"t": "TMP_DBG", "error": "trying to set session with nil token in auth.identify"})
}

return session
}

Expand Down Expand Up @@ -211,7 +221,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 && err == nil {
// Should not happen.
echo(Log{"t": "TMP_DBG", "error": "trying to set session with nil token in ensureValidOAuth2Token"})
}
return token, err
}

func (auth *Auth) redirectToLogin(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -390,6 +405,11 @@ func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

h.auth.set(session)

if session.token == nil {
// Should not happen.
echo(Log{"t": "TMP_DBG", "error": "trying to set session with nil token in authHandler"})
}

http.Redirect(w, r, session.successURL, http.StatusFound)
}

Expand Down Expand Up @@ -424,6 +444,10 @@ func (h *LogoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Purge session
h.auth.remove(sessionID)

if !ok {
echo(Log{"t": "TMP_DBG", "error": "session not found during logout", "session_id": sessionID})
}

if ok {
// Reload all of this user's browser tabs
h.broker.resetClients(session)
Expand Down Expand Up @@ -497,6 +521,11 @@ func (h *RefreshHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

if token == nil {
// Should not happen.
echo(Log{"t": "TMP_DBG", "error": "trying to set session with nil token in refreshHandler"})
}

session.token = token
h.auth.set(session)

Expand Down