Documentation ¶
Overview ¶
Package provides header generator for digest authentication.
The Auth object can be reused for subsequent requests.
Example:
req, _ := http.NewRequest("GET", "/", nil) resp, _ := http.DefaultClient.Do(req) if resp.StatusCode == http.StatusUnauthorized { auth := NewAuth("john.doe", "secret") err := auth.Parse(resp.Header.Get("www-authenticate")) if err != nil { // cannot authenticate using this package } auth.Authorize(req) } resp, _ := http.DefaultClient.Do(req) // and for the next request just authorize it before sending auth.Authorize(req2)
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
func (*Auth) Authorize ¶
Authorize sets the Authorization header on the given request. Also each call updates nc by one.
Example ¶
auth := NewAuth("john.doe", "secret") req, _ := http.NewRequest("GET", "/", nil) auth.Authorize(req)
Output:
func (*Auth) Header ¶
Example ¶
Example is the same as described on wikipedia at https://en.wikipedia.org/wiki/Digest_access_authentication
wwwAuth := fmt.Sprintf( "Digest %s=%q, %s=%q, %s=%q, %s=%s, %s=%q", "realm", "[email protected]", "nonce", "dcd98b7102dd2f0e8b11d0f600bfb0c093", "algorithm", "MD5", "qop", "auth", "opaque", "5ccc069c403ebaf9f0171e9517f40e41") auth := NewAuth("Mufasa", "Circle Of Life") err := auth.Parse(wwwAuth) if err != nil { // cannot use digest } auth.cnonce = "0a4f113b" hdr := auth.Header("GET", "/dir/index.html") fmt.Println(strings.Replace(hdr, ", ", ",\n", -1))
Output: Digest username="Mufasa", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop=auth, nc=00000001, cnonce="0a4f113b", response="6629fae49393a05397450978507c4ef1", opaque="5ccc069c403ebaf9f0171e9517f40e41"
Click to show internal directories.
Click to hide internal directories.