Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 859 Bytes

README.md

File metadata and controls

27 lines (20 loc) · 859 Bytes

digest - package provides header generator for digest authentication.

Quick start

go get -u github.com/gregoryv/digest

Example

The Auth object can be reused for subsequent requests thought it is not thread safe.

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)