package store import ( "errors" "strconv" "time" ) const DefaultAuthSessionMinutes = 24 * 60 const MaxAuthSessionMinutes = 30 * 24 * 60 // Absolute lifetime, fixed at issuance. Changing the policy cannot silently // revive, extend or invalidate existing sessions. App passwords are separate. func (s *Store) AuthSessionLifetimeMinutes(domain string) int { raw, err := s.GetConfigInDomain(domain, "auth_session_minutes") value, parseErr := strconv.Atoi(raw) if err != nil || parseErr != nil || value < 5 || value > MaxAuthSessionMinutes { return DefaultAuthSessionMinutes } return value } func (s *Store) SetAuthSessionLifetimeMinutes(domain string, minutes int) error { if minutes < 5 || minutes > MaxAuthSessionMinutes { return errors.New("session lifetime must be between 5 and 43200 minutes") } return s.SetConfigInDomain(domain, "auth_session_minutes", strconv.Itoa(minutes)) } func (s *Store) AuthSessionLifetime(domain string) time.Duration { return time.Duration(s.AuthSessionLifetimeMinutes(domain)) * time.Minute }