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,15 +725,14 @@ 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) {
if session != nil {
if 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) logger.Printf("Refreshing %s old session cookie for %s (refresh after %s)", session.Age(), session, p.CookieRefresh)
saveSession = true saveSession = true
} }
}
if session != nil { if ok, err := p.provider.RefreshSessionIfNeeded(session); err != nil {
var ok bool
if ok, err = p.provider.RefreshSessionIfNeeded(session); err != nil {
logger.Printf("%s removing session. error refreshing access token %s %s", remoteAddr, err, session) logger.Printf("%s removing session. error refreshing access token %s %s", remoteAddr, err, session)
clearSession = true clearSession = true
session = nil session = nil
@ -742,6 +741,7 @@ func (p *OAuthProxy) getAuthenticatedSession(rw http.ResponseWriter, req *http.R
revalidated = true revalidated = true
} }
} }
}
if session != nil && session.IsExpired() { if session != nil && session.IsExpired() {
logger.Printf("Removing session: token expired %s", session) logger.Printf("Removing session: token expired %s", session)