2024-01-01 10:31:45 +00:00
|
|
|
// Copyright (C) 2019 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
2023-01-03 09:18:30 +00:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2022-05-19 17:49:51 +00:00
|
|
|
package dataprovider
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SessionType defines the supported session types
|
|
|
|
type SessionType int
|
|
|
|
|
|
|
|
// Supported session types
|
|
|
|
const (
|
|
|
|
SessionTypeOIDCAuth SessionType = iota + 1
|
|
|
|
SessionTypeOIDCToken
|
|
|
|
SessionTypeResetCode
|
2023-06-03 14:17:32 +00:00
|
|
|
SessionTypeOAuth2Auth
|
2023-10-31 18:56:59 +00:00
|
|
|
SessionTypeInvalidToken
|
2024-03-11 17:19:57 +00:00
|
|
|
SessionTypeWebTask
|
2022-05-19 17:49:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Session defines a shared session persisted in the data provider
|
|
|
|
type Session struct {
|
|
|
|
Key string
|
|
|
|
Data any
|
|
|
|
Type SessionType
|
|
|
|
Timestamp int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Session) validate() error {
|
|
|
|
if s.Key == "" {
|
|
|
|
return errors.New("unable to save a session with an empty key")
|
|
|
|
}
|
2024-03-11 17:19:57 +00:00
|
|
|
if s.Type < SessionTypeOIDCAuth || s.Type > SessionTypeWebTask {
|
2022-05-19 17:49:51 +00:00
|
|
|
return fmt.Errorf("invalid session type: %v", s.Type)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|