diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2025-03-09 01:53:44 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-09 01:53:44 +1100 |
| commit | 9241731a4dd5592b4a02b5352c903b4d06b6f4ab (patch) | |
| tree | 5184b98751912a261ff70fd8721b9cd4f1c98f1e /internal/middlewares/util.go | |
| parent | bbcb38ab9ff35e69d5d52a71ab56346749f5e8b1 (diff) | |
feat(embed): make authelia embedable (#8841)
This adds a highly experimental option for developers looking to embed Authelia within another go binary.
Closes #5803
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/middlewares/util.go')
| -rw-r--r-- | internal/middlewares/util.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/internal/middlewares/util.go b/internal/middlewares/util.go index 03b80f557..7a7eb39e4 100644 --- a/internal/middlewares/util.go +++ b/internal/middlewares/util.go @@ -1,7 +1,26 @@ package middlewares import ( + "crypto/x509" + "github.com/valyala/fasthttp" + + "github.com/authelia/authelia/v4/internal/authentication" + "github.com/authelia/authelia/v4/internal/authorization" + "github.com/authelia/authelia/v4/internal/clock" + "github.com/authelia/authelia/v4/internal/configuration/schema" + "github.com/authelia/authelia/v4/internal/expression" + "github.com/authelia/authelia/v4/internal/metrics" + "github.com/authelia/authelia/v4/internal/notification" + "github.com/authelia/authelia/v4/internal/ntp" + "github.com/authelia/authelia/v4/internal/oidc" + "github.com/authelia/authelia/v4/internal/random" + "github.com/authelia/authelia/v4/internal/regulation" + "github.com/authelia/authelia/v4/internal/session" + "github.com/authelia/authelia/v4/internal/storage" + "github.com/authelia/authelia/v4/internal/templates" + "github.com/authelia/authelia/v4/internal/totp" + "github.com/authelia/authelia/v4/internal/webauthn" ) // SetContentTypeApplicationJSON sets the Content-Type header to `application/json; charset=utf-8`. @@ -13,3 +32,48 @@ func SetContentTypeApplicationJSON(ctx *fasthttp.RequestCtx) { func SetContentTypeTextPlain(ctx *fasthttp.RequestCtx) { ctx.SetContentTypeBytes(contentTypeTextPlain) } + +// NewProviders provisions all providers based on the configuration provided. +func NewProviders(config *schema.Configuration, caCertPool *x509.CertPool) (providers Providers, warns, errs []error) { + providers.Random = &random.Cryptographical{} + providers.StorageProvider = storage.NewProvider(config, caCertPool) + providers.Authorizer = authorization.NewAuthorizer(config) + providers.NTP = ntp.NewProvider(&config.NTP) + providers.PasswordPolicy = NewPasswordPolicyProvider(config.PasswordPolicy) + providers.Regulator = regulation.NewRegulator(config.Regulation, providers.StorageProvider, clock.New()) + providers.SessionProvider = session.NewProvider(config.Session, caCertPool) + providers.TOTP = totp.NewTimeBasedProvider(config.TOTP) + providers.UserAttributeResolver = expression.NewUserAttributes(config) + + var err error + + switch { + case config.AuthenticationBackend.File != nil: + providers.UserProvider = authentication.NewFileUserProvider(config.AuthenticationBackend.File) + case config.AuthenticationBackend.LDAP != nil: + providers.UserProvider = authentication.NewLDAPUserProvider(config.AuthenticationBackend, caCertPool) + } + + if providers.Templates, err = templates.New(templates.Config{EmailTemplatesPath: config.Notifier.TemplatePath}); err != nil { + errs = append(errs, err) + } + + if providers.MetaDataService, err = webauthn.NewMetaDataProvider(config, providers.StorageProvider); err != nil { + errs = append(errs, err) + } + + switch { + case config.Notifier.SMTP != nil: + providers.Notifier = notification.NewSMTPNotifier(config.Notifier.SMTP, caCertPool) + case config.Notifier.FileSystem != nil: + providers.Notifier = notification.NewFileNotifier(*config.Notifier.FileSystem) + } + + providers.OpenIDConnect = oidc.NewOpenIDConnectProvider(config, providers.StorageProvider, providers.Templates) + + if config.Telemetry.Metrics.Enabled { + providers.Metrics = metrics.NewPrometheus() + } + + return providers, warns, errs +} |
