Passport/pkg/services/sessions.go

28 lines
745 B
Go
Raw Normal View History

2024-01-07 07:52:23 +00:00
package services
import (
2024-03-20 12:56:43 +00:00
"time"
"git.solsynth.dev/hydrogen/identity/pkg/database"
"git.solsynth.dev/hydrogen/identity/pkg/models"
2024-02-18 08:26:46 +00:00
"github.com/spf13/viper"
"gorm.io/gorm"
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{})
}