{"id":35082091,"url":"https://github.com/josegomezr/go-http-auth-challenge","last_synced_at":"2026-05-23T07:06:05.220Z","repository":{"id":286130645,"uuid":"960403916","full_name":"josegomezr/go-http-auth-challenge","owner":"josegomezr","description":"Pure go library for parsing HTTP authentication headers described in RFC 7235 \u0026 7230","archived":false,"fork":false,"pushed_at":"2025-05-01T11:16:04.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-01T12:25:55.766Z","etag":null,"topics":["authentication","authorization","golang","http","library"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josegomezr.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-04T11:27:28.000Z","updated_at":"2025-05-01T11:15:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"f2d63765-902b-4ba3-9689-475650f967d2","html_url":"https://github.com/josegomezr/go-http-auth-challenge","commit_stats":null,"previous_names":["josegomezr/go-http-auth-challenge"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/josegomezr/go-http-auth-challenge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josegomezr%2Fgo-http-auth-challenge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josegomezr%2Fgo-http-auth-challenge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josegomezr%2Fgo-http-auth-challenge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josegomezr%2Fgo-http-auth-challenge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josegomezr","download_url":"https://codeload.github.com/josegomezr/go-http-auth-challenge/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josegomezr%2Fgo-http-auth-challenge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33386079,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T04:15:53.637Z","status":"ssl_error","status_checked_at":"2026-05-23T04:15:53.242Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["authentication","authorization","golang","http","library"],"created_at":"2025-12-27T12:59:04.626Z","updated_at":"2026-05-23T07:06:05.214Z","avatar_url":"https://github.com/josegomezr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"HTTP Auth* Headers Parser [![Go Reference](https://pkg.go.dev/badge/github.com/josegomezr/go-http-auth-challenge.svg)](https://pkg.go.dev/github.com/josegomezr/go-http-auth-challenge)\n===\n\nA compliant-enough implementation to parse HTTP `WWW-Authenticate` \u0026\n`Authorization` headers with 0 dependencies\n\nThis implementation tries to be compliant-enough (to the extent of my skills)\nwith the grammars defined in [RFC 7230 § 3.2.6](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6) \u0026 [RFC 7235 § 2.1](https://datatracker.ietf.org/doc/html/rfc7235#section-2.1) with regards\nto processing the values of the HTTP Authorization headers.\n\nUsage\n---\n\n### When consuming challenge headers (`www-authenticate`, `proxy-authenticate`)\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\thttp_auth \"github.com/josegomezr/go-http-auth-challenge\"\n)\n\nfunc main() {\n\t// what a server would respond\n\twwwAuthenticateHeader := `Bearer realm=\"https://auth.docker.io/token\",service=\"registry.docker.io\"`\n\n\t// Get the list of defined challenges\n\tchallenges, err := http_auth.ParseChallenges(wwwAuthenticateHeader, true)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Error parsing challenges: %s\", err))\n\t}\n\n\t// To accomodate for multiple challenges on a single header, the return type\n\t// is a slice of challenges, most of the world only uses one at a time, it up\n\t// for consumers to take this decision and use the first challenge if they\n\t// see it fit.\n\tfor _, challenge := range challenges {\n\t\tswitch challenge.Scheme {\n\t\tcase \"Basic\":\n\t\t\tfmt.Println(\"Scheme: Basic\")\n\t\t\t/* do some stuff with auth basic */\n\t\t\t// ...\n\t\t\trealm, found := challenge.Realm()\n\t\t\tif found {\n\t\t\t\tfmt.Println(\"- realm:\", realm)\n\t\t\t}\n\t\tcase \"Bearer\":\n\t\t\tfmt.Println(\"Scheme: Bearer\")\n\t\t\t/* do some stuff with auth basic */\n\t\t\t// ...\n\n\t\t\trealm, found := challenge.Realm()\n\t\t\tif found {\n\t\t\t\tfmt.Println(\"- realm:\", realm)\n\t\t\t}\n\t\t\tservice, found := challenge.GetParam(\"service\")\n\t\t\tif found {\n\t\t\t\tfmt.Println(\"- service:\", service)\n\t\t\t}\n\t\t\tfmt.Printf(\"- all-params: %v\\n\", challenge.Params)\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"Unknown challenge scheme: %s\", challenge.Scheme))\n\t\t}\n\t}\n}\n```\n\n### When consuming authorization headers (`authentication`, `proxy-authorization`)\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\thttp_auth \"github.com/josegomezr/go-http-auth-challenge\"\n)\n\nfunc main() {\n\t// what a server would respond\n\tauthorizationHeader := `Bearer dG9rZW4=,keyId=abc,username=foo`\n\n\t// Get the list of defined challenges\n\tchallenge, err := http_auth.ParseAuthorization(authorizationHeader, true)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Error parsing authorization header: %s\", err))\n\t}\n\n\tfmt.Println(\"Scheme: \", challenge.Scheme)\n\t// The convention here is that tokens (not auth-params) are saved in order\n\t// as string indexes. If it's too cumbersome, i'll refactor it.\n\tvalue0, found := challenge.GetParam(\"0\")\n\tif found {\n\t\tfmt.Println(\"- value0:\", value0)\n\t}\n\tfmt.Printf(\"- all-params: %v\\n\", challenge.Params)\n}\n```\n\nTake a look at the `example_*.go` files for more usage tips.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosegomezr%2Fgo-http-auth-challenge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosegomezr%2Fgo-http-auth-challenge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosegomezr%2Fgo-http-auth-challenge/lists"}