Auth

Configuration

Config reference, YAML example, and options for Auth

YAML Configuration Example

config.yaml
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 Configuration

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 Reference

FieldTypeDefaultDescription
EnabledbooltrueEnable the auth extension
Providers[]ProviderConfig[]Provider configurations
DefaultProviderstring""Default provider name
RequireConfigboolfalseRequire config from ConfigManager

ProviderConfig

FieldTypeDescription
NamestringProvider name (unique identifier)
TypestringProvider type (e.g. "jwt", "apikey", "oauth2")
Configmap[string]anyProvider-specific configuration

Option Helpers

FunctionDescription
WithEnabled(enabled)Toggle the extension
WithDefaultProvider(name)Set the default provider
WithRequireConfig(require)Require config from ConfigManager
WithConfig(config)Provide a complete config struct

How is this guide?

On this page