Documentation
¶
Index ¶
- func ResolveAuth(app forge.App) (*authsome.Auth, error)
- type Config
- type ConfigOption
- func WithAuthMiddlewareConfig(config middleware.AuthMiddlewareConfig) ConfigOption
- func WithBasePath(path string) ConfigOption
- func WithCORSEnabled(enabled bool) ConfigOption
- func WithConfig(config Config) ConfigOption
- func WithDatabase(db *bun.DB) ConfigOption
- func WithDatabaseName(name string) ConfigOption
- func WithDisableOpenAPI(disable bool) ConfigOption
- func WithGeoIPProvider(provider security.GeoIPProvider) ConfigOption
- func WithGlobalCookieConfig(config session.CookieConfig) ConfigOption
- func WithPlugins(plugins ...plugins.Plugin) ConfigOption
- func WithRBACEnforcement(enabled bool) ConfigOption
- func WithRateLimitConfig(config ratelimit.Config) ConfigOption
- func WithRateLimitStorage(storage ratelimit.Storage) ConfigOption
- func WithRequireConfig(require bool) ConfigOption
- func WithSecret(secret string) ConfigOption
- func WithSecurityConfig(config security.Config) ConfigOption
- func WithSessionCookieEnabled(enabled bool) ConfigOption
- func WithSessionCookieName(name string) ConfigOption
- func WithTrustedOrigins(origins []string) ConfigOption
- type Extension
- func (e *Extension) Auth() *authsome.Auth
- func (e *Extension) ExcludeFromSchemas() bool
- func (e *Extension) GetBasePath() string
- func (e *Extension) GetDB() *bun.DB
- func (e *Extension) GetPluginRegistry() plugins.PluginRegistry
- func (e *Extension) GetServiceRegistry() *registry.ServiceRegistry
- func (e *Extension) Health(ctx context.Context) error
- func (e *Extension) Register(app forge.App) error
- func (e *Extension) RegisterPlugin(plugin plugins.Plugin) error
- func (e *Extension) Start(ctx context.Context) error
- func (e *Extension) Stop(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// DisableOpenAPI disables the OpenAPI documentation
DisableOpenAPI bool `yaml:"disableOpenAPI" json:"disableOpenAPI"`
// BasePath is the base path where auth routes are mounted
BasePath string `yaml:"basePath" json:"basePath"`
// Database configuration - mutually exclusive options
// Database is a direct database connection (takes precedence)
Database interface{} `yaml:"-" json:"-"`
// DatabaseName is the name of the database to use from DatabaseManager
DatabaseName string `yaml:"databaseName" json:"databaseName"`
// CORS configuration
CORSEnabled bool `yaml:"corsEnabled" json:"corsEnabled"`
TrustedOrigins []string `yaml:"trustedOrigins" json:"trustedOrigins"`
// Secret for signing tokens
Secret string `yaml:"secret" json:"secret"`
// RBACEnforce enables handler-level RBAC enforcement
RBACEnforce bool `yaml:"rbacEnforce" json:"rbacEnforce"`
// SecurityConfig for IP/country restrictions
SecurityConfig *security.Config `yaml:"security" json:"security"`
// RateLimitConfig for rate limiting
RateLimitConfig *ratelimit.Config `yaml:"rateLimit" json:"rateLimit"`
// RateLimitStorage is the storage backend for rate limiting
RateLimitStorage ratelimit.Storage `yaml:"-" json:"-"`
// GeoIPProvider for country-based restrictions
GeoIPProvider security.GeoIPProvider `yaml:"-" json:"-"`
// SessionCookie configures cookie-based session management
SessionCookie *session.CookieConfig `yaml:"sessionCookie" json:"sessionCookie"`
// AuthMiddlewareConfig configures the authentication middleware behavior
AuthMiddlewareConfig *middleware.AuthMiddlewareConfig `yaml:"authMiddleware" json:"authMiddleware"`
// Plugins to register with AuthSome
Plugins []plugins.Plugin `yaml:"-" json:"-"`
// RequireConfig determines if configuration must be loaded from file
RequireConfig bool `yaml:"-" json:"-"`
}
Config holds the configuration for the AuthSome extension
type ConfigOption ¶
type ConfigOption func(*Config)
ConfigOption is a functional option for configuring the extension
func WithAuthMiddlewareConfig ¶ added in v0.0.2
func WithAuthMiddlewareConfig(config middleware.AuthMiddlewareConfig) ConfigOption
WithAuthMiddlewareConfig sets the authentication middleware configuration This controls how the global authentication middleware behaves, including: - Session cookie name - Optional authentication (allow unauthenticated requests) - API key authentication settings - Context resolution (app/environment from headers or API key)
Example:
WithAuthMiddlewareConfig(middleware.AuthMiddlewareConfig{
SessionCookieName: "my_session",
Optional: true,
AllowAPIKeyInQuery: false, // Security best practice
AllowSessionInQuery: false, // Security best practice
Context: middleware.ContextConfig{
AutoDetectFromAPIKey: true,
AutoDetectFromConfig: true,
},
})
func WithBasePath ¶
func WithBasePath(path string) ConfigOption
WithBasePath sets the base path for routes
func WithCORSEnabled ¶ added in v0.0.2
func WithCORSEnabled(enabled bool) ConfigOption
WithCORSEnabled enables or disables CORS middleware
func WithConfig ¶
func WithConfig(config Config) ConfigOption
WithConfig sets the entire configuration
func WithDatabase ¶
func WithDatabase(db *bun.DB) ConfigOption
WithDatabase sets a direct database connection
func WithDatabaseName ¶
func WithDatabaseName(name string) ConfigOption
WithDatabaseName sets the database name to use from DatabaseManager
func WithDisableOpenAPI ¶ added in v0.0.2
func WithDisableOpenAPI(disable bool) ConfigOption
func WithGeoIPProvider ¶
func WithGeoIPProvider(provider security.GeoIPProvider) ConfigOption
WithGeoIPProvider sets the GeoIP provider
func WithGlobalCookieConfig ¶ added in v0.0.2
func WithGlobalCookieConfig(config session.CookieConfig) ConfigOption
WithGlobalCookieConfig sets the global cookie configuration for session management This configuration applies to all apps unless overridden at the app level Example:
WithGlobalCookieConfig(session.CookieConfig{
Enabled: true,
Name: "my_session",
HttpOnly: true,
SameSite: "Lax",
})
func WithPlugins ¶
func WithPlugins(plugins ...plugins.Plugin) ConfigOption
WithPlugins sets the plugins to register
func WithRBACEnforcement ¶
func WithRBACEnforcement(enabled bool) ConfigOption
WithRBACEnforcement enables/disables RBAC enforcement
func WithRateLimitConfig ¶
func WithRateLimitConfig(config ratelimit.Config) ConfigOption
WithRateLimitConfig sets rate limit configuration
func WithRateLimitStorage ¶
func WithRateLimitStorage(storage ratelimit.Storage) ConfigOption
WithRateLimitStorage sets the rate limit storage backend
func WithRequireConfig ¶
func WithRequireConfig(require bool) ConfigOption
WithRequireConfig sets whether configuration must be loaded from file
func WithSecret ¶
func WithSecret(secret string) ConfigOption
WithSecret sets the secret for token signing
func WithSecurityConfig ¶
func WithSecurityConfig(config security.Config) ConfigOption
WithSecurityConfig sets security configuration
func WithSessionCookieEnabled ¶ added in v0.0.2
func WithSessionCookieEnabled(enabled bool) ConfigOption
WithSessionCookieEnabled enables or disables cookie-based session management globally When enabled, authentication responses will automatically set secure HTTP cookies
func WithSessionCookieName ¶ added in v0.0.2
func WithSessionCookieName(name string) ConfigOption
WithSessionCookieName sets the session cookie name Default: "authsome_session"
func WithTrustedOrigins ¶
func WithTrustedOrigins(origins []string) ConfigOption
WithTrustedOrigins sets trusted origins for CORS and auto-enables CORS if origins provided
type Extension ¶
type Extension struct {
*forge.BaseExtension
// contains filtered or unexported fields
}
Extension implements the Forge extension interface for AuthSome
func NewExtension ¶
func NewExtension(opts ...ConfigOption) *Extension
NewExtension creates a new AuthSome extension with optional configuration
func ResolveExtension ¶
ResolveExtension resolves the AuthSome extension from a Forge app This allows you to access the extension instance after registration
func (*Extension) Auth ¶
Auth returns the AuthSome instance Use this to access AuthSome programmatically after extension is registered
func (*Extension) ExcludeFromSchemas ¶ added in v0.0.2
func (*Extension) GetBasePath ¶
GetBasePath returns the configured base path This is used by plugins to construct URLs
func (*Extension) GetDB ¶
GetDB returns the database instance This is used by plugins that need direct database access
func (*Extension) GetPluginRegistry ¶
func (e *Extension) GetPluginRegistry() plugins.PluginRegistry
GetPluginRegistry returns the plugin registry for plugin detection This is used by the dashboard plugin to detect which plugins are enabled
func (*Extension) GetServiceRegistry ¶
func (e *Extension) GetServiceRegistry() *registry.ServiceRegistry
GetServiceRegistry returns the service registry This is used by plugins that need access to core services
func (*Extension) RegisterPlugin ¶
RegisterPlugin registers a plugin before Start is called