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 Authentication ¶
func Authentication(config *AuthenticationConfig) gin.HandlerFunc
Authentication 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 AuthenticationConfig ¶
type AuthenticationConfig 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"` }
AuthenticationConfig holds configuration related to user and API key authentication.
func NewAuthenticationConfig ¶
func NewAuthenticationConfig() *AuthenticationConfig
NewAuthenticationConfig creates and returns a new AuthenticationConfig having default values.
func (*AuthenticationConfig) Validate ¶
func (r *AuthenticationConfig) Validate() error
Validate ensures the all necessary configurations are filled and within valid confines. Any misconfiguration results in well-defined standardized errors.
Click to show internal directories.
Click to hide internal directories.