Documentation
¶
Index ¶
- Constants
- func AllowNamed(r *http.Request, rl RateLimiter, bucket string) bool
- func DefaultRateLimits() map[string]Limit
- func JWKSHandler(svc core.Verifier) http.Handler
- func LanguageMiddleware(cfg *LanguageConfig) func(http.Handler) http.Handler
- func Optional(svc core.Verifier) func(http.Handler) http.Handler
- func RequireAdmin(pg *pgxpool.Pool) func(http.Handler) http.Handler
- func Required(svc core.Verifier) func(http.Handler) http.Handler
- func ToMemoryLimits(in map[string]Limit) map[string]memorylimiter.Limit
- func ToRedisLimits(in map[string]Limit) map[string]redislimiter.Limit
- type Claims
- type ClientIPFunc
- type LanguageConfig
- type Limit
- type RateLimiter
- type Service
- func (s *Service) APIHandler() http.Handler
- func (s *Service) Core() *core.Service
- func (s *Service) DisableRateLimiter() *Service
- func (s *Service) JWKSHandler() http.Handler
- func (s *Service) OIDCHandler() http.Handler
- func (s *Service) WithAuthLogReader(r core.AuthEventLogReader) *Service
- func (s *Service) WithAuthLogger(l core.AuthEventLogger) *Service
- func (s *Service) WithClientIPFunc(fn ClientIPFunc) *Service
- func (s *Service) WithEmailSender(es core.EmailSender) *Service
- func (s *Service) WithEntitlements(p core.EntitlementsProvider) *Service
- func (s *Service) WithEphemeralStore(store core.EphemeralStore, mode core.EphemeralMode) *Service
- func (s *Service) WithLanguageConfig(cfg LanguageConfig) *Service
- func (s *Service) WithPostgres(pg *pgxpool.Pool) *Service
- func (s *Service) WithRateLimiter(rl RateLimiter) *Service
- func (s *Service) WithRedis(rd *redis.Client) *Service
- func (s *Service) WithSMSSender(sender core.SMSSender) *Service
- func (s *Service) WithSolanaDomain(domain string) *Service
- type Verifier
- func (v *Verifier) AcceptConfig() core.AcceptConfig
- func (v *Verifier) GetEmailByUserID(ctx context.Context, id string) (string, error)
- func (v *Verifier) GetProviderUsername(ctx context.Context, userID, provider string) (string, error)
- func (v *Verifier) JWKS() jwtkit.JWKS
- func (v *Verifier) Keyfunc() func(token *jwt.Token) (any, error)
- func (v *Verifier) ListRoleSlugsByUser(ctx context.Context, userID string) []string
- func (v *Verifier) Options() core.Options
- func (v *Verifier) Verify(tokenStr string) (jwt.MapClaims, error)
- func (v *Verifier) WithHTTPClient(c *http.Client) *Verifier
- func (v *Verifier) WithService(svc *core.Service) *Verifier
Constants ¶
const ( // 2FA-specific rate limit buckets RL2FAStartPhone = "auth_2fa_start_phone" RL2FAEnable = "auth_2fa_enable" RL2FADisable = "auth_2fa_disable" RL2FARegenerateCodes = "auth_2fa_regenerate_codes" RL2FAVerify = "auth_2fa_verify" RLAuthToken = "auth_token" RLAuthRegister = "auth_register" RLAuthRegisterResendEmail = "auth_register_resend_email" RLAuthRegisterResendPhone = "auth_register_resend_phone" RLPasswordLogin = "auth_password_login" RLAuthLogout = "auth_logout" RLAuthSessionsCurrent = "auth_sessions_current" RLAuthSessionsList = "auth_sessions_list" RLAuthSessionsRevoke = "auth_sessions_revoke" RLAuthSessionsRevokeAll = "auth_sessions_revoke_all" RLPasswordResetRequest = "auth_pwd_reset_request" RLPasswordResetConfirm = "auth_pwd_reset_confirm" RLEmailVerifyRequest = "auth_email_verify_request" RLEmailVerifyConfirm = "auth_email_verify_confirm" RLPhoneVerifyRequest = "auth_phone_verify_request" RLOIDCStart = "auth_oidc_start" RLOIDCCallback = "auth_oidc_callback" RLUserPasswordChange = "auth_user_password_change" RLUserMe = "auth_user_me" RLUserUpdateUsername = "auth_user_update_username" RLUserUpdateEmail = "auth_user_update_email" RLUserEmailChangeRequest = "auth_user_email_change_request" RLUserEmailChangeConfirm = "auth_user_email_change_confirm" RLUserEmailChangeResend = "auth_user_email_change_resend" RLUserPhoneChangeRequest = "auth_user_phone_change_request" RLUserPhoneChangeConfirm = "auth_user_phone_change_confirm" RLUserPhoneChangeResend = "auth_user_phone_change_resend" RLUserDelete = "auth_user_delete" RLUserUnlinkProvider = "auth_user_unlink_provider" RLAdminRolesGrant = "auth_admin_roles_grant" RLAdminRolesRevoke = "auth_admin_roles_revoke" RLAdminUserSessionsList = "auth_admin_user_sessions_list" RLAdminUserSessionsRevoke = "auth_admin_user_sessions_revoke" RLAdminUserSessionsRevokeAll = "auth_admin_user_sessions_revoke_all" // Solana SIWS authentication RLSolanaChallenge = "auth_solana_challenge" RLSolanaLogin = "auth_solana_login" RLSolanaLink = "auth_solana_link" )
Bucket names used by authkit endpoints.
Variables ¶
This section is empty.
Functions ¶
func AllowNamed ¶
func AllowNamed(r *http.Request, rl RateLimiter, bucket string) bool
AllowNamed applies a per-IP limit using the provided bucket name. It fails open on limiter error.
func DefaultRateLimits ¶
DefaultRateLimits returns AuthKit's built-in per-endpoint rate limits.
These limits are enforced per client IP (as determined by the Service's ClientIPFunc). Hosts can override by supplying their own limiter via WithRateLimiter(...).
func JWKSHandler ¶
JWKSHandler serves the public JWKS document.
func LanguageMiddleware ¶
func LanguageMiddleware(cfg *LanguageConfig) func(http.Handler) http.Handler
LanguageMiddleware infers request language and attaches it to the request context.
func RequireAdmin ¶
RequireAdmin verifies JWT then checks admin role directly in Postgres.
func Required ¶
Required validates the Bearer token (JWT), enforces iss/aud/exp, and stores claims in request context.
func ToMemoryLimits ¶
func ToMemoryLimits(in map[string]Limit) map[string]memorylimiter.Limit
func ToRedisLimits ¶
func ToRedisLimits(in map[string]Limit) map[string]redislimiter.Limit
Types ¶
type Claims ¶
type Claims struct {
UserID string
Email string
EmailVerified bool
Username string
DiscordUsername string
SessionID string
Roles []string
Entitlements []string
}
Claims is a typed view of authenticated user information attached by middleware.
func (Claims) HasEntitlement ¶
type ClientIPFunc ¶
ClientIPFunc determines the client IP used for rate limiting and auditing.
Returning an empty string means "unknown" and causes rate limiting to fail open.
func ClientIPFromForwardedHeaders ¶
func ClientIPFromForwardedHeaders(trustedProxies []netip.Prefix) ClientIPFunc
ClientIPFromForwardedHeaders trusts CF-Connecting-IP and X-Forwarded-For only when the immediate peer (RemoteAddr) is in trustedProxies. Otherwise it falls back to DefaultClientIP behavior.
func DefaultClientIP ¶
func DefaultClientIP() ClientIPFunc
DefaultClientIP returns a conservative client IP strategy:
- If RemoteAddr is a public IP, use it.
- If RemoteAddr is private/loopback/etc, return "" (fail open) so we don't accidentally rate-limit a reverse proxy/ingress as a single client.
Hosts behind proxies should configure a forwarded-header strategy with a trusted proxy list.
type LanguageConfig ¶
type RateLimiter ¶
RateLimiter is a minimal interface used by adapters.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service wraps core.Service with net/http mounting helpers.
func NewService ¶
NewService constructs a core.Service and wraps it for net/http mounting. Returns an error if the core service fails to initialize (e.g., missing keys in production).
func (*Service) APIHandler ¶
APIHandler returns a handler that serves the JSON API routes under /auth/*. It is intended to be mounted under the host's mux/router at any prefix.
func (*Service) DisableRateLimiter ¶
func (*Service) JWKSHandler ¶
JWKSHandler returns a handler for GET /.well-known/jwks.json.
func (*Service) OIDCHandler ¶
OIDCHandler returns a handler that serves browser redirect flows: - GET /auth/oidc/{provider}/login - GET /auth/oidc/{provider}/callback - GET /auth/oauth/discord/login (if configured) - GET /auth/oauth/discord/callback (if configured)
func (*Service) WithAuthLogReader ¶ added in v0.4.2
func (s *Service) WithAuthLogReader(r core.AuthEventLogReader) *Service
func (*Service) WithAuthLogger ¶
func (s *Service) WithAuthLogger(l core.AuthEventLogger) *Service
func (*Service) WithClientIPFunc ¶
func (s *Service) WithClientIPFunc(fn ClientIPFunc) *Service
func (*Service) WithEmailSender ¶
func (s *Service) WithEmailSender(es core.EmailSender) *Service
func (*Service) WithEntitlements ¶
func (s *Service) WithEntitlements(p core.EntitlementsProvider) *Service
func (*Service) WithEphemeralStore ¶
func (s *Service) WithEphemeralStore(store core.EphemeralStore, mode core.EphemeralMode) *Service
func (*Service) WithLanguageConfig ¶
func (s *Service) WithLanguageConfig(cfg LanguageConfig) *Service
func (*Service) WithRateLimiter ¶
func (s *Service) WithRateLimiter(rl RateLimiter) *Service
func (*Service) WithSolanaDomain ¶
WithSolanaDomain sets the domain used in SIWS sign-in messages. If not set, the domain is derived from the request Origin or Host header.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier validates JWTs from one or more issuers using remote JWKS (verify-only mode). It also exposes Optional/Required middleware via adapters/http/middleware.go.
func NewVerifier ¶
func NewVerifier(accept core.AcceptConfig) *Verifier
func (*Verifier) AcceptConfig ¶
func (v *Verifier) AcceptConfig() core.AcceptConfig
AcceptConfig exposes the accept configuration (used by middleware).
func (*Verifier) GetEmailByUserID ¶
func (*Verifier) GetProviderUsername ¶
func (*Verifier) ListRoleSlugsByUser ¶
Source Files
¶
- admin_routes.go
- admin_signins.go
- audit.go
- auth_sessions_current_post.go
- auth_token_post.go
- buckets.go
- claims.go
- client_ip.go
- discord_link_start_post.go
- discord_oauth_browser.go
- email_verify.go
- email_verify_confirm_link_post.go
- errors.go
- handlers.go
- jwks_get.go
- language.go
- logout_delete.go
- middleware.go
- oidc_browser.go
- oidc_handler.go
- oidc_link_start_post.go
- oidc_util.go
- password_login_post.go
- password_reset.go
- phone_password_reset.go
- phone_verify.go
- ratelimit.go
- ratelimit_defaults.go
- register.go
- service.go
- siws_cache.go
- solana_siws.go
- user_2fa.go
- user_2fa_verify_post.go
- user_me_get.go
- user_password_post.go
- user_routes.go
- user_sessions.go
- util.go
- validate.go
- verifier.go