{"id":37119477,"url":"https://github.com/teacat/ginrs","last_synced_at":"2026-01-14T13:56:03.481Z","repository":{"id":130714078,"uuid":"456766887","full_name":"teacat/ginrs","owner":"teacat","description":"🔒 JWT with RS-signing methods, designed for Gin.","archived":true,"fork":false,"pushed_at":"2022-02-23T19:17:49.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T02:05:45.838Z","etag":null,"topics":["gin","go","golang","jwt"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teacat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-02-08T03:21:40.000Z","updated_at":"2023-11-27T08:39:54.000Z","dependencies_parsed_at":"2024-06-20T01:38:39.101Z","dependency_job_id":null,"html_url":"https://github.com/teacat/ginrs","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/teacat/ginrs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fginrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fginrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fginrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fginrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teacat","download_url":"https://codeload.github.com/teacat/ginrs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teacat%2Fginrs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28422376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["gin","go","golang","jwt"],"created_at":"2026-01-14T13:56:03.005Z","updated_at":"2026-01-14T13:56:03.472Z","avatar_url":"https://github.com/teacat.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GinRS [![GoDoc](https://godoc.org/github.com/teacat/ginrs/?status.svg)](https://godoc.org/github.com/teacat/ginrs) [![Go Report Card](https://goreportcard.com/badge/github.com/teacat/ginrs)](https://goreportcard.com/report/github.com/teacat/ginrs)\n\n套用在 [gin-gonic/gin](https://github.com/gin-gonic/gin) 基於 RS256 演算法的 JWT 簽署套件。\n\n## 非對稱金鑰\n\n透過 `openssl` 產生一個私鑰。\n\n```go\nopenssl genrsa -out private.key 2048\n```\n\n再透過這個私鑰產生一個公鑰，這個公鑰可以配發到其他伺服器或是第三方的手中用來驗證未來的 JWT 是否都由同人所簽署。\n\n```go\nopenssl rsa -in private.key -pubout \u003e public.key\n```\n\n## 使用方式\n\n產生金鑰，便能透過下列方式簽署 JWT，並以公鑰驗證其簽發正確性。\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/teacat/ginrs\"\n)\n\ntype Data struct {\n\tUsername string\n}\n\nfunc main() {\n\t// 欲簽署的資料。\n\tdata := Data{\n\t\tUsername: \"YamiOdymel\",\n\t}\n\n\t// 因為要簽署和驗證，所以必須載入公私鑰兩個檔案。\n\terr := ginrs.LoadKeys(\"./tests/public.key\", \"./tests/private.key\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// 將資料透過 RS256 簽署成一個 JWT。\n\ttoken, err := ginrs.SignRS256(data)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// 驗證這個 JWT 是否正確。\n\tvar signedData Data\n\terr = ginrs.Parse(token, \u0026signedData)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(signedData.Username) // 輸出：YamiOdymel\n}\n\n```\n\n若沒有要進行簽署，而只是要驗證 JWT 是否正確，則可以將 `LoadKeys` 替換成 `LoadPublicKey` 僅載入公鑰作為驗證用途而不需要私鑰。\n\n### 用於 Gin 的中介函式\n\n透過 `Middleware` 函式可以在每個請求進入時將 JWT 簽署的資料放入 `*gin.Context` 的變數中。\n\n```go\ntype Data struct {\n\tUsername string\n}\n\nfunc main() {\n\tr := gin.Default()\n\t// 套用 GinRS 的中介函式到所有 Gin 路由。\n\tr.Use(ginrs.Middleware())\n\n\tr.GET(\"/hello\", func(c *gin.Context) {\n\t\tvar data Data\n\t\t// 透過 ginrs.MustGet 取得 JWT 資料。\n\t\tginrs.MustGet(c, \u0026data)\n\t\tfmt.Println(v.Username)\n\t})\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteacat%2Fginrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteacat%2Fginrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteacat%2Fginrs/lists"}