init: Initial commit

This commit is contained in:
Björn Benouarets
2026-01-21 06:36:38 +01:00
commit 346100feb6
27 changed files with 1126 additions and 0 deletions

41
app/models/application.go Normal file
View File

@@ -0,0 +1,41 @@
package models
import (
"time"
"git.secnex.io/secnex/oauth2-api/utils"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Application struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
Name string `gorm:"not null" json:"name"`
Secret string `gorm:"not null" json:"secret"`
TenantID uuid.UUID `gorm:"type:uuid" json:"tenant_id"`
ExpiresAt *time.Time `gorm:"not null" json:"expires_at"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
Tenant *Tenant `gorm:"foreignKey:TenantID" json:"tenant"`
Authorizations []Authorization `gorm:"foreignKey:ClientID" json:"authorizations"`
}
func (Application) TableName() string {
return "applications"
}
func (application *Application) BeforeCreate(tx *gorm.DB) (err error) {
secretHash, err := utils.Hash(application.Secret)
if err != nil {
return err
}
application.Secret = secretHash
if application.ExpiresAt == nil {
expiresAt := time.Now().Add(time.Hour * 24 * 365)
application.ExpiresAt = &expiresAt
}
return nil
}