OIDC: Ensure ID tokens fit into the auth_sessions.id_token column #5294

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2025-11-14 17:02:17 +01:00
parent d89ac51159
commit 6e82481944

View file

@ -339,7 +339,14 @@ func OIDCRedirect(router *gin.RouterGroup) {
sess.SetAuthID(user.AuthID, provider.Issuer())
sess.SetUser(user)
sess.SetGrantType(authn.GrantAuthorizationCode)
sess.IdToken = tokens.IDToken
// Ensure that the ID token fits into the existing
// database column; otherwise, truncate it.
if n := len(tokens.IDToken); n > 2048 {
sess.IdToken = tokens.IDToken[:2048]
} else {
sess.IdToken = tokens.IDToken
}
// Set session expiration and timeout.
sess.SetExpiresIn(unix.Day)