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

73 lines
1.5 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/pocket-id/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
2025-02-14 17:09:27 +01:00
Name string `sortable:"true"`
Secret string
CallbackURLs UrlList
LogoutCallbackURLs UrlList
ImageType *string
HasLogo bool `gorm:"-"`
IsPublic bool
PkceEnabled bool
2024-08-23 17:04:19 +02:00
AllowedUserGroups []UserGroup `gorm:"many2many:oidc_clients_allowed_user_groups;"`
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
}
2025-02-14 17:09:27 +01:00
type UrlList []string
2024-08-23 17:04:19 +02:00
2025-02-14 17:09:27 +01:00
func (cu *UrlList) 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
}
2025-02-14 17:09:27 +01:00
func (cu UrlList) Value() (driver.Value, error) {
return json.Marshal(cu)
}