{"modulePath":"github.com/Compogo/http","version":"v0.0.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package basic\n\n## Constants\n\n```go\nconst (\n\t// CredsFieldName is the command-line flag for inline credentials.\n\t// Format: \"username1:password1,username2:password2\"\n\tCredsFieldName = \"server.http.auth.basic.creds\"\n\n\t// FilePathFieldName is the command-line flag for credentials file.\n\t// File should contain one \"username:password\" per line.\n\tFilePathFieldName = \"server.http.auth.basic.filepath\"\n)\n```\n\n## Variables\n\n```go\nvar Component = \u0026component.Component{\n\tInit: component.StepFunc(func(container container.Container) error {\n\t\treturn container.Provides(\n\t\t\tNewConfig,\n\t\t\tNewAuth,\n\t\t)\n\t}),\n\tConfiguration: component.StepFunc(func(container container.Container) error {\n\t\treturn container.Invoke(Configuration)\n\t}),\n}\n```\nComponent is a ready-to-use Compogo component that provides HTTP Basic Authentication middleware.\n\nUsage:\n\n\tcompogo.WithComponents(\n\t    http.Component,\n\t    basic.Component,\n\t)\n\nThen in your router setup:\n\n\trouter.Use(basicAuth.Middleware)\n\n## Types\n\n```go\ntype Auth struct {\n\t// contains filtered or unexported fields\n}\n```\nAuth implements HTTP Basic Authentication middleware. It validates incoming requests against configured credentials.\n\n```go\nfunc NewAuth(config *Config) *Auth\n```\nNewAuth creates a new Auth middleware instance with the given configuration.\n\n```go\nfunc (auth *Auth) Middleware(next http.Handler) http.Handler\n```\nMiddleware implements the http.Middleware interface. It checks for valid Basic Authentication credentials:\n\n  - If no credentials or invalid credentials, returns 401 Unauthorized\n  - If valid, passes the request to the next handler\n\n```go\ntype Config struct {\n\tFilePath string\n\n\tCreds mapper.Mapper[*Cred]\n\t// contains filtered or unexported fields\n}\n```\nConfig holds the basic authentication configuration. It can be populated from command-line flags, config files, or a credentials file.\n\n```go\nfunc Configuration(config *Config, configurator configurator.Configurator) (*Config, error)\n```\nConfiguration applies configuration values to the Config struct. It reads from configurator and optionally from a credentials file. Returns an error if file reading fails.\n\n```go\nfunc NewConfig() *Config\n```\nNewConfig creates a new Config instance with default values.\n\n```go\ntype Cred struct {\n\tUserName string\n\tPassword string\n}\n```\nCred represents a single username/password pair for basic authentication.\n\n```go\nfunc (c *Cred) String() string\n```\nString returns the username, implementing fmt.Stringer.\n\n","path":"github.com/Compogo/http/middleware/auth/basic","name":"basic","synopsis":"","isRedistributable":true}
