Skip to content

Commit

Permalink
fix bug of invalid session
Browse files Browse the repository at this point in the history
  • Loading branch information
Jing-ze committed Dec 26, 2024
1 parent e98bf3c commit f5a14a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions pkg/middleware/stored_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (s *StoredSessionLoader) loadSession(next http.Handler) http.Handler {
resumeFlag := args[0].(bool)
validateSessionCallback := func(args ...interface{}) {
resumeFlag := args[0].(bool)
sessionValid := args[1].(bool)
if !sessionValid {
session = nil
}
scope.Session = session
next.ServeHTTP(rw, req)
if resumeFlag {
Expand All @@ -115,14 +119,11 @@ func (s *StoredSessionLoader) loadSession(next http.Handler) http.Handler {
}
if session != nil {
err, isAsync := s.validateSession(req.Context(), session, validateSessionCallback)
if err != nil {
session = nil
}
if !isAsync {
validateSessionCallback(resumeFlag)
validateSessionCallback(resumeFlag, err == nil)
}
} else {
validateSessionCallback(resumeFlag)
validateSessionCallback(resumeFlag, true)
}
}
keysNeedsUpdate := (session != nil) && (s.NeedsVerifier)
Expand Down
6 changes: 3 additions & 3 deletions providers/internal_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package providers

import (
"context"
"fmt"
"net/http"
"net/url"

Expand Down Expand Up @@ -70,9 +69,10 @@ func validateToken(ctx context.Context, p Provider, accessToken string, header h
client.Get(endpoint, headerArray, func(statusCode int, responseHeaders http.Header, responseBody []byte) {
util.Logger.Debugf("%d GET %s %s", statusCode, stripToken(endpoint), responseBody)
if statusCode == 200 {
callback(true)
callback(true, true)
} else {
util.SendError(fmt.Sprintf("token validation request failed: status %d - %s", statusCode, responseBody), nil, http.StatusInternalServerError)
util.Logger.Errorf("token validation request failed: status %d - %s", statusCode, responseBody)
callback(false, false)
}
}, timeout)
return true, true
Expand Down

0 comments on commit f5a14a4

Please sign in to comment.