Passport/pkg/services/sessions.go

27 lines
756 B
Go
Raw Normal View History

2024-01-07 07:52:23 +00:00
package services
import (
2024-02-18 03:20:22 +00:00
"code.smartsheep.studio/hydrogen/identity/pkg/database"
"code.smartsheep.studio/hydrogen/identity/pkg/models"
2024-02-18 08:26:46 +00:00
"github.com/spf13/viper"
"gorm.io/gorm"
"time"
2024-01-07 07:52:23 +00:00
)
func LookupSessionWithToken(tokenId string) (models.AuthSession, error) {
var session models.AuthSession
if err := database.C.
Where(models.AuthSession{AccessToken: tokenId}).
Or(models.AuthSession{RefreshToken: tokenId}).
First(&session).Error; err != nil {
return session, err
}
return session, nil
}
2024-02-18 08:26:46 +00:00
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{})
}