Move refreshing code to block acquiring cookied session

This commit is contained in:
Brian Van Klaveren 2019-06-05 16:08:34 -07:00
parent 48dbb391bc
commit 2f6dcf3b5f

View File

@ -725,21 +725,21 @@ func (p *OAuthProxy) getAuthenticatedSession(rw http.ResponseWriter, req *http.R
if err != nil { if err != nil {
logger.Printf("Error loading cookied session: %s", err) logger.Printf("Error loading cookied session: %s", err)
} }
if session != nil && session.Age() > p.CookieRefresh && p.CookieRefresh != time.Duration(0) {
logger.Printf("Refreshing %s old session cookie for %s (refresh after %s)", session.Age(), session, p.CookieRefresh)
saveSession = true
}
}
if session != nil { if session != nil {
var ok bool if session.Age() > p.CookieRefresh && p.CookieRefresh != time.Duration(0) {
if ok, err = p.provider.RefreshSessionIfNeeded(session); err != nil { logger.Printf("Refreshing %s old session cookie for %s (refresh after %s)", session.Age(), session, p.CookieRefresh)
logger.Printf("%s removing session. error refreshing access token %s %s", remoteAddr, err, session) saveSession = true
clearSession = true }
session = nil
} else if ok { if ok, err := p.provider.RefreshSessionIfNeeded(session); err != nil {
saveSession = true logger.Printf("%s removing session. error refreshing access token %s %s", remoteAddr, err, session)
revalidated = true clearSession = true
session = nil
} else if ok {
saveSession = true
revalidated = true
}
} }
} }