Documentation
¶
Index ¶
Constants ¶
View Source
const ( // TokensFieldName is the command-line flag for inline tokens. // Format: "token1,token2,token3" TokensFieldName = "server.http.auth.token.tokens" // HeaderNameFieldName is the command-line flag for the header name. HeaderNameFieldName = "server.http.auth.token.header" // FilePathFieldName is the command-line flag for tokens file. // File should contain one token per line. FilePathFieldName = "server.http.auth.token.filepath" // HeaderNameDefault is the default header name for token authentication. HeaderNameDefault = "X-Auth-Token" )
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 Token Authentication middleware.
Usage:
compogo.WithComponents(
http.Component,
token.Component,
)
Then in your router setup:
router.Use(tokenAuth.Middleware)
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth implements HTTP Token Authentication middleware. It validates incoming requests against configured tokens.
type Config ¶
type Config struct {
// HeaderName is the HTTP header to look for the token.
HeaderName string
// FilePath is the path to a file containing allowed tokens.
FilePath string
// Set of allowed tokens for O(1) lookup
Tokens set.Set[string]
// contains filtered or unexported fields
}
Config holds the token authentication configuration. It can be populated from command-line flags, config files, or a tokens 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 tokens file. Returns an error if file reading fails.
Click to show internal directories.
Click to hide internal directories.