Another attempt to fix the issue with expired session.

This commit is contained in:
2024-09-17 08:30:44 +01:00
parent 38433dfff8
commit e97d8e15ff
2 changed files with 7 additions and 10 deletions
+5 -3
View File
@@ -137,15 +137,17 @@ func (t *TraefikOidc) handleExpiredToken(rw http.ResponseWriter, req *http.Reque
func (t *TraefikOidc) handleCallback(rw http.ResponseWriter, req *http.Request) (bool, string) {
session, err := t.store.Get(req, cookieName)
if err != nil {
handleError(rw, "Session error", http.StatusInternalServerError, t.logger)
t.logger.Errorf("Session error: %v", err)
t.initiateAuthentication(rw, req, session, t.redirectURL)
return false, ""
}
callbackState := req.URL.Query().Get("state")
sessionState, ok := session.Values["csrf"].(string)
if !ok || callbackState != sessionState {
handleError(rw, "Invalid state parameter", http.StatusBadRequest, t.logger)
return false, "invalid-state-param"
t.logger.Debug("Invalid state parameter. Session might have expired.")
t.initiateAuthentication(rw, req, session, t.redirectURL)
return false, ""
}
code := req.URL.Query().Get("code")
+2 -7
View File
@@ -275,12 +275,7 @@ func (t *TraefikOidc) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
authenticated, needsRefresh, expired := t.isUserAuthenticated(session)
if expired {
t.handleExpiredToken(rw, req, session)
return
}
if !authenticated {
if expired || !authenticated {
t.initiateAuthentication(rw, req, session, t.redirectURL)
return
}
@@ -288,7 +283,7 @@ func (t *TraefikOidc) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if needsRefresh {
refreshed := t.refreshToken(rw, req, session)
if !refreshed {
t.handleExpiredToken(rw, req, session)
t.initiateAuthentication(rw, req, session, t.redirectURL)
return
}
}