1
0

session.go 1.3 KB

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