{"id":20765333,"url":"https://github.com/livenux/gin-paseto","last_synced_at":"2026-04-21T11:37:34.884Z","repository":{"id":60511687,"uuid":"542496174","full_name":"Livenux/gin-paseto","owner":"Livenux","description":"gin paseto token middleware","archived":false,"fork":false,"pushed_at":"2023-06-27T10:51:37.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T06:11:40.121Z","etag":null,"topics":["auth","authentication","gin","go","middleware","paseto","token"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/Livenux/gin-paseto","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Livenux.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":"2022-09-28T08:55:32.000Z","updated_at":"2023-08-23T00:52:50.000Z","dependencies_parsed_at":"2024-06-21T02:27:23.775Z","dependency_job_id":null,"html_url":"https://github.com/Livenux/gin-paseto","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"79219739bf5028630a6ac7b5205597e7f3277cf9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Livenux%2Fgin-paseto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Livenux%2Fgin-paseto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Livenux%2Fgin-paseto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Livenux%2Fgin-paseto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Livenux","download_url":"https://codeload.github.com/Livenux/gin-paseto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243093061,"owners_count":20235289,"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":["auth","authentication","gin","go","middleware","paseto","token"],"created_at":"2024-11-17T11:16:15.112Z","updated_at":"2025-12-24T11:57:54.716Z","avatar_url":"https://github.com/Livenux.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gin PASETO token middleware\n\nThis is a middleware for Gin framework.\n\nIt uses [pvx](https://github.com/vk-rv/pvx) to provide a PASETO authentication middleware. \nCurrently, middleware supports paseto version 4 local and public.\n\n\n## Usage\n\nDownload and install using [go module](https://blog.golang.org/using-go-modules):\n``` shell\nexport GO111MODULE=on\ngo get -u github.com/Livenux/gin-paseto\n```\n\nImport it in your code:\n\n```go\nimport \"github.com/Livenux/ginpaseto\"\n```\n\n\n## Example\n### Claims\nclaims are pieces of information asserted about a subject.\n\nCreate Claims simple\n```go\nclamis := ginpaseto.NewClaims(time.Hour * 1, time.Hour*24)\n\n```\nCreate Claims with option(_Issuer_, _Subject_, _Audience_)\n\n```go\nclamis := ginpaseto.NewClaims(time.Hour * 1, time.Hour*24,\n ginpaeto.WithClaimsOption(\"api.example.com\", \n\t \"authToken\", \"web.example.com\"))\n```\n\n### Local PASETO\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"net/http\"\n\t\"time\"\n\n\tginpaseto \"github.com/Livenux/gin-paseto\"\n\t\"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n\t// hex string key\n\tkey := \"707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f\"\n\tmaker := ginpaseto.NewPasetoLocalMaker(key)\n\tauthMiddleware := ginpaseto.PasetoMiddleware{\n\t\tIssuer:       \"api.example.com\",\n\t\tSubject:      \"authToken\",\n\t\tAudience:     \".example.com\",\n\t\tExpired:         time.Hour * 2,  // token expired\n\t\tMaxRefresh:      time.Hour * 24, // token max age\n\t\tRefreshTokenURL: \"/auth/refresh\",\n\t\tBaseLoginURL:    \"/auth/login\",\n\t\tLogoutURL:       \"/auth/logout\",\n\t\tTokenHeadName:   \"Authorization\",\n\t\tCookieName:      \"auth\",\n\t\tCookieSameSite:  1,\n\t\tSendCookie:      false,\n\t\tSecureCookie:    false,\n\t\tCookieHTTPOnly:  false,\n\t}\n\t// Completion property\n\tauthMiddleware.Init(maker)\n\n\n\n\tr := gin.Default()\n\n\t// binding login handler\n\tr.POST(authMiddleware.BaseLoginURL, authMiddleware.LoginHandler(loginHandler))\n\n\t// need auth router group\n\tprivateGroup := r.Group(\"/\")\n\tprivateGroup.Use(authMiddleware.Authorization())\n\tprivateGroup.GET(\"\", func(c *gin.Context) {\n\t\tc.String(http.StatusOK, \"hello world\")\n\t})\n\t// refresh token route\n\tprivateGroup.GET(authMiddleware.RefreshTokenURL, authMiddleware.RefreshToken())\n\t// logout route\n\tprivateGroup.GET(authMiddleware.LogoutURL, authMiddleware.LogOut())\n\n\tr.Run()\n\n}\n\nfunc loginHandler(c *gin.Context) (data any, err error) {\n\tuser := loginUser{\n\t\tId:       1,\n\t\tUsername: \"admin\",\n\t\tPassword: \"chan9eMe\",\n\t}\n\trequestUser := new(loginUser)\n\tif err := c.ShouldBindJSON(requestUser); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif requestUser.Username == user.Username \u0026\u0026 requestUser.Password == user.Password {\n\t\treturn user, nil\n\t}\n\treturn nil, errors.New(\"auth failed\")\n\n}\n\ntype loginUser struct {\n\tId       int64  `json:\"id\"`\n\tUsername string `json:\"username\"`\n\tPassword string `json:\"password\"`\n}\n```\n\n\nexample start\n```shell\ngo run main.go\n```\n\nlogin example user get token\n```shell\n curl -XPOST -d '{\"username\": \"admin\", \"password\": \"chan9eMe\"}' -H \"Content-Type: application/json\" http://localhos\nt:8080/auth/login\n```\nresponse token example:\n```shell\n{\"code\":200,\"message\":\"login successful\",\"data\":{\"expire\":\"2022-09-30T18:21:48.09772Z\",\"token\":\"v4.local.qLBoiHYgkE19moyOZ0PcvhLUKTlx2QGQQ3EQ6TTLDBGMPrmqAd1jHNAf6iz6-RqAe90YFtNkWQIU3amhKPGlyyH9vKCb2pkPoW_oxft1_Q9yZzSwpuovg6Vs3xyv3eoVU8c-FepXzfcOfkNW6zUfe_WJGjAAxKn23LyO8p9wiFdRpGtzFOzlSF7nVm_iX_KZRNyQ4-91wMbm_1EUHNc3f7Jsk5mfaEWKKRP1Ez6a3A2dvQGMibPTakgpS4gmHyradbXViBKaUlkbFVX5-Qb27d1CUWu5-bIG-yOLpDgnZt7rTsOx79IkVNW29J4PEJXID_UgQzX2kXD-EN5D\"}}\n```\nrefresh token use exists token:\n```shell\ncurl -XGET -H \"Authorization: Bearer v4.local.qLBoiHYgkE19moyOZ0PcvhLUKTlx2QGQQ3EQ6TTLDBGMPrmqAd1jHNAf6iz6-RqAe90YFtNkWQIU3amhKPGlyyH9vKCb2pkPoW_oxft1_Q9yZzSwpuovg6Vs3xyv3eoVU8c-FepXzfcOfkNW6zUfe_WJGjAAxKn23LyO8p9wiFdRpGtzFOzlSF7nVm_iX_KZRNyQ4-91wMbm_1EUHNc3f7Jsk5mfaEWKKRP1Ez6a3A2dvQGMibPTakgpS4gmHyradbXViBKaUlkbFVX5-Qb27d1CUWu5-bIG-yOLpDgnZt7rTsOx79IkVNW29J4PEJXID_UgQzX2kXD-EN5D\" http://localhost:8080/auth/refresh\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivenux%2Fgin-paseto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivenux%2Fgin-paseto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivenux%2Fgin-paseto/lists"}