session.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2019-2023 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. )
  28. // Session defines a shared session persisted in the data provider
  29. type Session struct {
  30. Key string
  31. Data any
  32. Type SessionType
  33. Timestamp int64
  34. }
  35. func (s *Session) validate() error {
  36. if s.Key == "" {
  37. return errors.New("unable to save a session with an empty key")
  38. }
  39. if s.Type < SessionTypeOIDCAuth || s.Type > SessionTypeOAuth2Auth {
  40. return fmt.Errorf("invalid session type: %v", s.Type)
  41. }
  42. return nil
  43. }