OAuth providers

Signed-off-by: Ronni Skansing <rskansing@gmail.com>
This commit is contained in:
Ronni Skansing
2025-11-20 23:54:00 +01:00
parent cff927d477
commit f6eb87fa2b
31 changed files with 2627 additions and 60 deletions
+36
View File
@@ -0,0 +1,36 @@
package database
import (
"time"
"github.com/google/uuid"
)
const (
OAUTH_STATE_TABLE = "oauth_states"
)
// OAuthState stores temporary state tokens for oauth flows
// used for csrf protection
type OAuthState struct {
ID uuid.UUID `gorm:"primary_key;not null;unique;type:uuid"`
CreatedAt *time.Time `gorm:"not null;index;"`
// the state token sent to oauth provider (random cryptographic token)
StateToken string `gorm:"not null;uniqueIndex;type:varchar(255);"`
// the oauth provider this state is for
OAuthProviderID uuid.UUID `gorm:"not null;index;type:uuid"`
OAuthProvider *OAuthProvider `gorm:"foreignkey:OAuthProviderID;"`
// expiration (state tokens expire after 10 minutes)
ExpiresAt *time.Time `gorm:"not null;index;"`
// whether this state token has been used (prevent replay attacks)
Used bool `gorm:"not null;default:false;index;"`
UsedAt *time.Time `gorm:"index;"`
}
func (OAuthState) TableName() string {
return OAUTH_STATE_TABLE
}