{"id":14987710,"url":"https://github.com/ken109/gin-jwt","last_synced_at":"2025-04-12T00:16:47.282Z","repository":{"id":57564171,"uuid":"334800356","full_name":"ken109/gin-jwt","owner":"ken109","description":"Very easy to use jwt with gin framework.","archived":false,"fork":false,"pushed_at":"2025-02-20T07:42:39.000Z","size":63,"stargazers_count":2,"open_issues_count":3,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T00:16:41.148Z","etag":null,"topics":["gin","go","golang","jwt"],"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/ken109.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":"2021-02-01T01:44:58.000Z","updated_at":"2025-02-20T07:41:45.000Z","dependencies_parsed_at":"2023-11-23T06:26:43.988Z","dependency_job_id":"54c85f5d-5ad9-4b84-8af4-928b095144c3","html_url":"https://github.com/ken109/gin-jwt","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken109%2Fgin-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken109%2Fgin-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken109%2Fgin-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ken109%2Fgin-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ken109","download_url":"https://codeload.github.com/ken109/gin-jwt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248497818,"owners_count":21113984,"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":["gin","go","golang","jwt"],"created_at":"2024-09-24T14:15:14.811Z","updated_at":"2025-04-12T00:16:47.258Z","avatar_url":"https://github.com/ken109.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Overview\n\n1. Issue private key\n\n```bash\nopenssl genrsa -out private.key 2048\n```\n\n2. Example main.go\n\n```go\npackage main\n\nimport (\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/ken109/gin-jwt\"\n\t\"fmt\"\n\t\"net/http\"\n)\n\nconst MyRealm = \"my-realm\"\n\nfunc main() {\n\t// setup\n\t_ = jwt.SetUp(\n\t\tjwt.Option{\n\t\t\tRealm:            MyRealm,\n\t\t\tSigningAlgorithm: jwt.RS256,\n\t\t\tPrivKeyFile:      \"private.key\",\n\t\t},\n\t)\n\n\tr := gin.New()\n\tr.POST(\"/login\", Login)\n\tr.GET(\"/refresh\", RefreshToken)\n\n\tauth := r.Group(\"/api\")\n\n\t// Set the middleware on the route you want to authenticate\n\tauth.Use(jwt.MustVerify(MyRealm))\n\n\tauth.GET(\n\t\t\"/hello\", func(c *gin.Context) {\n\t\t\tclaims := jwt.GetClaims(c)\n\n\t\t\tfmt.Println(claims[\"admin\"].(bool)) // true\n\n\t\t\tc.JSON(http.StatusOK, claims)\n\t\t},\n\t)\n\n\tif err := r.Run(\":8080\"); err != nil {\n\t\tpanic(err)\n\t}\n}\n\nfunc Login(c *gin.Context) {\n\tpassword := \"test\"\n\n\tif password != \"test\" {\n\n\t\tc.JSON(http.StatusForbidden, \"login failed\")\n\n\t\treturn\n\t} else {\n\t\t// Issue Token\n\t\ttoken, refreshToken, _ := jwt.IssueToken(\n\t\t\tMyRealm,\n\t\t\tjwt.Claims{\n\t\t\t\t\"admin\": true,\n\t\t\t},\n\t\t)\n\n\t\tc.JSON(\n\t\t\thttp.StatusOK, gin.H{\n\t\t\t\t\"token\":         token,\n\t\t\t\t\"refresh_token\": refreshToken,\n\t\t\t},\n\t\t)\n\t}\n}\n\nfunc RefreshToken(c *gin.Context) {\n\tok, token, refreshToken, _ := jwt.RefreshToken(MyRealm, c.Query(\"refresh_token\"))\n\tif !ok {\n\t\tc.Status(http.StatusUnauthorized)\n\t\treturn\n\t}\n\n\tc.JSON(\n\t\thttp.StatusOK, gin.H{\n\t\t\t\"token\":         token,\n\t\t\t\"refresh_token\": refreshToken,\n\t\t},\n\t)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fken109%2Fgin-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fken109%2Fgin-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fken109%2Fgin-jwt/lists"}