Documentation
¶
Index ¶
- Variables
- func ErrNoSchema(driver string) error
- func GenerateSchema(driver, outPath string) error
- func GetSchema(driver string) (string, error)
- func SplitSQL(sql string) []string
- func WithApp(cfg AppConfig) func(*Config)
- func WithCookie(cfg CookieConfig) func(*Config)
- func WithEmail(cfg EmailConfig) func(*Config)
- func WithIPAddressHeader(header string) func(*Config)
- func WithIPv6Subnet(prefixLen int) func(*Config)
- func WithLogger(logger *slog.Logger) func(*Config)
- func WithMailer(m port.Mailer) func(*Config)
- func WithOrganizations(cfg OrganizationConfig) func(*Config)
- func WithProvider(p port.OAuthProvider) func(*Config)
- func WithRateLimit(cfg ratelimit.Config) func(*Config)
- func WithRateLimitDefault(r ratelimit.Rate) func(*Config)
- func WithRateLimitEnabled(enabled bool) func(*Config)
- func WithRateLimitRoute(pattern string, r ratelimit.Rate) func(*Config)
- func WithRateLimitStore(s ratelimit.Store) func(*Config)
- func WithRegistration(cfg RegistrationConfig) func(*Config)
- func WithSecurity(cfg SecurityConfig) func(*Config)
- func WithSession(cfg SessionConfig) func(*Config)
- func WithTemplates(p port.TemplateProvider) func(*Config)
- func WithTrustedIPs(ips []string) func(*Config)
- type AppConfig
- type Auth
- func (a *Auth) CheckSession(ctx context.Context, tokenRaw string) bool
- func (a *Auth) Close()
- func (a *Auth) CompleteInviteRegistration(ctx context.Context, input CompleteInviteInput) (*CompleteInviteResult, *domain.AuthError)
- func (a *Auth) GetSession(ctx context.Context, tokenRaw string) (*domain.User, *domain.Session, error)
- func (a *Auth) Login(ctx context.Context, input LoginInput) (*LoginResult, *domain.AuthError)
- func (a *Auth) Mount(mux *http.ServeMux)
- func (a *Auth) Register(ctx context.Context, input RegisterInput) (*RegisterResult, *domain.AuthError)
- type CompleteInviteInput
- type CompleteInviteResult
- type Config
- type CookieConfig
- type DatabaseConfig
- type Driver
- type EmailConfig
- type HandlerGroup
- type LoginInput
- type LoginResult
- type MiddlewareGroup
- type OrganizationConfig
- type RegisterInput
- type RegisterResult
- type RegistrationConfig
- type SMTPMailer
- type SecurityConfig
- type Services
- type SessionConfig
- type TLSMode
Constants ¶
This section is empty.
Variables ¶
var ErrNoDatabase = errors.New("go-auth: no database pool or DSN provided")
Functions ¶
func ErrNoSchema ¶
func GenerateSchema ¶
func WithCookie ¶
func WithCookie(cfg CookieConfig) func(*Config)
WithCookie sets the session cookie configuration.
func WithEmail ¶
func WithEmail(cfg EmailConfig) func(*Config)
WithEmail configures SMTP email delivery (transport only).
func WithIPAddressHeader ¶
WithIPAddressHeader sets which header to trust for client IP (e.g. "CF-Connecting-IP"). Requires TrustedIPs to be set - validated in Config.validate().
func WithIPv6Subnet ¶
WithIPv6Subnet sets the subnet prefix length used to bucket IPv6 clients for rate limiting.
func WithLogger ¶
WithLogger sets the structured logger.
func WithMailer ¶
WithMailer provides a custom mailer implementation.
func WithOrganizations ¶
func WithOrganizations(cfg OrganizationConfig) func(*Config)
WithOrganizations configures the organizations feature.
func WithProvider ¶
func WithProvider(p port.OAuthProvider) func(*Config)
WithProvider registers an OAuth provider. The provider's Name() must be non-empty and unique across all registered providers. Nil providers are rejected.
func WithRateLimit ¶
WithRateLimit configures rate limiting. Takes a value to force a copy at the call site, preventing shared mutation across separate NewConfig calls.
func WithRateLimitDefault ¶
WithRateLimitDefault overrides only the fallback rate applied to routes not present in Routes.
func WithRateLimitEnabled ¶
WithRateLimitEnabled toggles rate limiting on/off without touching Routes, Default, or Store.
func WithRateLimitRoute ¶
WithRateLimitRoute overrides or adds a single route's rate without replacing the rest of the Routes table.
func WithRateLimitStore ¶
WithRateLimitStore swaps the backing store (e.g. a Redis-backed Store) without touching Routes or Default.
func WithRegistration ¶
func WithRegistration(cfg RegistrationConfig) func(*Config)
WithRegistration configures which registration methods are available. Login is ALWAYS unconditional regardless of these settings.
func WithSecurity ¶
func WithSecurity(cfg SecurityConfig) func(*Config)
WithSecurity groups security-related settings.
func WithSession ¶
func WithSession(cfg SessionConfig) func(*Config)
WithSession groups session lifetime settings.
func WithTemplates ¶
func WithTemplates(p port.TemplateProvider) func(*Config)
WithTemplates provides a custom email template provider. When set, the provider's Render method is called for every email instead of the built-in default templates.
func WithTrustedIPs ¶
WithTrustedIPs sets the list of IPs/CIDRs trusted to supply IPAddressHeader.
Types ¶
type AppConfig ¶
type AppConfig struct {
Name string // app name displayed in emails
BaseURL string // frontend base URL for email links
Database DatabaseConfig // database connection
}
AppConfig groups the three identity-level settings for the application instance.
type Auth ¶
type Auth struct {
Config Config
Pool *pgxpool.Pool
DB *sqlstore.DB
Services Services
Handlers HandlerGroup
Middleware MiddlewareGroup
// contains filtered or unexported fields
}
func (*Auth) CheckSession ¶
CheckSession validates a raw session token and returns whether it is valid. It checks the session exists, is not expired, and the associated user exists and is not banned.
func (*Auth) CompleteInviteRegistration ¶
func (a *Auth) CompleteInviteRegistration(ctx context.Context, input CompleteInviteInput) (*CompleteInviteResult, *domain.AuthError)
func (*Auth) GetSession ¶
func (a *Auth) GetSession(ctx context.Context, tokenRaw string) (*domain.User, *domain.Session, error)
GetSession validates a raw session token and returns the associated user and session. Returns the user, session, and nil error on success. Returns nil, nil, error if the token is invalid, expired, or the user is banned.
func (*Auth) Login ¶
func (a *Auth) Login(ctx context.Context, input LoginInput) (*LoginResult, *domain.AuthError)
func (*Auth) Register ¶
func (a *Auth) Register(ctx context.Context, input RegisterInput) (*RegisterResult, *domain.AuthError)
type CompleteInviteInput ¶
type CompleteInviteResult ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is the top-level configuration for go-auth. All fields are unexported — use NewConfig + With* functions.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type CookieConfig ¶
type CookieConfig struct {
Name string
Domain string
Path string
Secure bool
SameSite http.SameSite
}
CookieConfig configures the session cookie.
type DatabaseConfig ¶
type DatabaseConfig struct {
URL string // connection string (preferred)
DB *sql.DB // pre-opened *sql.DB (library borrows, does not close)
Pool *pgxpool.Pool // pre-opened pgx pool (library borrows, does not close)
Driver Driver // DriverPostgres (default), DriverSQLite, DriverMySQL
// contains filtered or unexported fields
}
DatabaseConfig configures the database connection. Provide one of URL, DB, or Pool. URL is the preferred option — the library will open, validate, and close the connection automatically.
type EmailConfig ¶
type EmailConfig struct {
From string
Host string
Port int
User string
Pass string
TLSMode TLSMode
AllowHTTPURLs bool // allow http:// URLs in email templates (dev only, default false)
}
EmailConfig configures SMTP email delivery (transport only).
type HandlerGroup ¶
type HandlerGroup struct {
Register http.HandlerFunc
Login http.HandlerFunc
Logout http.HandlerFunc
ForgotPassword http.HandlerFunc
ResetPassword http.HandlerFunc
ChangePassword http.HandlerFunc
SetPasswordRequest http.HandlerFunc
SetPasswordConfirm http.HandlerFunc
VerifyEmail http.HandlerFunc
ResendVerification http.HandlerFunc
ResendVerificationPublic http.HandlerFunc
ListSessions http.HandlerFunc
RevokeSession http.HandlerFunc
RevokeAllSessions http.HandlerFunc
InviteRegister http.HandlerFunc
CheckSession http.HandlerFunc
RefreshToken http.HandlerFunc
GetMe http.HandlerFunc
ChangeName http.HandlerFunc
DeleteAccount http.HandlerFunc
RequestDeleteAccount http.HandlerFunc
ConfirmDeleteAccount http.HandlerFunc
ListUsers http.HandlerFunc
UpdateUserRole http.HandlerFunc
BanUser http.HandlerFunc
UnbanUser http.HandlerFunc
DeleteUser http.HandlerFunc
RevokeUserSessions http.HandlerFunc
AdminCreateUser http.HandlerFunc
AdminListUserSessions http.HandlerFunc
AdminRevokeUserSession http.HandlerFunc
GetInviteInfo http.HandlerFunc
CreateInvite http.HandlerFunc
ListInvites http.HandlerFunc
RevokeInvite http.HandlerFunc
ResendInvite http.HandlerFunc
HardDeleteInvite http.HandlerFunc
OAuthInitiate http.HandlerFunc
OAuthCallback http.HandlerFunc
OAuthLink http.HandlerFunc
OAuthUnlink http.HandlerFunc
OAuthProviders http.HandlerFunc
CSRFToken http.HandlerFunc
CreateOrg http.HandlerFunc
GetOrg http.HandlerFunc
UpdateOrg http.HandlerFunc
DeleteOrg http.HandlerFunc
ListUserOrgs http.HandlerFunc
ListOrgMembers http.HandlerFunc
RemoveOrgMember http.HandlerFunc
UpdateOrgMemberRole http.HandlerFunc
LeaveOrg http.HandlerFunc
SetActiveOrg http.HandlerFunc
ClearActiveOrg http.HandlerFunc
CreateOrgInvite http.HandlerFunc
AcceptOrgInvite http.HandlerFunc
ListOrgInvites http.HandlerFunc
ResendOrgInvite http.HandlerFunc
DeleteOrgInvite http.HandlerFunc
}
type LoginInput ¶
type LoginResult ¶
type MiddlewareGroup ¶
type OrganizationConfig ¶
type OrganizationConfig struct {
Enable bool // enable orgs feature (default false)
MaxOrgsPerUser int // max orgs a user can own (0=default 100, >100 rejected)
InviteTTL time.Duration // how long org invites last (default 7d)
}
OrganizationConfig controls the organizations feature.
type RegisterInput ¶
type RegisterResult ¶
type RegistrationConfig ¶
type RegistrationConfig struct {
EnableEmailPassword bool // email+password registration (default true)
EnableOAuth bool // OAuth signup for new users (default true)
EnableInvite bool // invite-code registration (default true)
AllowPublic bool // public registration is allowed (default true)
RequireEmailVerification bool // require email verification on signup (default false)
InviteTTL time.Duration // how long signup invites last (default 7d)
VerificationCodeTTL time.Duration // how long verification codes live (default 15m)
}
RegistrationConfig controls which registration methods are available. Login is ALWAYS unconditional regardless of these flags.
type SMTPMailer ¶
type SMTPMailer struct {
// contains filtered or unexported fields
}
type SecurityConfig ¶
type SecurityConfig struct {
AllowedOrigins []string // allowed origins for CSRF Origin/Referer check
AllowMissingCSRFHeaders bool // allow requests without Origin/Referer headers (default false)
CSRFToken *middleware.CSRFTokenConfig // double-submit cookie CSRF (optional, disabled by default)
PasswordPolicy domain.PasswordPolicy // password complexity requirements
TokenTTL time.Duration // how long verification/reset tokens live (default 1h)
}
SecurityConfig groups security-related settings.
type Services ¶
type Services struct {
Auth *service.AuthService
Password *service.PasswordService
Session *service.SessionService
Verify *service.VerificationService
Invite *service.InviteService
Admin *service.AdminService
OAuth *service.OAuthService
Org *service.OrgService
OrgInvite *service.OrgInviteService
}
type SessionConfig ¶
type SessionConfig struct {
TTL time.Duration // absolute hard expiry (default 30d)
IdleTTL time.Duration // idle timeout after last activity (default 7d)
RefreshTokenTTL time.Duration // refresh token absolute expiry (default 30d)
MaxLifetime time.Duration // max session lifetime from created_at (0 = no limit)
GraceWindow time.Duration // grace period for reusing old refresh token (default 10s)
TouchDebounce time.Duration // minimum interval between last_active_at updates (default 5m)
}
SessionConfig groups session lifetime settings.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package emailtemplate provides the default email template provider for go-auth.
|
Package emailtemplate provides the default email template provider for go-auth. |
|
internal
|
|
|
provider
|
|