Documentation
¶
Overview ¶
http basic / digect authentication to the Simplegoproxy server. Largely adopted from https://github.com/abbot/go-http-auth . See also: https://en.wikipedia.org/wiki/Digest_access_authentication .
Index ¶
Constants ¶
const ( DefaultClientCacheSize = 1000 DefaultClientCacheTolerance = 100 )
Default values for ClientCacheSize and ClientCacheTolerance for DigestAuth
Variables ¶
var NormalHeaders = &Headers{ Authenticate: "WWW-Authenticate", Authorization: "Authorization", AuthInfo: "Authentication-Info", UnauthCode: http.StatusUnauthorized, UnauthContentType: "text/plain", UnauthResponse: fmt.Sprintf("%d %s\n", http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized)), }
NormalHeaders are the regular Headers used by an HTTP Server for request authentication.
var ProxyHeaders = &Headers{ Authenticate: "Proxy-Authenticate", Authorization: "Proxy-Authorization", AuthInfo: "Proxy-Authentication-Info", UnauthCode: http.StatusProxyAuthRequired, UnauthContentType: "text/plain", UnauthResponse: fmt.Sprintf("%d %s\n", http.StatusProxyAuthRequired, http.StatusText(http.StatusProxyAuthRequired)), }
ProxyHeaders are Headers used by an HTTP Proxy server for proxy access authentication.
Functions ¶
func DigestAuthParams ¶
DigestAuthParams parses Authorization header from the http.Request. Returns a map of auth parameters or nil if the header is not a valid parsable Digest auth header.
func ParseList ¶
ParseList parses a comma-separated list of values as described by RFC 2068 and returns list elements.
Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go which was ported from urllib2.parse_http_list, from the Python standard library.
func ParsePairs ¶
ParsePairs extracts key/value pairs from a comma-separated list of values as described by RFC 2068 and returns a map[key]value. The resulting values are unquoted. If a list element doesn't contain a "=", the key is the element itself and the value is an empty string.
Lifted from https://code.google.com/p/gorilla/source/browse/http/parser/parser.go
Types ¶
type Auth ¶
type Auth struct {
Realm string
Opaque string
PlainTextSecrets bool
IgnoreNonceCount bool
// Headers used by authenticator. Set to ProxyHeaders to use with
// proxy server. When nil, NormalHeaders are used.
Headers *Headers
/*
Approximate size of Client's Cache. When actual number of
tracked client nonces exceeds
ClientCacheSize+ClientCacheTolerance, ClientCacheTolerance*2
older entries are purged.
*/
ClientCacheSize int
ClientCacheTolerance int
// contains filtered or unexported fields
}
Auth is an authenticator implementation for 'Digest' HTTP Authentication scheme (RFC 7616).
Note: this implementation was written following now deprecated RFC 2617, and supports only MD5 algorithm.
TODO: Add support for SHA-256 and SHA-512/256 algorithms.
func NewAuthenticator ¶
NewAuthenticator generates a new DigestAuth object
func (*Auth) CheckAuth ¶
func (a *Auth) CheckAuth(r *http.Request, username, password string, basic bool) (errres *http.Response, err error)
CheckAuth checks whether the request contains valid authentication data. If not, return a "RequireAuth" http response with an error.
func (*Auth) Wrap ¶
func (a *Auth) Wrap(wrapped http.HandlerFunc, user, pass string, basic bool) http.HandlerFunc
type Headers ¶
type Headers struct {
Authenticate string // WWW-Authenticate
Authorization string // Authorization
AuthInfo string // Authentication-Info
UnauthCode int // 401
UnauthContentType string // text/plain
UnauthResponse string // Unauthorized.
}
Headers contains header and error codes used by authenticator.