Skip to content

Commit 7b43805

Browse files
authored
Merge pull request #1 from ploxiln/session_state_htpasswd
fix htpasswd auth when cookie-refresh is enabled
2 parents 81b13fb + a4c57be commit 7b43805

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

oauthproxy.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ func (p *OAuthProxy) Authenticate(rw http.ResponseWriter, req *http.Request) int
637637
if err != nil {
638638
log.Printf("%s %s", remoteAddr, err)
639639
}
640-
if session != nil && sessionAge > p.CookieRefresh && p.CookieRefresh != time.Duration(0) {
640+
if session != nil && p.CookieRefresh != time.Duration(0) && sessionAge > p.CookieRefresh && session.AccessToken != "" {
641641
log.Printf("%s refreshing %s old session cookie for %s (refresh after %s)", remoteAddr, sessionAge, session, p.CookieRefresh)
642642
saveSession = true
643643
}
@@ -658,12 +658,16 @@ func (p *OAuthProxy) Authenticate(rw http.ResponseWriter, req *http.Request) int
658658
clearSession = true
659659
}
660660

661-
if saveSession && !revalidated && session != nil && session.AccessToken != "" {
662-
if !p.provider.ValidateSessionState(session) {
663-
log.Printf("%s removing session. error validating %s", remoteAddr, session)
661+
if saveSession && !revalidated && session != nil {
662+
if session.AccessToken != "" {
663+
if !p.provider.ValidateSessionState(session) {
664+
log.Printf("%s removing session. error validating %s", remoteAddr, session)
665+
saveSession = false
666+
session = nil
667+
clearSession = true
668+
}
669+
} else {
664670
saveSession = false
665-
session = nil
666-
clearSession = true
667671
}
668672
}
669673

providers/session_state.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ func decodeSessionStatePlain(v string) (s *SessionState, err error) {
8585
}
8686

8787
func DecodeSessionState(v string, c *cookie.Cipher) (s *SessionState, err error) {
88-
if c == nil {
88+
chunks := strings.Split(v, "|")
89+
90+
if c == nil || len(chunks) == 1 {
8991
return decodeSessionStatePlain(v)
9092
}
9193

92-
chunks := strings.Split(v, "|")
9394
if len(chunks) != 4 {
9495
err = fmt.Errorf("invalid number of fields (got %d expected 4)", len(chunks))
9596
return

0 commit comments

Comments
 (0)