Skip to content

Commit

Permalink
fix: change default session expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyu committed Sep 14, 2024
1 parent 5a5ac4e commit fb4d1c2
Show file tree
Hide file tree
Showing 4 changed files with 286 additions and 115 deletions.
6 changes: 3 additions & 3 deletions internal/configuration/schema/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ type SessionCookieConfiguration struct {
var DefaultSessionConfiguration = SessionConfiguration{
SessionCookieCommonConfiguration: SessionCookieCommonConfiguration{
Name: "authelia_session",
Expiration: time.Hour * 24 * 14,
Inactivity: time.Hour * 24 * 14,
RememberMe: time.Hour * 24 * 30,
Expiration: time.Hour * 24 * 365,
Inactivity: time.Hour * 24 * 365,
RememberMe: time.Hour * 24 * 365,
SameSite: "lax",
},
}
Expand Down
5 changes: 4 additions & 1 deletion internal/session/kubesphere/v3.3/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ func NewTokenOperator() (*Operator, error) {
}, nil
}

func (o *Operator) RestoreToken(username, token string, duration time.Duration) {
func (o *Operator) RestoreToken(username, token string, duration time.Duration) error {
key := fmt.Sprintf("kubesphere:user:%s:token:%s", username, token)
if exist, err := o.client.Exists(key); err != nil {
klog.Error("validate token error, ", err, " : ", key)
return err
} else if !exist {
if err := o.client.Set(key, token, duration); err != nil {
klog.Error("set token error, ", err)
return err
}
}
return nil
}
12 changes: 10 additions & 2 deletions internal/session/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func (p *Provider) reloadTokenToCache() {

if err != nil {
klog.Error("connect to kubesphere token cache error, ", err)
panic(err)
}

for key, data := range dataList {
Expand Down Expand Up @@ -346,8 +347,15 @@ func (p *Provider) reloadTokenToCache() {
}

if ksTokenOperator != nil {
ksTokenOperator.RestoreToken(us.Username, us.AccessToken, p.Config.Expiration)
ksTokenOperator.RestoreToken(us.Username, us.RefreshToken, p.Config.Expiration)
err = ksTokenOperator.RestoreToken(us.Username, us.AccessToken, p.Config.Expiration)
if err != nil {
continue
}

err = ksTokenOperator.RestoreToken(us.Username, us.RefreshToken, p.Config.Expiration)
if err != nil {
continue
}
}

// create provider.
Expand Down
Loading

0 comments on commit fb4d1c2

Please sign in to comment.