Skip to content

Commit 6dde283

Browse files
committed
fix(oidc_auth): Fix userinfo cache expiration logic
When the userinfo claims store in the usercache is found to be expired, do not return an error but ignore the cached entry and force a re-verification of the access token (either via parsing the JWT again or via a UserInfo lookup). This is required for setups with non-JWT access tokes where the expiry date set in the cached claims does not reflect the actual token expiry, but just the CacheTTL. Fixes: #1493
1 parent 212846f commit 6dde283

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

services/proxy/pkg/middleware/oidc_auth.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/golang-jwt/jwt/v5"
1211
"github.com/opencloud-eu/opencloud/pkg/log"
1312
"github.com/opencloud-eu/opencloud/pkg/oidc"
1413
"github.com/pkg/errors"
@@ -68,12 +67,13 @@ func (m *OIDCAuthenticator) getClaims(token string, req *http.Request) (map[stri
6867
if len(record) > 0 {
6968
if err = msgpack.Unmarshal(record[0].Value, &claims); err == nil {
7069
m.Logger.Debug().Interface("claims", claims).Msg("cache hit for userinfo")
71-
if ok := verifyExpiresAt(claims, m.TimeFunc()); !ok {
72-
return nil, false, jwt.ErrTokenExpired
70+
if verifyExpiresAt(claims, m.TimeFunc()) {
71+
return claims, false, nil
7372
}
74-
return claims, false, nil
73+
m.Logger.Debug().Msg("cached userinfo claims expired, ignoring cache")
74+
} else {
75+
m.Logger.Error().Err(err).Msg("failed to unmarshal cached userinfo, ignoring cache")
7576
}
76-
m.Logger.Error().Err(err).Msg("could not unmarshal userinfo")
7777
}
7878

7979
aClaims, claims, err := m.oidcClient.VerifyAccessToken(req.Context(), token)

0 commit comments

Comments
 (0)