Documentation
¶
Index ¶
- Variables
- func AccountInfoCheckGroup(group string) bool
- type Account
- type AccountManager
- type Accounts
- type Cache
- type HTTPBasicAuthExt
- func (hba HTTPBasicAuthExt) Authenticate(w http.ResponseWriter, req *http.Request) (caddyauth.User, bool, error)
- func (HTTPBasicAuthExt) CaddyModule() caddy.ModuleInfo
- func (hba *HTTPBasicAuthExt) Cleanup() error
- func (hba *HTTPBasicAuthExt) Provision(ctx caddy.Context) error
- func (hba *HTTPBasicAuthExt) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
Constants ¶
This section is empty.
Variables ¶
var GetAccountMangerInstance = sync.OnceValue(NewAccountManager)
Functions ¶
func AccountInfoCheckGroup ¶
Types ¶
type Account ¶
type Account struct {
// A user's username.
Username string
Password []byte
// A user's groups. used as set of strings;
// group names are case-sensitive, should only contain alphanumeric characters and underscores
// Stored in
Groups map[string]struct{}
}
func (*Account) RemoveGroup ¶
Remove a group from a user
type AccountManager ¶
type AccountManager struct {
// contains filtered or unexported fields
}
func NewAccountManager ¶
func NewAccountManager() *AccountManager
type Accounts ¶
type Accounts struct {
// The file path
File string
// The hash algorithm used to hash the passwords
Hash caddyauth.Comparer
// The accounts in the file
Accounts map[string]*Account
}
Accounts is a list of accounts from one file
func ParseAccountsFromFile ¶
func (*Accounts) GetAccount ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache enables caching of basic auth results. This is especially helpful for secure password hashes which can be expensive to compute on every HTTP request.
type HTTPBasicAuthExt ¶
type HTTPBasicAuthExt struct {
// The algorithm with which the passwords are hashed. Default: bcrypt
HashRaw json.RawMessage `json:"hash,omitempty" caddy:"namespace=http.authentication.hashes inline_key=algorithm"`
// account file
File string `json:"file,omitempty"`
// permission (group) for this module
Permission string `json:"permission,omitempty"`
// The name of the realm. Default: restricted
Realm string `json:"realm,omitempty"`
// If non-nil, a mapping of plaintext passwords to their
// hashes will be cached in memory (with random eviction).
// This can greatly improve the performance of traffic-heavy
// servers that use secure password hashing algorithms, with
// the downside that plaintext passwords will be stored in
// memory for a longer time (this should not be a problem
// as long as your machine is not compromised, at which point
// all bets are off, since basicauth necessitates plaintext
// passwords being received over the wire anyway). Note that
// a cache hit does not mean it is a valid password.
HashCache *Cache `json:"hash_cache,omitempty"`
// contains filtered or unexported fields
}
HTTPBasicAuthExt facilitates HTTP basic authentication.
func (HTTPBasicAuthExt) Authenticate ¶
func (hba HTTPBasicAuthExt) Authenticate(w http.ResponseWriter, req *http.Request) (caddyauth.User, bool, error)
Authenticate validates the user credentials in req and returns the user, if valid.
func (HTTPBasicAuthExt) CaddyModule ¶
func (HTTPBasicAuthExt) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*HTTPBasicAuthExt) Cleanup ¶
func (hba *HTTPBasicAuthExt) Cleanup() error
Cleanup implements caddy.CleanerUpper.
func (*HTTPBasicAuthExt) Provision ¶
func (hba *HTTPBasicAuthExt) Provision(ctx caddy.Context) error
Provision provisions the HTTP basic auth provider.
func (*HTTPBasicAuthExt) UnmarshalCaddyfile ¶
func (hba *HTTPBasicAuthExt) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
parseCaddyfile sets up the handler from Caddyfile tokens. Syntax:
basic_auth_ext [<matcher>] [<hash_algorithm> [<realm>]] {
file <filename>
[permission <permission-group>]
}
If no hash algorithm is supplied, bcrypt will be assumed. UnmarshalCaddyfile implements caddyfile.Unmarshaler.