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

104 lines
1.9 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"
"fmt"
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
}
type OidcRefreshToken struct {
Base
Token string
ExpiresAt datatype.DateTime
Scope string
UserID string
User User
ClientID string
Client OidcClient
}
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-03-27 16:48:36 +01:00
type UrlList []string //nolint:recvcheck
2024-08-23 17:04:19 +02:00
2025-02-14 17:09:27 +01:00
func (cu *UrlList) Scan(value interface{}) error {
switch v := value.(type) {
case []byte:
return json.Unmarshal(v, cu)
case string:
return json.Unmarshal([]byte(v), cu)
default:
return fmt.Errorf("unsupported type: %T", value)
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)
}
type OidcDeviceCode struct {
Base
DeviceCode string
UserCode string
Scope string
ExpiresAt datatype.DateTime
IsAuthorized bool
UserID *string
User User
ClientID string
Client OidcClient
}