{"id":37174311,"url":"https://github.com/demo007x/oauth2-client","last_synced_at":"2026-01-14T20:22:14.627Z","repository":{"id":152046093,"uuid":"624350803","full_name":"demo007x/oauth2-client","owner":"demo007x","description":"Oauth2 Client package for Golang","archived":false,"fork":false,"pushed_at":"2023-04-08T13:53:15.000Z","size":112,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T14:53:01.345Z","etag":null,"topics":["auth","auth2","dingtalk-oauth","feishu-api","go","golang-package","oauth","oauth2-client","oauth2-provider","servers","wechat-oauth2"],"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/demo007x.png","metadata":{"files":{"readme":"README-CN.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-04-06T09:20:41.000Z","updated_at":"2025-12-17T04:53:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ec39d75-e51a-4aaf-a655-6a9741d16b5a","html_url":"https://github.com/demo007x/oauth2-client","commit_stats":null,"previous_names":["anziguoer/oauth2-client"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/demo007x/oauth2-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demo007x%2Foauth2-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demo007x%2Foauth2-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demo007x%2Foauth2-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demo007x%2Foauth2-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/demo007x","download_url":"https://codeload.github.com/demo007x/oauth2-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/demo007x%2Foauth2-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["auth","auth2","dingtalk-oauth","feishu-api","go","golang-package","oauth","oauth2-client","oauth2-provider","servers","wechat-oauth2"],"created_at":"2026-01-14T20:22:14.030Z","updated_at":"2026-01-14T20:22:14.590Z","avatar_url":"https://github.com/demo007x.png","language":"Go","funding_links":["https://www.buymeacoffee.com/demo007x"],"categories":[],"sub_categories":[],"readme":"# Golang OAuth 2.0 Client\n\u003cp align=\"center\"\u003e\n\u003cimg align=\"center\" width=\"150px\" src=\"https://www.oauth.com/wp-content/themes/oauthdotcom/images/oauth_logo@2x.png\" /\u003e\n\u003c/p\u003e\n\u003ch3 align=center\u003eGolang 实现的 OAuth2.0 客户端\u003c/h3\u003e\n\n[English](README.md) | 简体中文 | [Oauth2 流程介绍](oauth-flow-cn.md)\n\n## OAuth 2.0协议流程\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## OAuth 客户端的实现及其特点\n\n- 提供生成授权码URL\n- 通过 OAuth2 服务器的授权码提供获取 AccessToken\n- 通过AccessToken提供获取用户信息\n- 通过AccessToken刷新 AccessToken 功能\n- 注销 AccessToken 功能\n\n## 安装\n\n在你的项目中使用下面的命令安装:\n\n`go get -u github.com/demo007x/oauth2-client`\n\n## 快速开始\n\n以下示例提供了一个github授权的示例代码:\n\n```go\npackage main\n\nimport (\n\t\"github.com/demo007x/oauth2-client/oauth\"\n\t\"log\"\n\t\"net/http\"\n\t\"net/url\"\n)\n\n// This Is GitHub.com Oauth Restfull Demo\nvar (\n\tclientID    = \"567bcc7f346c8ce22e1893cee0f43a3a\" // change youself clientID\n\tsecret      = \"a4a2d532e29a262a8fc67bc5e4db01be\"\n\tserverURL   = \"https://github.com/login/oauth/authorize\"\n\tredirectURL = \"http://127.0.0.1:8080/oauth/callback\"\n\tscope       = \"user read:user\"\n\tstate       = \"xxxx\"\n)\n\nfunc handler(w http.ResponseWriter, r *http.Request) {\n\tgithubClient := oauth.NewOauth2Client(serverURL, clientID, oauth.WithRedirectURI(redirectURL), oauth.WithState(state), oauth.WithScope(scope))\n\tauthURL, err := githubClient.AuthorizeURL()\n\tif err != nil {\n\t\tw.WriteHeader(http.StatusInternalServerError)\n\t\tw.Write([]byte(err.Error()))\n\t\treturn\n\t}\n\thttp.Redirect(w, r, authURL, http.StatusFound)\n\treturn\n}\n\nfunc callback(w http.ResponseWriter, r *http.Request) {\n\tvar serverURL = \"https://github.com/login/oauth/access_token\"\n\tu, _ := url.ParseRequestURI(r.RequestURI)\n\tvar code = u.Query().Get(\"code\")\n\tlog.Println(\"code = \", code)\n\t// get access token by code\n\taccessToken := oauth.NewAccessToken(serverURL, clientID, secret, code, oauth.AccessTokenWithContentType(\"application/json\"))\n\tdata, err := accessToken.DoRequest()\n\tif err != nil {\n\t\tw.WriteHeader(http.StatusInternalServerError)\n\t\tw.Write([]byte(err.Error()))\n\t\treturn\n\t}\n\tgetUserinfo(w, string(data))\n}\n\nfunc getUserinfo(w http.ResponseWriter, requestURI string) {\n\t//access_token=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\u0026scope=user\u0026token_type=bearer\n\tvalues, _ := url.ParseQuery(requestURI)\n\tvar accessToken = values.Get(\"access_token\")\n\tvar serverURL = \"https://api.github.com/user\"\n\tuser := oauth.NewUserInfo(serverURL, accessToken)\n\tdata, err := user.DoRequest()\n\tif err != nil {\n\t\tw.WriteHeader(http.StatusInternalServerError)\n\t\tw.Write([]byte(err.Error()))\n\t\treturn\n\t}\n\tw.Write(data)\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", handler)\n\thttp.HandleFunc(\"/oauth/callback\", callback)\n\n\thttp.ListenAndServe(\":8080\", nil)\n}\n```\n\n## Give a Star! ⭐\n如果你喜欢或正在使用这个项目来学习或开始你的解决方案，请给它一颗星。谢谢！\n\n## Buy me a coffee\n\n\u003ca href=\"https://www.buymeacoffee.com/demo007x\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"height: 60px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n\n## 问题讨论\n\u003cimg src=\"https://user-images.githubusercontent.com/6418340/230716042-135d28f0-9912-4ba4-8adf-a8f14eb76b05.png\" alt=\"discard with Me\" style=\"height: 150px !important;width: 150px !important;\" \u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemo007x%2Foauth2-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdemo007x%2Foauth2-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdemo007x%2Foauth2-client/lists"}