mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-12 20:59:04 +02:00
feat: add ability to customize session duration of clients (#1641)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user