{"id":13493301,"url":"https://github.com/go-oauth2/oauth2","last_synced_at":"2025-05-14T12:00:25.242Z","repository":{"id":37756278,"uuid":"59758059","full_name":"go-oauth2/oauth2","owner":"go-oauth2","description":"OAuth 2.0 server library for the Go programming language.","archived":false,"fork":false,"pushed_at":"2025-04-01T08:12:59.000Z","size":1030,"stargazers_count":3444,"open_issues_count":107,"forks_count":578,"subscribers_count":62,"default_branch":"master","last_synced_at":"2025-05-05T15:08:56.646Z","etag":null,"topics":["go-oauth2","go-oauth2-server","oauth2","oauth2-authentication","oauth2-provider","oauth2-server"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/go-oauth2/oauth2/v4","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/go-oauth2.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":"2016-05-26T14:42:51.000Z","updated_at":"2025-05-05T02:56:27.000Z","dependencies_parsed_at":"2024-05-06T02:29:58.428Z","dependency_job_id":"b9ae4ca2-f26b-4460-a346-de6dbdb1c6b4","html_url":"https://github.com/go-oauth2/oauth2","commit_stats":{"total_commits":182,"total_committers":50,"mean_commits":3.64,"dds":"0.44505494505494503","last_synced_commit":"d1b58c7e627024ddaab9cd4a8a5e4676f623bf28"},"previous_names":[],"tags_count":67,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-oauth2%2Foauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-oauth2%2Foauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-oauth2%2Foauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-oauth2%2Foauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-oauth2","download_url":"https://codeload.github.com/go-oauth2/oauth2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252720130,"owners_count":21793736,"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":["go-oauth2","go-oauth2-server","oauth2","oauth2-authentication","oauth2-provider","oauth2-server"],"created_at":"2024-07-31T19:01:14.012Z","updated_at":"2025-05-06T21:31:02.128Z","avatar_url":"https://github.com/go-oauth2.png","language":"Go","funding_links":[],"categories":["Go","Authentication \u0026 OAuth"],"sub_categories":[],"readme":"# Golang OAuth 2.0 Server\n\n\u003e An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications.\n\n[![Build][build-status-image]][build-status-url] [![Codecov][codecov-image]][codecov-url] [![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url]\n\n## Protocol Flow\n\n```text\n     +--------+                               +---------------+\n     |        |--(A)- Authorization Request -\u003e|   Resource    |\n     |        |                               |     Owner     |\n     |        |\u003c-(B)-- Authorization Grant ---|               |\n     |        |                               +---------------+\n     |        |\n     |        |                               +---------------+\n     |        |--(C)-- Authorization Grant --\u003e| Authorization |\n     | Client |                               |     Server    |\n     |        |\u003c-(D)----- Access Token -------|               |\n     |        |                               +---------------+\n     |        |\n     |        |                               +---------------+\n     |        |--(E)----- Access Token ------\u003e|    Resource   |\n     |        |                               |     Server    |\n     |        |\u003c-(F)--- Protected Resource ---|               |\n     +--------+                               +---------------+\n```\n\n## Quick Start\n\n### Download and install\n\n```bash\ngo get -u -v github.com/go-oauth2/oauth2/v4/...\n```\n\n### Create file `server.go`\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/go-oauth2/oauth2/v4/errors\"\n\t\"github.com/go-oauth2/oauth2/v4/manage\"\n\t\"github.com/go-oauth2/oauth2/v4/models\"\n\t\"github.com/go-oauth2/oauth2/v4/server\"\n\t\"github.com/go-oauth2/oauth2/v4/store\"\n)\n\nfunc main() {\n\tmanager := manage.NewDefaultManager()\n\t// token memory store\n\tmanager.MustTokenStorage(store.NewMemoryTokenStore())\n\n\t// client memory store\n\tclientStore := store.NewClientStore()\n\tclientStore.Set(\"000000\", \u0026models.Client{\n\t\tID:     \"000000\",\n\t\tSecret: \"999999\",\n\t\tDomain: \"http://localhost\",\n\t})\n\tmanager.MapClientStorage(clientStore)\n\n\tsrv := server.NewDefaultServer(manager)\n\tsrv.SetAllowGetAccessRequest(true)\n\tsrv.SetClientInfoHandler(server.ClientFormHandler)\n\n\tsrv.UserAuthorizationHandler = func(w http.ResponseWriter, r *http.Request) (userID string, err error) {\n\t\treturn \"000000\", nil\n\t}\n\n\tsrv.SetInternalErrorHandler(func(err error) (re *errors.Response) {\n\t\tlog.Println(\"Internal Error:\", err.Error())\n\t\treturn\n\t})\n\n\tsrv.SetResponseErrorHandler(func(re *errors.Response) {\n\t\tlog.Println(\"Response Error:\", re.Error.Error())\n\t})\n\n\thttp.HandleFunc(\"/authorize\", func(w http.ResponseWriter, r *http.Request) {\n\t\terr := srv.HandleAuthorizeRequest(w, r)\n\t\tif err != nil {\n\t\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\t}\n\t})\n\n\thttp.HandleFunc(\"/token\", func(w http.ResponseWriter, r *http.Request) {\n\t\tsrv.HandleTokenRequest(w, r)\n\t})\n\n\tlog.Fatal(http.ListenAndServe(\":9096\", nil))\n}\n\n```\n\n### Build and run\n\n```bash\ngo build server.go\n\n./server\n```\n\n### Open in your web browser\n**Authorization Request**:\n[http://localhost:9096/authorize?client_id=000000\u0026response_type=code](http://localhost:9096/authorize?client_id=000000\u0026response_type=code)\n\n**Grant Token Request**:\n[http://localhost:9096/token?grant_type=client_credentials\u0026client_id=000000\u0026client_secret=999999\u0026scope=read](http://localhost:9096/token?grant_type=client_credentials\u0026client_id=000000\u0026client_secret=999999\u0026scope=read)\n\n```json\n{\n  \"access_token\": \"J86XVRYSNFCFI233KXDL0Q\",\n  \"expires_in\": 7200,\n  \"scope\": \"read\",\n  \"token_type\": \"Bearer\"\n}\n```\n\n## Features\n\n- Easy to use\n- Based on the [RFC 6749](https://tools.ietf.org/html/rfc6749) implementation\n- Token storage support TTL\n- Support custom expiration time of the access token\n- Support custom extension field\n- Support custom scope\n- Support jwt to generate access tokens\n\n## Example\n\n\u003e A complete example of simulation authorization code model\n\nSimulation examples of authorization code model, please check [example](/example)\n\n### Use jwt to generate access tokens\n\n```go\n\nimport (\n\t\"github.com/go-oauth2/oauth2/v4/generates\"\n\t\"github.com/dgrijalva/jwt-go\"\n)\n\n// ...\nmanager.MapAccessGenerate(generates.NewJWTAccessGenerate(\"\", []byte(\"00000000\"), jwt.SigningMethodHS512))\n\n// Parse and verify jwt access token\ntoken, err := jwt.ParseWithClaims(access, \u0026generates.JWTAccessClaims{}, func(t *jwt.Token) (interface{}, error) {\n\tif _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {\n\t\treturn nil, fmt.Errorf(\"parse error\")\n\t}\n\treturn []byte(\"00000000\"), nil\n})\nif err != nil {\n\t// panic(err)\n}\n\nclaims, ok := token.Claims.(*generates.JWTAccessClaims)\nif !ok || !token.Valid {\n\t// panic(\"invalid token\")\n}\n```\n\n## Store Implements\n\n- [BuntDB](https://github.com/tidwall/buntdb)(default store)\n- [Redis](https://github.com/go-oauth2/redis)\n- [MongoDB](https://github.com/go-oauth2/mongo)\n- [MySQL](https://github.com/go-oauth2/mysql)\n- [MySQL (Provides both client and token store)](https://github.com/imrenagi/go-oauth2-mysql)\n- [PostgreSQL](https://github.com/vgarvardt/go-oauth2-pg)\n- [DynamoDB](https://github.com/contamobi/go-oauth2-dynamodb)\n- [XORM](https://github.com/techknowlogick/go-oauth2-xorm)\n- [XORM (MySQL, client and token store)](https://github.com/rainlay/go-oauth2-xorm)\n- [GORM](https://github.com/techknowlogick/go-oauth2-gorm)\n- [Firestore](https://github.com/tslamic/go-oauth2-firestore)\n- [Hazelcast](https://github.com/clowre/go-oauth2-hazelcast) (token only)\n\n## Handy Utilities\n\n- [OAuth2 Proxy Logger (Debug utility that proxies interfaces and logs)](https://github.com/aubelsb2/oauth2-logger-proxy)\n\n## MIT License\n\nCopyright (c) 2016 Lyric\n\n[build-status-url]: https://travis-ci.org/go-oauth2/oauth2\n[build-status-image]: https://travis-ci.org/go-oauth2/oauth2.svg?branch=master\n[codecov-url]: https://codecov.io/gh/go-oauth2/oauth2\n[codecov-image]: https://codecov.io/gh/go-oauth2/oauth2/branch/master/graph/badge.svg\n[reportcard-url]: https://goreportcard.com/report/github.com/go-oauth2/oauth2/v4\n[reportcard-image]: https://goreportcard.com/badge/github.com/go-oauth2/oauth2/v4\n[godoc-url]: https://godoc.org/github.com/go-oauth2/oauth2/v4\n[godoc-image]: https://godoc.org/github.com/go-oauth2/oauth2/v4?status.svg\n[license-url]: http://opensource.org/licenses/MIT\n[license-image]: https://img.shields.io/npm/l/express.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-oauth2%2Foauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-oauth2%2Foauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-oauth2%2Foauth2/lists"}