session.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (C) 2019 Nicola Murino
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Affero General Public License as published
  5. // by the Free Software Foundation, version 3.
  6. //
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU Affero General Public License for more details.
  11. //
  12. // You should have received a copy of the GNU Affero General Public License
  13. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. package dataprovider
  15. import (
  16. "errors"
  17. "fmt"
  18. )
  19. // SessionType defines the supported session types
  20. type SessionType int
  21. // Supported session types
  22. const (
  23. SessionTypeOIDCAuth SessionType = iota + 1
  24. SessionTypeOIDCToken
  25. SessionTypeResetCode
  26. SessionTypeOAuth2Auth
  27. SessionTypeInvalidToken
  28. SessionTypeWebTask
  29. )
  30. // Session defines a shared session persisted in the data provider
  31. type Session struct {
  32. Key string
  33. Data any
  34. Type SessionType
  35. Timestamp int64
  36. }
  37. func (s *Session) validate() error {
  38. if s.Key == "" {
  39. return errors.New("unable to save a session with an empty key")
  40. }
  41. if s.Type < SessionTypeOIDCAuth || s.Type > SessionTypeWebTask {
  42. return fmt.Errorf("invalid session type: %v", s.Type)
  43. }
  44. return nil
  45. }