package digest

Import Path
	github.com/icholy/digest (on go.dev)

Dependency Relation
	imports 16 packages, and imported by one package


Code Examples package main import ( "net/http" "github.com/icholy/digest" ) func main() { // The first request will return a 401 Unauthorized response req, _ := http.NewRequest(http.MethodGet, "https://httpbun.com/digest-auth/auth/foo/bar", nil) res, _ := http.DefaultClient.Do(req) // Create digest credentials from the request challenge chal, _ := digest.FindChallenge(res.Header) cred, _ := digest.Digest(chal, digest.Options{ Method: req.Method, URI: req.URL.RequestURI(), Username: "foo", Password: "bar", }) // Try the request again with the credentials req.Header.Set("Authorization", cred.String()) res, _ = http.DefaultClient.Do(req) println(res.Status) } package main import ( "net/http" "github.com/icholy/digest" ) func main() { client := http.Client{ Transport: &digest.Transport{ Username: "foo", Password: "bar", }, } res, _ := client.Get("https://httpbun.com/digest-auth/auth/foo/bar") println(res.Status) }
Package-Level Type Names (total 4)
/* sort by: | */
Challenge is a challenge sent in the WWW-Authenticate header Algorithm string Charset string Domain []string Nonce string Opaque string QOP []string Realm string Stale bool Userhash bool String returns the foramtted header value SupportsQOP returns true if the challenge advertises support for the provided qop value *Challenge : github.com/pancsta/asyncmachine-go/internal/nofmt.Stringer *Challenge : github.com/pandatix/go-abnf.ElemItf *Challenge : expvar.Var *Challenge : fmt.Stringer func FindChallenge(h http.Header) (*Challenge, error) func ParseChallenge(s string) (*Challenge, error) func CanDigest(c *Challenge) bool func Digest(chal *Challenge, o Options) (*Credentials, error)
Credentials is a parsed version of the Authorization header Algorithm string Cnonce string Nc int Nonce string Opaque string QOP string Realm string Response string URI string Userhash bool Username string String formats the credentials into the header format *Credentials : github.com/pancsta/asyncmachine-go/internal/nofmt.Stringer *Credentials : github.com/pandatix/go-abnf.ElemItf *Credentials : expvar.Var *Credentials : fmt.Stringer func Digest(chal *Challenge, o Options) (*Credentials, error) func ParseCredentials(s string) (*Credentials, error)
Options for creating a credentials The following are provided for advanced use cases where the client needs to override the default digest calculation behavior. Most users should leave these fields unset. Cnonce string Count int GetBody func() (io.ReadCloser, error) Method string Password string URI string Username string func Digest(chal *Challenge, o Options) (*Credentials, error)
Transport implements http.RoundTripper Digest computes the digest credentials. If nil, the Digest function is used. FindChallenge extracts the challenge from the request headers. If nil, the FindChallenge function is used. Jar specifies the cookie jar. The Jar is used to insert relevant cookies into every outbound Request and is updated with the cookie values of every inbound Response. The Jar is consulted for every redirect that the Client follows. If Jar is nil, cookies are only sent if they are explicitly set on the Request. NoReuse prevents the transport from reusing challenges. Password string Probe discovers the challenge with a bodyless request before streaming the body, so it's only sent once authenticated — for servers that reject the unauthenticated request without draining the body. Applies only when uncached. Transport specifies the mechanism by which individual HTTP requests are made. If nil, DefaultTransport is used. Username string CloseIdleConnections delegates the call to the underlying transport. RoundTrip will try to authorize the request using a cached challenge. If that doesn't work and we receive a 401, we'll try again using that challenge. *Transport : net/http.RoundTripper
Package-Level Functions (total 7)
CanDigest checks if the algorithm and qop are supported
CutPrefix removes the digest prefix from the header value
Digest creates credentials from a challenge and request options. Note: if you want to re-use a challenge, you must increment the Count.
FindChallenge returns the first supported challenge in the headers
IsDigest returns true if the header value is a digest auth header
ParseChallenge parses the WWW-Authenticate header challenge
ParseCredentials parses the Authorization header value into credentials
Package-Level Variables (only one)
ErrNoChallenge indicates that no WWW-Authenticate headers were found.
Package-Level Constants (only one)
Prefix for digest authentication headers