Documentation
¶
Index ¶
- Constants
- type Account
- type AccountDatabaseHooksConfig
- type CSRFConfig
- type ChangeEmailConfig
- type Config
- type ConfigOption
- func WithAppName(name string) ConfigOption
- func WithBasePath(path string) ConfigOption
- func WithBaseURL(url string) ConfigOption
- func WithCSRF(csrfConfig CSRFConfig) ConfigOption
- func WithDatabase(db DatabaseConfig) ConfigOption
- func WithDatabaseHooks(databaseHooksConfig DatabaseHooksConfig) ConfigOption
- func WithEmailPassword(config EmailPasswordConfig) ConfigOption
- func WithEmailVerification(config EmailVerificationConfig) ConfigOption
- func WithEndpointHooks(endpointHooksConfig EndpointHooksConfig) ConfigOption
- func WithEventHooks(eventHooksConfig EventHooksConfig) ConfigOption
- func WithRateLimit(rateLimitConfig RateLimitConfig) ConfigOption
- func WithSecondaryStorage(storage SecondaryStorageConfig) ConfigOption
- func WithSecret(secret string) ConfigOption
- func WithSession(sessionConfig SessionConfig) ConfigOption
- func WithSocialProviders(socialProvidersConfig SocialProvidersConfig) ConfigOption
- func WithTrustedOrigins(trustedOriginsConfig TrustedOriginsConfig) ConfigOption
- func WithUser(userConfig UserConfig) ConfigOption
- type DatabaseConfig
- type DatabaseHooksConfig
- type DefaultOAuth2ProvidersConfig
- type EmailPasswordConfig
- type EmailVerificationConfig
- type EndpointHookContext
- type EndpointHooksConfig
- type EventHooksConfig
- type GenericOAuth2Config
- type GenericOAuth2EndpointConfig
- type IPConfig
- type KeyValueStore
- type OAuth2Config
- type PasswordConfig
- type ProviderType
- type RateLimitConfig
- type RateLimitCustomRule
- type RateLimitCustomRuleFunc
- type SecondaryStorage
- type SecondaryStorageConfig
- type SecondaryStorageDatabaseConfig
- type SecondaryStorageMemoryConfig
- type Session
- type SessionConfig
- type SessionDatabaseHooksConfig
- type SocialProvidersConfig
- type TrustedOriginsConfig
- type User
- type UserConfig
- type UserDatabaseHooksConfig
- type Verification
- type VerificationDatabaseHooksConfig
- type VerificationType
Constants ¶
View Source
const (
RateLimitAlgorithmFixedWindow = "fixed_window"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
ID string `json:"id" gorm:"primaryKey"`
UserID string `json:"user_id" gorm:"index"`
AccountID string `json:"account_id"`
ProviderID ProviderType `json:"provider_id"`
AccessToken *string `json:"access_token,omitempty"`
RefreshToken *string `json:"refresh_token,omitempty"`
IDToken *string `json:"id_token,omitempty"`
AccessTokenExpiresAt *time.Time `json:"access_token_expires_at,omitempty"`
RefreshTokenExpiresAt *time.Time `json:"refresh_token_expires_at,omitempty"`
Scope *string `json:"scope,omitempty"`
Password *string `json:"password,omitempty"` // for email/password auth
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
User User `gorm:"foreignKey:UserID"`
}
type CSRFConfig ¶ added in v1.0.4
type ChangeEmailConfig ¶
type Config ¶
type Config struct {
AppName string
BaseURL string
BasePath string
Secret string
Database DatabaseConfig
SecondaryStorage SecondaryStorageConfig
EmailPassword EmailPasswordConfig
EmailVerification EmailVerificationConfig
User UserConfig
Session SessionConfig
CSRF CSRFConfig
SocialProviders SocialProvidersConfig
TrustedOrigins TrustedOriginsConfig
RateLimit RateLimitConfig
EndpointHooks EndpointHooksConfig
DatabaseHooks DatabaseHooksConfig
EventHooks EventHooksConfig
}
Config holds all configurable options for the GoBetterAuth library.
func NewConfig ¶
func NewConfig(opts ...ConfigOption) *Config
NewConfig builds a Config using functional options with sensible defaults.
type ConfigOption ¶ added in v1.0.1
type ConfigOption func(*Config)
func WithAppName ¶ added in v1.0.1
func WithAppName(name string) ConfigOption
func WithBasePath ¶ added in v1.0.1
func WithBasePath(path string) ConfigOption
func WithBaseURL ¶ added in v1.0.1
func WithBaseURL(url string) ConfigOption
func WithCSRF ¶ added in v1.0.4
func WithCSRF(csrfConfig CSRFConfig) ConfigOption
func WithDatabase ¶ added in v1.0.1
func WithDatabase(db DatabaseConfig) ConfigOption
func WithDatabaseHooks ¶ added in v1.0.1
func WithDatabaseHooks(databaseHooksConfig DatabaseHooksConfig) ConfigOption
func WithEmailPassword ¶ added in v1.0.1
func WithEmailPassword(config EmailPasswordConfig) ConfigOption
func WithEmailVerification ¶ added in v1.0.1
func WithEmailVerification(config EmailVerificationConfig) ConfigOption
func WithEndpointHooks ¶ added in v1.0.3
func WithEndpointHooks(endpointHooksConfig EndpointHooksConfig) ConfigOption
func WithEventHooks ¶ added in v1.0.3
func WithEventHooks(eventHooksConfig EventHooksConfig) ConfigOption
func WithRateLimit ¶ added in v1.0.4
func WithRateLimit(rateLimitConfig RateLimitConfig) ConfigOption
func WithSecondaryStorage ¶ added in v1.0.4
func WithSecondaryStorage(storage SecondaryStorageConfig) ConfigOption
func WithSecret ¶ added in v1.0.1
func WithSecret(secret string) ConfigOption
func WithSession ¶ added in v1.0.1
func WithSession(sessionConfig SessionConfig) ConfigOption
func WithSocialProviders ¶ added in v1.0.4
func WithSocialProviders(socialProvidersConfig SocialProvidersConfig) ConfigOption
func WithTrustedOrigins ¶ added in v1.0.1
func WithTrustedOrigins(trustedOriginsConfig TrustedOriginsConfig) ConfigOption
func WithUser ¶ added in v1.0.1
func WithUser(userConfig UserConfig) ConfigOption
type DatabaseConfig ¶
type DatabaseHooksConfig ¶
type DatabaseHooksConfig struct {
Users *UserDatabaseHooksConfig
Accounts *AccountDatabaseHooksConfig
Sessions *SessionDatabaseHooksConfig
Verifications *VerificationDatabaseHooksConfig
}
type DefaultOAuth2ProvidersConfig ¶ added in v1.0.4
type DefaultOAuth2ProvidersConfig struct {
Google *OAuth2Config
GitHub *OAuth2Config
Discord *OAuth2Config
}
type EmailPasswordConfig ¶
type EmailVerificationConfig ¶
type EndpointHookContext ¶ added in v1.0.3
type EndpointHooksConfig ¶ added in v1.0.3
type EndpointHooksConfig struct {
Before func(ctx *EndpointHookContext) error
After func(ctx *EndpointHookContext) error
}
type EventHooksConfig ¶ added in v1.0.3
type GenericOAuth2Config ¶ added in v1.0.4
type GenericOAuth2Config struct {
OAuth2Config
Endpoint GenericOAuth2EndpointConfig
}
type GenericOAuth2EndpointConfig ¶ added in v1.0.4
type KeyValueStore ¶ added in v1.0.4
type KeyValueStore struct {
Key string `json:"key" gorm:"primaryKey"`
Value string `json:"value"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
KeyValueStore represents the persistent key-value store table in the database. This is a domain model used for secondary storage operations.
type OAuth2Config ¶ added in v1.0.4
type PasswordConfig ¶
type ProviderType ¶
type ProviderType string
const ( ProviderEmail ProviderType = "email" ProviderDiscord ProviderType = "discord" ProviderGitHub ProviderType = "github" ProviderGoogle ProviderType = "google" )
type RateLimitConfig ¶ added in v1.0.4
type RateLimitCustomRule ¶ added in v1.0.4
type RateLimitCustomRuleFunc ¶ added in v1.0.4
type RateLimitCustomRuleFunc func(req *http.Request) RateLimitCustomRule
type SecondaryStorage ¶ added in v1.0.4
type SecondaryStorage interface {
Get(ctx context.Context, key string) (any, error)
Set(ctx context.Context, key string, value any, ttl *time.Duration) error
Delete(ctx context.Context, key string) error
Incr(ctx context.Context, key string, ttl *time.Duration) (int, error)
}
SecondaryStorage defines an interface for secondary storage operations.
type SecondaryStorageConfig ¶ added in v1.0.4
type SecondaryStorageConfig struct {
Storage SecondaryStorage
}
type SecondaryStorageDatabaseConfig ¶ added in v1.0.4
type SecondaryStorageDatabaseConfig struct {
// CleanupInterval controls how often expired entries are cleaned up.
// If zero, the implementation should use a default.
CleanupInterval time.Duration
}
SecondaryStorageDatabaseConfig holds settings specific to the database storage.
type SecondaryStorageMemoryConfig ¶ added in v1.0.4
type SecondaryStorageMemoryConfig struct {
// CleanupInterval controls how often expired entries are cleaned up.
// If zero, the implementation should use a default.
CleanupInterval time.Duration
}
SecondaryStorageMemoryConfig holds settings specific to the in-memory storage.
type Session ¶
type Session struct {
ID string `json:"id" gorm:"primaryKey"`
UserID string `json:"user_id" gorm:"index"`
Token string `json:"token" gorm:"uniqueIndex"`
ExpiresAt time.Time `json:"expires_at"`
IPAddress *string `json:"ip_address,omitempty"`
UserAgent *string `json:"user_agent,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SessionConfig ¶
type SocialProvidersConfig ¶ added in v1.0.4
type SocialProvidersConfig struct {
Default DefaultOAuth2ProvidersConfig
Generic map[string]GenericOAuth2Config
}
type TrustedOriginsConfig ¶
type TrustedOriginsConfig struct {
Origins []string
}
type UserConfig ¶
type UserConfig struct {
ChangeEmail ChangeEmailConfig
}
type UserDatabaseHooksConfig ¶
type Verification ¶
type Verification struct {
ID string `json:"id" gorm:"primaryKey"`
UserID *string `json:"user_id,omitempty"`
Identifier string `json:"identifier"` // email or other identifier
Token string `json:"token"`
Type VerificationType `json:"type"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type VerificationDatabaseHooksConfig ¶
type VerificationDatabaseHooksConfig struct {
BeforeCreate func(verification *Verification) error
AfterCreate func(verification Verification) error
}
type VerificationType ¶
type VerificationType string
const ( TypeEmailVerification VerificationType = "email_verification" TypePasswordReset VerificationType = "password_reset" TypeEmailChange VerificationType = "email_change" )
Click to show internal directories.
Click to hide internal directories.