Auto sign off

This commit is contained in:
2024-02-18 16:26:46 +08:00
parent 00028cfce8
commit e429627ecf
5 changed files with 30 additions and 2 deletions

View File

@ -3,6 +3,9 @@ package services
import (
"code.smartsheep.studio/hydrogen/identity/pkg/database"
"code.smartsheep.studio/hydrogen/identity/pkg/models"
"github.com/spf13/viper"
"gorm.io/gorm"
"time"
)
func LookupSessionWithToken(tokenId string) (models.AuthSession, error) {
@ -16,3 +19,8 @@ func LookupSessionWithToken(tokenId string) (models.AuthSession, error) {
return session, nil
}
func PerformAutoSignoff() *gorm.DB {
signoffDuration := time.Duration(viper.GetInt64("security.auto_signoff_duration")) * time.Second
return database.C.Where("last_grant_at < ?", time.Now().Add(-signoffDuration)).Delete(&models.AuthSession{})
}