Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidPassword = errors.New("password is not valid")
)
View Source
var (
ErrNoPassword = errors.New("password of a user cannot be empty")
)
Functions ¶
func New ¶
func New(config *Config) gin.HandlerFunc
New is a middleware function that handles HTTP Basic Auth, Bearer tokens and API Key header. If Basic Auth failed or not provided, it tries to get API key from the headers "API-Key" and "X-API-Key". The username in Basic Auth is ignored, but must contain at least one character.
Types ¶
type Config ¶
type Config struct { // APIKeys list representing API keys that can be used to authenticate requests. APIKeys []string `json:"api_keys" yaml:"api_keys" mapstructure:"api_keys"` // HeaderName is the name of the header that contains the authentication token. // This could be "Authorization" or "API-Key", for example, which is commonly used in HTTP authentication. HeaderName string `json:"header_name" yaml:"header_name" mapstructure:"header_name"` // HeaderValuePrefix is a prefix that will be added to the API key in the header. // This can be used to provide additional context or information about how the API key was obtained, // such as "Bearer ", which is commonly used in HTTP authentication. HeaderValuePrefix string `json:"header_value_prefix" yaml:"header_value_prefix" mapstructure:"header_value_prefix"` // Users is a map where keys are usernames and values are passwords. It's used for basic HTTP authentication. Users map[string]string `json:"users" yaml:"users" mapstructure:"users"` }
Config holds configuration related to user and API key authentication.
Click to show internal directories.
Click to hide internal directories.