Documentation
¶
Index ¶
Constants ¶
View Source
const ( // CredsFieldName is the command-line flag for inline credentials. // Format: "username1:password1,username2:password2" CredsFieldName = "server.http.auth.basic.creds" // FilePathFieldName is the command-line flag for credentials file. // File should contain one "username:password" per line. FilePathFieldName = "server.http.auth.basic.filepath" )
Variables ¶
View Source
var Component = &component.Component{ Init: component.StepFunc(func(container container.Container) error { return container.Provides( NewConfig, NewAuth, ) }), Configuration: component.StepFunc(func(container container.Container) error { return container.Invoke(Configuration) }), }
Component is a ready-to-use Compogo component that provides HTTP Basic Authentication middleware.
Usage:
compogo.WithComponents(
http.Component,
basic.Component,
)
Then in your router setup:
router.Use(basicAuth.Middleware)
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth implements HTTP Basic Authentication middleware. It validates incoming requests against configured credentials.
func (*Auth) Middleware ¶
Middleware implements the http.Middleware interface. It checks for valid Basic Authentication credentials:
- If no credentials or invalid credentials, returns 401 Unauthorized
- If valid, passes the request to the next handler
type Config ¶
type Config struct {
FilePath string
Creds mapper.Mapper[*Cred]
// contains filtered or unexported fields
}
Config holds the basic authentication configuration. It can be populated from command-line flags, config files, or a credentials file.
func Configuration ¶
func Configuration(config *Config, configurator configurator.Configurator) (*Config, error)
Configuration applies configuration values to the Config struct. It reads from configurator and optionally from a credentials file. Returns an error if file reading fails.
Click to show internal directories.
Click to hide internal directories.