2024-08-12 11:00:25 +02:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
2024-08-23 17:04:19 +02:00
|
|
|
"database/sql/driver"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
2024-08-12 11:00:25 +02:00
|
|
|
"gorm.io/gorm"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UserAuthorizedOidcClient struct {
|
|
|
|
|
Scope string
|
2024-08-23 17:04:19 +02:00
|
|
|
UserID string `gorm:"primary_key;"`
|
2024-08-19 18:48:18 +02:00
|
|
|
User User
|
2024-08-12 11:00:25 +02:00
|
|
|
|
2024-08-23 17:04:19 +02:00
|
|
|
ClientID string `gorm:"primary_key;"`
|
2024-08-12 11:00:25 +02:00
|
|
|
Client OidcClient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OidcAuthorizationCode struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
Code string
|
|
|
|
|
Scope string
|
|
|
|
|
Nonce string
|
|
|
|
|
ExpiresAt time.Time
|
|
|
|
|
|
|
|
|
|
UserID string
|
|
|
|
|
User User
|
|
|
|
|
|
|
|
|
|
ClientID string
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 17:04:19 +02:00
|
|
|
type OidcClient struct {
|
|
|
|
|
Base
|
|
|
|
|
|
|
|
|
|
Name string
|
|
|
|
|
Secret string
|
|
|
|
|
CallbackURLs CallbackURLs
|
|
|
|
|
ImageType *string
|
|
|
|
|
HasLogo bool `gorm:"-"`
|
|
|
|
|
|
|
|
|
|
CreatedByID string
|
|
|
|
|
CreatedBy User
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-23 17:04:19 +02:00
|
|
|
func (c *OidcClient) AfterFind(_ *gorm.DB) (err error) {
|
|
|
|
|
// Compute HasLogo field
|
|
|
|
|
c.HasLogo = c.ImageType != nil && *c.ImageType != ""
|
|
|
|
|
return nil
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-23 17:04:19 +02:00
|
|
|
type CallbackURLs []string
|
|
|
|
|
|
|
|
|
|
func (s *CallbackURLs) Scan(value interface{}) error {
|
|
|
|
|
switch v := value.(type) {
|
|
|
|
|
case []byte:
|
|
|
|
|
return json.Unmarshal(v, s)
|
|
|
|
|
case string:
|
|
|
|
|
return json.Unmarshal([]byte(v), s)
|
|
|
|
|
default:
|
|
|
|
|
return errors.New("type assertion to []byte or string failed")
|
|
|
|
|
}
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
2024-08-17 21:57:14 +02:00
|
|
|
|
2024-08-23 17:04:19 +02:00
|
|
|
func (atl CallbackURLs) Value() (driver.Value, error) {
|
|
|
|
|
return json.Marshal(atl)
|
2024-08-17 21:57:14 +02:00
|
|
|
}
|