Documentation
¶
Overview ¶
Package basic provides HTTP Basic authentication middleware and utilities.
Copyright 2019 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Imported from https://golang.org/src/cmd/go/internal/auth/netrc.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCredentials ¶
AddCredentials fills in the user's credentials for req, if any. The return value reports whether any matching credentials were found. This function uses the default package-level NetrcProvider for backward compatibility.
func AddCredentialsWithProvider ¶ added in v0.53.0
func AddCredentialsWithProvider(req *http.Request, provider *NetrcProvider) (added bool)
AddCredentialsWithProvider fills in the user's credentials for req using the specified provider. The return value reports whether any matching credentials were found.
Types ¶
type AuthMap ¶ added in v0.37.0
type AuthMap map[string]BasicAuthPair
AuthMap is a user and password pair
func LoadBasicAuthFromFile ¶
func LoadBasicAuthFromReader ¶
func (AuthMap) AddUserWithHashedPassword ¶ added in v0.37.0
AddUserWithHashedPassword if user already exists it will over ride it
func (AuthMap) AddUserWithPlainPassword ¶ added in v0.37.0
AddUserWithPlainPassword if user already exists it will over ride it
func (AuthMap) Authenticate ¶ added in v0.37.0
Authenticate returns true if the user exists and the password is correct
func (AuthMap) UserExists ¶ added in v0.37.0
UserExists returns true if the user exists
type BasicAuthPair ¶
func NewBasicAuthPairWithPlainPassword ¶
func NewBasicAuthPairWithPlainPassword(user, password string) (BasicAuthPair, error)
func (BasicAuthPair) VerifyPassword ¶
func (p BasicAuthPair) VerifyPassword(password string) (bool, error)
type ClientAuth ¶ added in v0.40.0
type ClientAuth struct {
Config ClientConfig
// contains filtered or unexported fields
}
func (*ClientAuth) HTTPClient ¶ added in v0.40.0
func (a *ClientAuth) HTTPClient() *http.Client
type ClientConfig ¶ added in v0.37.0
type ClientConfig struct {
// https://everything.curl.dev/usingcurl/netrc
//
// machine connect.lab.dioad.net
// login blah
// password blah
NetRCFile string `mapstructure:"netrc-file"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
}
type Handler ¶ added in v0.37.0
type Handler struct {
// contains filtered or unexported fields
}
Handler implements basic authentication for HTTP servers.
func NewHandler ¶ added in v0.37.0
func NewHandler(cfg ServerConfig) (*Handler, error)
NewHandler creates a new Basic authentication handler from the provided configuration.
func NewHandlerWithMap ¶ added in v0.37.0
NewHandlerWithMap creates a new Basic authentication handler using the provided AuthMap.
func (*Handler) AuthRequest ¶ added in v0.37.0
AuthRequest authenticates an HTTP request using Basic authentication.
type NetrcProvider ¶ added in v0.53.0
type NetrcProvider struct {
// contains filtered or unexported fields
}
NetrcProvider manages netrc credentials and their loading. It encapsulates the state for loading and parsing netrc files, allowing for multiple independent instances with different configurations. This resolves the global state issue that made testing difficult.
func NewNetrcProviderFromContent ¶ added in v0.53.0
func NewNetrcProviderFromContent(content string) *NetrcProvider
NewNetrcProviderFromContent creates a NetrcProvider initialized with the given netrc content. This is useful for testing or when netrc data comes from a non-standard source.
type RoundTripper ¶ added in v0.40.0
type RoundTripper struct {
Username string
Password string
Base http.RoundTripper
}