{"id":13806444,"url":"https://github.com/spider-gazelle/digest-auth","last_synced_at":"2025-03-31T13:40:30.132Z","repository":{"id":92225156,"uuid":"271501382","full_name":"spider-gazelle/digest-auth","owner":"spider-gazelle","description":"HTTP digest auth for crystal lang","archived":false,"fork":false,"pushed_at":"2021-05-26T01:53:16.000Z","size":7,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-06T19:52:05.644Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/spider-gazelle.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}},"created_at":"2020-06-11T09:08:39.000Z","updated_at":"2021-05-26T01:53:18.000Z","dependencies_parsed_at":"2023-06-19T05:38:51.235Z","dependency_job_id":null,"html_url":"https://github.com/spider-gazelle/digest-auth","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fdigest-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fdigest-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fdigest-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fdigest-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spider-gazelle","download_url":"https://codeload.github.com/spider-gazelle/digest-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246475782,"owners_count":20783723,"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-08-04T01:01:11.809Z","updated_at":"2025-03-31T13:40:30.101Z","avatar_url":"https://github.com/spider-gazelle.png","language":"Crystal","funding_links":[],"categories":["HTTP"],"sub_categories":[],"readme":"# Crystal Lang Digest Auth\n\n[![CI](https://github.com/spider-gazelle/digest-auth/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/digest-auth/actions/workflows/ci.yml)\n\nCommunicate with servers that implement digest auth.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     digest-auth:\n       github: spider-gazelle/digest-auth\n   ```\n\n2. Run `shards install`\n\n\n## Usage\n\n```crystal\nrequire \"http/client\"\nrequire \"digest-auth\"\n\n# New client per-connection, this keeps track of nonce count\ndigest_auth = DigestAuth.new\n\nuri = URI.parse \"http://foo.com/posts?id=30\u0026limit=5\"\n\n# if you expect digest auth use a head request to get the challenge header\nclient = HTTP::Client.new uri\nresponse = client.head uri.full_path\nresponse.status_code # =\u003e 401\n\nchallenge = response.headers[\"WWW-Authenticate\"]\nuri.user = \"username\"\nuri.password = \"password\"\n\n# Generate the auth header, need to indicate if talking to IIS\nauth_header = digest_auth.auth_header(uri, challenge, \"get\", iis: false)\n\n# Make the request\nresponse = client.get uri.full_path, HTTP::Headers{ \"Authorization\" =\u003e auth_header }\nresponse.status_code # =\u003e 200\n\n# Make a second request while the connection is still open\nuri.path = \"/posts/30\"\nauth_header = digest_auth.auth_header(uri, challenge, \"post\", iis: false)\nresponse = client.post uri.full_path, HTTP::Headers{ \"Authorization\" =\u003e auth_header }, body: \"hello!\"\nresponse.status_code # =\u003e 201\n```\n\nor using `.before_request`\n\n```crystal\nrequire \"http/client\"\nrequire \"digest-auth\"\n\ndigest_auth = DigestAuth.new\nuri = URI.parse \"http://foo.com/\"\n\nclient = HTTP::Client.new uri\nresponse = client.head uri.full_path\nresponse.status_code # =\u003e 401\n\nchallenge = response.headers[\"WWW-Authenticate\"]\nuri.user = \"username\"\nuri.password = \"password\"\n\nclient.before_request do |request|\n  req_path = URI.parse request.resource\n  uri.path = req_path.path\n  uri.query = req_path.query\n  auth_header = digest_auth.auth_header(uri, challenge, request.method, iis: false)\n  request.headers[\"Authorization\"] = auth_header\nend\n\nclient.get \"/\"\nclient.post \"/some_path\", body: \"hello!\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspider-gazelle%2Fdigest-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspider-gazelle%2Fdigest-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspider-gazelle%2Fdigest-auth/lists"}