{"id":15557456,"url":"https://github.com/icholy/digest","last_synced_at":"2025-04-07T13:09:07.006Z","repository":{"id":46660571,"uuid":"269194994","full_name":"icholy/digest","owner":"icholy","description":"Go HTTP Digest Access Authentication","archived":false,"fork":false,"pushed_at":"2024-06-13T16:16:39.000Z","size":66,"stargazers_count":59,"open_issues_count":0,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-16T00:30:48.150Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icholy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-03T21:08:11.000Z","updated_at":"2024-10-13T15:35:44.000Z","dependencies_parsed_at":"2023-01-30T13:30:22.707Z","dependency_job_id":"b199678d-9005-45be-9b40-e45b53a0406c","html_url":"https://github.com/icholy/digest","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fdigest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fdigest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fdigest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Fdigest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icholy","download_url":"https://codeload.github.com/icholy/digest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247657281,"owners_count":20974345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T15:17:59.194Z","updated_at":"2025-04-07T13:09:06.988Z","avatar_url":"https://github.com/icholy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTP Digest Access Authentication\n\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/icholy/digest)\n\n\u003e This package provides a http.RoundTripper implementation which re-uses digest challenges\n\n``` go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/icholy/digest\"\n)\n\nfunc main() {\n\tclient := \u0026http.Client{\n\t\tTransport: \u0026digest.Transport{\n\t\t\tUsername: \"foo\",\n\t\t\tPassword: \"bar\",\n\t\t},\n\t}\n\tres, err := client.Get(\"http://localhost:8080/some_outdated_service\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer res.Body.Close()\n}\n```\n\n## Using Cookies\n\nIf you're using an `http.CookieJar` the `digest.Transport` needs a reference to it.\n\n``` go\npackage main\n\nimport (\n\t\"net/http\"\n\t\"net/http/cookiejar\"\n\n\t\"github.com/icholy/digest\"\n)\n\nfunc main() {\n\tjar, _ := cookiejar.New(nil)\n\tclient := \u0026http.Client{\n\t\tTransport: \u0026digest.Transport{\n\t\t\tJar:      jar,\n\t\t\tUsername: \"foo\",\n\t\t\tPassword: \"bar\",\n\t\t},\n\t}\n\tres, err := client.Get(\"http://localhost:8080/digest_with_cookies\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer res.Body.Close()\n}\n```\n\n## Custom Authenticate Header\n\n``` go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/icholy/digest\"\n)\n\nfunc main() {\n\tclient := \u0026http.Client{\n\t\tTransport: \u0026digest.Transport{\n\t\t\tUsername: \"foo\",\n\t\t\tPassword: \"bar\",\n\t\t\tFindChallenge: func(h http.Header) (*digest.Challenge, error) {\n\t\t\t\tvalue := h.Get(\"Custom-Authenticate-Header\")\n\t\t\t\tif value == \"\" {\n\t\t\t\t\treturn nil, digest.ErrNoChallenge\n\t\t\t\t}\n\t\t\t\treturn digest.ParseChallenge(value)\n\t\t\t},\n\t\t},\n\t}\n\tres, err := client.Get(\"http://localhost:8080/non_compliant\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer res.Body.Close()\n}\n```\n\n## Override Digest Options\n\n``` go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\t\"github.com/icholy/digest\"\n)\n\nfunc main() {\n\tclient := \u0026http.Client{\n\t\tTransport: \u0026digest.Transport{\n\t\t\tDigest: func(req *http.Request, chal *digest.Challenge, opt digest.Options) (*digest.Credentials, error) {\n\t\t\t\tswitch req.URL.Hostname() {\n\t\t\t\tcase \"badauth.org\":\n\t\t\t\t\topt.Username = \"foo\"\n\t\t\t\t\topt.Password = \"bar\"\n\t\t\t\tcase \"poorsecurity.com\":\n\t\t\t\t\topt.Username = \"zoo\"\n\t\t\t\t\topt.Password = \"boo\"\n\t\t\t\tdefault:\n\t\t\t\t\treturn nil, fmt.Errorf(\"unsuported host: %q\", req.URL)\n\t\t\t\t}\n\t\t\t\treturn digest.Digest(chal, opt)\n\t\t\t},\n\t\t},\n\t}\n\tres, err := client.Get(\"http://poorsecurity.com/legacy.php\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer res.Body.Close()\n}\n```\n\n\n## Low Level API\n\n``` go\nfunc main() {\n  // get the challenge from a 401 response\n  header := res.Header.Get(\"WWW-Authenticate\")\n  chal, _ := digest.ParseChallenge(header)\n\n  // use it to create credentials for the next request\n  cred, _ := digest.Digest(chal, digest.Options{\n    Username: \"foo\",\n    Password: \"bar\",\n    Method:   req.Method,\n    URI:      req.URL.RequestURI(),\n    GetBody:  req.GetBody,\n    Count:    1,\n  })\n  req.Header.Set(\"Authorization\", cred.String())\n\n  // if you use the same challenge again, you must increment the Count\n  cred2, _ := digest.Digest(chal, digest.Options{\n    Username: \"foo\",\n    Password: \"bar\",\n    Method:   req2.Method,\n    URI:      req2.URL.RequestURI(),\n    GetBody:  req2.GetBody,\n    Count:    2,\n  })\n  req2.Header.Set(\"Authorization\", cred.String())\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficholy%2Fdigest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficholy%2Fdigest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficholy%2Fdigest/lists"}