Files
pocket-id-pocket-id-2/backend/internal/model/oidc.go

69 lines
1.3 KiB
Go
Raw Normal View History

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"
datatype "github.com/stonith404/pocket-id/backend/internal/model/types"
2024-08-12 11:00:25 +02:00
"gorm.io/gorm"
)
type UserAuthorizedOidcClient struct {
Scope string
2024-08-23 17:04:19 +02:00
UserID string `gorm:"primary_key;"`
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
2024-11-15 15:00:25 +01:00
Code string
Scope string
Nonce string
CodeChallenge *string
CodeChallengeMethodSha256 *bool
ExpiresAt datatype.DateTime
2024-08-12 11:00:25 +02:00
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:"-"`
2024-11-15 15:00:25 +01:00
IsPublic bool
2024-08-23 17:04:19 +02:00
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 (cu *CallbackURLs) Scan(value interface{}) error {
if v, ok := value.([]byte); ok {
return json.Unmarshal(v, cu)
} else {
return errors.New("type assertion to []byte failed")
2024-08-23 17:04:19 +02:00
}
2024-08-12 11:00:25 +02:00
}
func (cu CallbackURLs) Value() (driver.Value, error) {
return json.Marshal(cu)
}