mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-05 09:19:04 +02:00
feat: add ability to customize session duration of clients (#1641)
This commit is contained in:
@@ -24,6 +24,8 @@ type OidcClientDto struct {
|
||||
Credentials OidcClientCredentialsDto `json:"credentials"`
|
||||
IsGroupRestricted bool `json:"isGroupRestricted"`
|
||||
PkceSupported bool `json:"pkceSupported,omitempty"`
|
||||
AccessTokenDurationMinutes int64 `json:"accessTokenDurationMinutes"`
|
||||
RefreshTokenDurationMinutes int64 `json:"refreshTokenDurationMinutes"`
|
||||
}
|
||||
|
||||
type OidcClientWithAllowedUserGroupsDto struct {
|
||||
@@ -53,6 +55,8 @@ type OidcClientUpdateDto struct {
|
||||
LogoURL *string `json:"logoUrl"`
|
||||
DarkLogoURL *string `json:"darkLogoUrl"`
|
||||
IsGroupRestricted bool `json:"isGroupRestricted"`
|
||||
AccessTokenDurationMinutes int64 `json:"accessTokenDurationMinutes" binding:"required,token_duration"`
|
||||
RefreshTokenDurationMinutes int64 `json:"refreshTokenDurationMinutes" binding:"required,token_duration"`
|
||||
}
|
||||
|
||||
type OidcClientCreateDto struct {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ory/fosite"
|
||||
"github.com/pocket-id/pocket-id/backend/internal/model"
|
||||
"github.com/pocket-id/pocket-id/backend/internal/utils"
|
||||
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
@@ -61,6 +62,9 @@ func init() {
|
||||
"resource_uri": func(fl validator.FieldLevel) bool {
|
||||
return ValidateResourceURI(fl.Field().String())
|
||||
},
|
||||
"token_duration": func(fl validator.FieldLevel) bool {
|
||||
return model.IsValidTokenDurationMinutes(fl.Field().Int())
|
||||
},
|
||||
}
|
||||
for k, v := range validators {
|
||||
err := engine.RegisterValidation(k, v)
|
||||
|
||||
@@ -3,9 +3,38 @@ package dto
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestTokenDurationValidation(t *testing.T) {
|
||||
type input struct {
|
||||
Duration int64 `binding:"required,token_duration"`
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
value int64
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "omitted", wantErr: true},
|
||||
{name: "below minimum", value: 0, wantErr: true},
|
||||
{name: "minimum", value: 1},
|
||||
{name: "custom duration", value: 90},
|
||||
{name: "above maximum", value: 365*24*60 + 1, wantErr: true},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := binding.Validator.ValidateStruct(input{Duration: test.value})
|
||||
if test.wantErr {
|
||||
require.Error(t, err)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateUsername(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
Reference in New Issue
Block a user