feat: add ability to customize session duration of clients (#1641)

This commit is contained in:
Elias Schneider
2026-08-03 23:23:29 +02:00
committed by GitHub
parent 1238bf0f37
commit 5d43c4aaeb
28 changed files with 752 additions and 77 deletions
+34
View File
@@ -2,6 +2,7 @@ package oidc
import (
"slices"
"time"
"github.com/ory/fosite"
"github.com/pocket-id/pocket-id/backend/internal/model"
@@ -86,3 +87,36 @@ func (c Client) GetResponseModes() []fosite.ResponseModeType {
fosite.ResponseModeFormPost,
}
}
func (c Client) GetEffectiveLifespan(grantType fosite.GrantType, tokenType fosite.TokenType, fallback time.Duration) time.Duration {
var minutes int64
switch tokenType {
case fosite.AccessToken:
switch grantType {
case fosite.GrantTypeAuthorizationCode, fosite.GrantTypeRefreshToken, fosite.GrantTypeDeviceCode, fosite.GrantTypeClientCredentials:
minutes = c.AccessTokenDurationMinutes
case fosite.GrantTypeImplicit, fosite.GrantTypePassword, fosite.GrantTypeJWTBearer:
return fallback
default:
return fallback
}
case fosite.RefreshToken:
switch grantType {
case fosite.GrantTypeAuthorizationCode, fosite.GrantTypeRefreshToken, fosite.GrantTypeDeviceCode:
minutes = c.RefreshTokenDurationMinutes
case fosite.GrantTypeImplicit, fosite.GrantTypePassword, fosite.GrantTypeClientCredentials, fosite.GrantTypeJWTBearer:
return fallback
default:
return fallback
}
case fosite.AuthorizeCode, fosite.IDToken, fosite.UserCode, fosite.DeviceCode, fosite.PushedAuthorizeRequestContext:
return fallback
default:
return fallback
}
if !model.IsValidTokenDurationMinutes(minutes) {
return fallback
}
return time.Duration(minutes) * time.Minute
}