mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-13 04:07:37 +00:00
Add redis support for distributed caching (#83)
* Add redis support for distributed caching * Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * fixup! fixup! fixup! fixup! fixup! Move towards the self-provided Redis connection pool and RESP protocol implementation. Official redis client library won't work with yaegi. * ... and another all nighter. * fixup! ... and another all nighter. * fixup! fixup! ... and another all nighter. * fixup! fixup! fixup! ... and another all nighter. * Resolve issue #85 by adding ability to set custom claims in JWT tokens * Remove redundant validation in auth middleware ( issue #89 ) * Add ability to set cookie prefix for session cookies ( #87 ) * fixup! Add ability to set cookie prefix for session cookies ( #87 ) * Add ability to set cookie max age - issue #91 * Potential fix for code scanning alert no. 10: Size computation for allocation may overflow Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fixup! Merge main into 0.8.0-redis: resolve conflicts --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
parent
5fcbd54955
commit
e64fc7f730
@@ -261,17 +261,10 @@ func (m *AuthMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
if authenticated && !needsRefresh {
|
||||
m.logger.Debug("User authenticated and token valid, proceeding to process authorized request")
|
||||
if accessToken := session.GetAccessToken(); accessToken != "" {
|
||||
if strings.Count(accessToken, ".") == 2 {
|
||||
if err := m.tokenVerifier.VerifyToken(accessToken); err != nil {
|
||||
m.logger.Errorf("Access token validation failed: %v", err)
|
||||
m.handleExpiredToken(rw, req, session, redirectURL)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
m.logger.Debugf("Access token appears opaque, skipping JWT verification for it.")
|
||||
}
|
||||
}
|
||||
// Access token validation is already performed by provider-specific validation
|
||||
// methods (validateAzureTokens/validateStandardTokens) before reaching this point.
|
||||
// Redundant validation here was causing issues with Azure AD tokens that have
|
||||
// JWT format but unverifiable signatures. See issue #89.
|
||||
m.processAuthorizedRequest(rw, req, session, redirectURL)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -730,9 +730,9 @@ func TestServeHTTP_ComprehensiveCoverage(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("jwt_token_validation_failure", func(t *testing.T) {
|
||||
t.Run("authenticated_user_proceeds_to_authorized_request", func(t *testing.T) {
|
||||
logger := &mockLogger{}
|
||||
handleExpiredCalled := false
|
||||
nextHandlerCalled := false
|
||||
|
||||
initComplete := make(chan struct{})
|
||||
close(initComplete)
|
||||
@@ -741,11 +741,14 @@ func TestServeHTTP_ComprehensiveCoverage(t *testing.T) {
|
||||
logger: logger,
|
||||
issuerURL: "https://issuer.example.com",
|
||||
initComplete: initComplete,
|
||||
next: http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
nextHandlerCalled = true
|
||||
}),
|
||||
sessionManager: &mockSessionManager{
|
||||
getSessionFunc: func(req *http.Request) (SessionData, error) {
|
||||
return &mockSessionData{
|
||||
email: "[email protected]",
|
||||
accessToken: "invalid.jwt.token", // JWT format (has dots)
|
||||
accessToken: "valid.jwt.token", // JWT format (has dots)
|
||||
}, nil
|
||||
},
|
||||
cleanupOldCookiesFunc: func(rw http.ResponseWriter, req *http.Request) {},
|
||||
@@ -762,34 +765,28 @@ func TestServeHTTP_ComprehensiveCoverage(t *testing.T) {
|
||||
},
|
||||
},
|
||||
isUserAuthenticatedFunc: func(session SessionData) (bool, bool, bool) {
|
||||
// When authenticated=true, it means provider-specific validation already passed
|
||||
return true, false, false // authenticated, no refresh needed
|
||||
},
|
||||
isAllowedDomainFunc: func(email string) bool {
|
||||
return true
|
||||
},
|
||||
tokenVerifier: &mockTokenVerifier{
|
||||
verifyFunc: func(token string) error {
|
||||
return errors.New("token validation failed")
|
||||
},
|
||||
extractClaimsFunc: func(token string) (map[string]interface{}, error) {
|
||||
return map[string]interface{}{"email": "[email protected]"}, nil
|
||||
},
|
||||
authHandler: &mockAuthHandler{
|
||||
initiateAuthFunc: func(rw http.ResponseWriter, req *http.Request, session SessionData, redirectURL string,
|
||||
genNonce, genVerifier, deriveChallenge func() (string, error)) {
|
||||
handleExpiredCalled = true
|
||||
},
|
||||
extractGroupsAndRolesFunc: func(token string) ([]string, []string, error) {
|
||||
return []string{}, []string{}, nil
|
||||
},
|
||||
firstRequestReceived: true,
|
||||
}
|
||||
|
||||
// We'll track this through the authHandler's InitiateAuthentication call
|
||||
|
||||
req := httptest.NewRequest("GET", "/test", nil)
|
||||
rw := httptest.NewRecorder()
|
||||
|
||||
m.ServeHTTP(rw, req)
|
||||
|
||||
if !handleExpiredCalled {
|
||||
t.Error("Expected handleExpiredToken for invalid JWT")
|
||||
if !nextHandlerCalled {
|
||||
t.Error("Expected next handler to be called when user is authenticated")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user