Configuration
Config reference, YAML example, and options for Auth
YAML Configuration Example01
extensions:
auth:
enabled: true
defaultProvider: "jwt"
providers:
- name: "jwt"
type: "jwt"
config:
secret: "${JWT_SECRET}"
- name: "apikey"
type: "apikey"
config:
header: "X-API-Key"
The extension loads config from extensions.auth first, falling back to auth.
Programmatic Configuration02
ext := auth.NewExtension(
auth.WithEnabled(true),
auth.WithDefaultProvider("jwt"),
)
Auth providers are typically registered in your application code after the extension is loaded:
registry := auth.MustGetRegistry(app.Container())
registry.Register(myJWTProvider)
registry.Register(myAPIKeyProvider)
Config Struct Reference03
| Field | Type | Default | Description |
Enabled | bool | true | Enable the auth extension |
Providers | []ProviderConfig | [] | Provider configurations |
DefaultProvider | string | "" | Default provider name |
RequireConfig | bool | false | Require config from ConfigManager |
ProviderConfig
| Field | Type | Description |
Name | string | Provider name (unique identifier) |
Type | string | Provider type (e.g. "jwt", "apikey", "oauth2") |
Config | map[string]any | Provider-specific configuration |
Option Helpers04
| Function | Description |
WithEnabled(enabled) | Toggle the extension |
WithDefaultProvider(name) | Set the default provider |
WithRequireConfig(require) | Require config from ConfigManager |
WithConfig(config) | Provide a complete config struct |