{"id":16828052,"url":"https://github.com/kataras/basicauth","last_synced_at":"2025-03-22T04:30:27.173Z","repository":{"id":73636751,"uuid":"315457418","full_name":"kataras/basicauth","owner":"kataras","description":"The most advanced and powerful Go HTTP Basic Authentication middleware.","archived":false,"fork":false,"pushed_at":"2025-01-07T11:45:46.000Z","size":48,"stargazers_count":13,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T07:51:46.648Z","etag":null,"topics":["basic-authentication","basicauthentication","go","golang"],"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/kataras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":"kataras"}},"created_at":"2020-11-23T22:36:21.000Z","updated_at":"2024-11-07T00:40:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"fb7665d1-1b96-4a0c-a305-25ef4828d8e1","html_url":"https://github.com/kataras/basicauth","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.5,"last_synced_commit":"5adf524fb757c97cc63e9f031eeb1f72ecca9ad9"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fbasicauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fbasicauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fbasicauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kataras%2Fbasicauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kataras","download_url":"https://codeload.github.com/kataras/basicauth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244907420,"owners_count":20529850,"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":["basic-authentication","basicauthentication","go","golang"],"created_at":"2024-10-13T11:24:23.355Z","updated_at":"2025-03-22T04:30:26.647Z","avatar_url":"https://github.com/kataras.png","language":"Go","funding_links":["https://github.com/sponsors/kataras"],"categories":[],"sub_categories":[],"readme":"# Basic Authentication\n\n[![build status](https://img.shields.io/github/actions/workflow/status/kataras/basicauth/ci.yml?style=for-the-badge)](https://github.com/kataras/basicauth/actions) [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=for-the-badge)](https://goreportcard.com/report/github.com/kataras/basicauth) [![godocs](https://img.shields.io/badge/go-%20docs-488AC7.svg?style=for-the-badge)](https://pkg.go.dev/github.com/kataras/basicauth)\n\nThe most advanced and powerful Go HTTP middleware to handle basic authentication. It is fully compatible with the [net/http](https://pkg.go.dev/net/http) package and third-party frameworks.\n\nIn the context of an HTTP transaction, basic access authentication is a method for an HTTP user agent (e.g. a web browser) to provide a user name and password when making a request [RFC 7617](https://tools.ietf.org/html/rfc7617).\n\n\u003e Looking for JWT? Navigate through [kataras/jwt](https://github.com/kataras/jwt) instead.\n\n## Installation\n\nThe only requirement is the [Go Programming Language](https://go.dev/dl/).\n\n```sh\n$ go get github.com/kataras/basicauth\n```\n\nPlease star this open source project to attract more developers so that together we can improve it even more!\n\n### Examples\n\n- [Basic](_examples/basic/main.go)\n- [Load from a slice of Users](_examples/users_list/main.go)\n- [Load from a file \u0026 encrypted passwords](_examples/users_file_bcrypt)\n- [Fetch \u0026 validate a User from a Database (MySQL)](_examples/database)\n\n## Getting Started\n\nImport the package:\n\n```go\nimport \"github.com/kataras/basicauth\"\n```\n\nInitialize the middleware with a simple map of username:password (see [Options](https://pkg.go.dev/github.com/kataras/basicauth#Options) type and [New](https://pkg.go.dev/github.com/kataras/basicauth#New) function for real-world scenarios):\n\n```go\nauth := basicauth.Default(map[string]string{\n\t\"admin\":       \"admin\",\n\t\"my_username\": \"my_password\",\n})\n```\n\nWrap any `http.Handler` with the `auth` middleware, e.g. `*http.ServeMux`:\n\n```go\nmux := http.NewServeMux()\n// [...routes]\n\nhttp.ListenAndServe(\":8080\", auth(mux))\n```\n\nOr register the middleware to a single `http.HandlerFunc` route:\n\n```go\nmux.HandleFunc(\"/\", basicauth.HandlerFunc(auth, routeHandlerFunc))\n```\n\nAccess the authenticated User entry:\n\n```go\nrouteHandlerFunc := func(w http.ResponseWriter, r *http.Request) {\n\tuser := basicauth.GetUser(r).(*basicauth.SimpleUser)\n\t// user.Username\n\t// user.Password\n}\n```\n\n\u003e The `*http.Request.BasicAuth()` works too, but it has limitations when it comes to a [custom user struct](_examples/users_list/main.go).\n\nFor a more detailed technical documentation you can head over to our [godocs](https://pkg.go.dev/github.com/kataras/basicauth).\n\n## License\n\nThis software is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fbasicauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkataras%2Fbasicauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkataras%2Fbasicauth/lists"}