mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-17 04:37:48 +00:00
Resolve invalid state parameter issue.
This commit is contained in:
+1
-1
@@ -143,7 +143,7 @@ func (t *TraefikOidc) handleCallback(rw http.ResponseWriter, req *http.Request)
|
|||||||
sessionState, ok := session.Values["csrf"].(string)
|
sessionState, ok := session.Values["csrf"].(string)
|
||||||
if !ok || callbackState != sessionState {
|
if !ok || callbackState != sessionState {
|
||||||
handleError(rw, "Invalid state parameter", http.StatusBadRequest, t.logger)
|
handleError(rw, "Invalid state parameter", http.StatusBadRequest, t.logger)
|
||||||
return false, ""
|
return false, "invalid-state-param"
|
||||||
}
|
}
|
||||||
|
|
||||||
code := req.URL.Query().Get("code")
|
code := req.URL.Query().Get("code")
|
||||||
|
|||||||
@@ -261,6 +261,13 @@ func (t *TraefikOidc) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
http.Redirect(rw, req, originalPath, http.StatusFound)
|
http.Redirect(rw, req, originalPath, http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !authSuccess && originalPath == "invalid-state-param" {
|
||||||
|
// redirect to the root path so that the user can try again
|
||||||
|
// this usually happens when user was previously authenticated
|
||||||
|
// and the session was cleared, but user tries to refresh the page
|
||||||
|
// and different traefik instance is used.
|
||||||
|
http.Redirect(rw, req, "/", http.StatusFound)
|
||||||
|
}
|
||||||
http.Error(rw, "Authentication failed", http.StatusUnauthorized)
|
http.Error(rw, "Authentication failed", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user