models

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	ID            string `gorm:"primaryKey"`
	Token         string `gorm:"uniqueIndex;not null"`
	TokenType     string `gorm:"not null;default:'Bearer'"`
	TokenCategory string `gorm:"not null;default:'access';index"` // 'access' or 'refresh'
	Status        string `gorm:"not null;default:'active';index"` // 'active', 'disabled', 'revoked'
	UserID        string `gorm:"not null;index"`
	ClientID      string `gorm:"not null;index"`
	Scopes        string `gorm:"not null"` // space-separated scopes
	ExpiresAt     time.Time
	CreatedAt     time.Time
	LastUsedAt    *time.Time `gorm:"index"` // Last time token was used (for refresh tokens)
	ParentTokenID string     `gorm:"index"` // Links access tokens to their refresh token
}

func (*AccessToken) IsActive added in v0.3.0

func (t *AccessToken) IsActive() bool

IsActive returns true if token status is 'active'

func (*AccessToken) IsDisabled added in v0.3.0

func (t *AccessToken) IsDisabled() bool

IsDisabled returns true if token status is 'disabled'

func (*AccessToken) IsExpired

func (t *AccessToken) IsExpired() bool

func (*AccessToken) IsRevoked added in v0.3.0

func (t *AccessToken) IsRevoked() bool

IsRevoked returns true if token status is 'revoked'

type DeviceCode

type DeviceCode struct {
	DeviceCode   string `gorm:"primaryKey"`
	UserCode     string `gorm:"uniqueIndex;not null"`
	ClientID     string `gorm:"not null;index"`
	Scopes       string `gorm:"not null"` // space-separated scopes
	ExpiresAt    time.Time
	Interval     int    // polling interval in seconds
	UserID       string // filled after authorization
	Authorized   bool   `gorm:"default:false"`
	AuthorizedAt time.Time
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

func (*DeviceCode) IsExpired

func (d *DeviceCode) IsExpired() bool

type OAuthClient

type OAuthClient struct {
	ClientID     string `gorm:"primaryKey"`
	ClientSecret string `gorm:"not null"` // bcrypt hashed secret
	ClientName   string `gorm:"not null"`
	Description  string `gorm:"type:text"`
	Scopes       string `gorm:"not null"`                       // space-separated scopes
	GrantTypes   string `gorm:"not null;default:'device_code'"` // comma-separated grant types
	RedirectURIs string `gorm:"type:text"`                      // comma-separated redirect URIs
	IsActive     bool   `gorm:"not null;default:true"`
	CreatedBy    string // User ID who created this client
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

func (OAuthClient) TableName

func (OAuthClient) TableName() string

TableName overrides the table name used by OAuthClient to `oauth_client`

type User

type User struct {
	ID           string `gorm:"primaryKey"`
	Username     string `gorm:"uniqueIndex;not null"`
	PasswordHash string `gorm:"not null"`
	Role         string `gorm:"not null;default:'user'"` // "admin" or "user"

	// External authentication support
	ExternalID string `gorm:"index"`           // External user ID (e.g., from HTTP API)
	AuthSource string `gorm:"default:'local'"` // "local" or "http_api"
	Email      string // User email (optional)
	FullName   string // User full name (optional)

	CreatedAt time.Time
	UpdatedAt time.Time
}

func (*User) IsAdmin added in v0.2.0

func (u *User) IsAdmin() bool

IsAdmin returns true if the user has admin role

func (*User) IsExternal added in v0.3.0

func (u *User) IsExternal() bool

IsExternal returns true if user authenticates via external provider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL