{"id":22015524,"url":"https://github.com/rafaelsouzaribeiro/jwt-auth","last_synced_at":"2026-05-07T14:43:58.986Z","repository":{"id":233214694,"uuid":"784383007","full_name":"rafaelsouzaribeiro/jwt-auth","owner":"rafaelsouzaribeiro","description":"JWT with gRPC, HTTP, Echo and Gin auth module in Golang","archived":false,"fork":false,"pushed_at":"2025-05-13T23:59:40.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-20T03:40:38.201Z","etag":null,"topics":["gin-gonic","golang","grpc","http","jwt-authentication"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"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/rafaelsouzaribeiro.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,"zenodo":null}},"created_at":"2024-04-09T18:32:36.000Z","updated_at":"2025-04-10T09:47:44.000Z","dependencies_parsed_at":"2025-01-28T15:40:37.912Z","dependency_job_id":"6abf7dc7-c37c-4049-9fe0-fff151b11ab3","html_url":"https://github.com/rafaelsouzaribeiro/jwt-auth","commit_stats":null,"previous_names":["rafaelsouzaribeiro/jwt-auth"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/rafaelsouzaribeiro/jwt-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelsouzaribeiro%2Fjwt-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelsouzaribeiro%2Fjwt-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelsouzaribeiro%2Fjwt-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelsouzaribeiro%2Fjwt-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafaelsouzaribeiro","download_url":"https://codeload.github.com/rafaelsouzaribeiro/jwt-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelsouzaribeiro%2Fjwt-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32742775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"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":["gin-gonic","golang","grpc","http","jwt-authentication"],"created_at":"2024-11-30T04:25:53.631Z","updated_at":"2026-05-07T14:43:58.957Z","avatar_url":"https://github.com/rafaelsouzaribeiro.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cstrong\u003eVersion: v1.20.0\u003c/strong\u003e\u003cbr /\u003e\n\u003cstrong\u003eAdding Bearer authentication with Echo\u003c/strong\u003e\u003cbr/\u003e\n```go\n\te := echo.New()\n\tcre, err := middleware.NewCredential(3600, \"secretkey\", nil)\n\n\tif err != nil {\n\t\tpanic(err)\n\n\t}\n\n\te.GET(\"/protected\", func(c echo.Context) error {\n\t\treturn c.JSON(http.StatusOK, map[string]string{\"message\": \"You are authorized!\"})\n\t}, cre.AuthMiddlewareEcho)\n\te.Logger.Fatal(e.Start(\":1323\"))\n```\n\n\u003cstrong\u003eVersion: v1.19.0\u003c/strong\u003e\u003cbr /\u003e\n\u003cstrong\u003eAdding Bearer authentication with Gin\u003c/strong\u003e\u003cbr/\u003e\n ```go\n import (\n\t\"net/http\"\n\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/rafaelsouzaribeiro/jwt-auth/pkg/middleware\"\n)\n\nrouter := gin.Default()\ncre, err := middleware.NewCredential(3600, \"secretkey\", nil)\n\nif err != nil {\n\tpanic(err)\n}\n\nrouter.POST(\"/publish\", cre.AuthMiddlewareGin(), func(c *gin.Context) {\n\tvar json struct {\n\t\tMessage string `json:\"message\"`\n\t}\n\n\tif err := c.ShouldBindJSON(\u0026json); err != nil {\n\t\tc.JSON(http.StatusBadRequest, gin.H{\"error\": err.Error()})\n\t\treturn\n\t}\n\n\tc.JSON(http.StatusOK, gin.H{\n\t\t\"status\":  \"success\",\n\t\t\"message\": json.Message,\n\t})\n})\n\nrouter.Run(\":8080\")\n ```\n\n\u003cstrong\u003eVersion: v1.15.0 or latest\u003c/strong\u003e\u003cbr /\u003e\n\u003cstrong\u003eUpdating folder: pkg/middleware\u003c/strong\u003e\u003cbr /\u003e \n ```go\nimport jwtauth \"github.com/rafaelsouzaribeiro/jwt-auth/pkg/middleware\"\n ```\n\n\u003cstrong\u003eVersion: v1.14.0 or latest\u003c/strong\u003e\u003cbr /\u003e\n\u003cstrong\u003eExtractClaims method\u003c/strong\u003e\u003cbr /\u003e \n ```go\n\n\tcre, err := jwtauth.NewCredential(3600, \"secretkey\", nil)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\t\n\n\tclaims, err = cre.ExtractClaims(token)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tprintln(fmt.Sprint(claims[\"lastname\"]), fmt.Sprint(claims[\"firstname\"]))\n```\n\u003cbr /\u003e \n\u003cstrong\u003eCreateToken\u003c/strong\u003e\u003cbr /\u003e\n\t\n```go \t\n\t// pass multiple data\n\tclaims := map[string]interface{}{\n\t\t\"username\": username,\n\t\t // ... other claims\n\t}\n\n\ttoken, err := cre.CreateToken(claims)\n```\n\n\u003cstrong\u003eMethods for http getting the bearer token and validating\u003c/strong\u003e\u003cbr /\u003e      \n\n  ```go\n package main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\n\tjwtauth \"github.com/rafaelsouzaribeiro/jwt-auth\"\n)\n\nfunc main() {\n\n\tmx := http.NewServeMux()\n\tcre, err := jwtauth.NewCredential(3600, \"secretkey\", nil)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Protected routes\n\tmx.HandleFunc(\"/route1\", cre.AuthMiddleware(rota1Handler))\n\tmx.HandleFunc(\"/route2\", cre.AuthMiddleware(rota2Handler))\n\n\t// Public route\n\tmx.HandleFunc(\"/public-route\", rotaPublicaHandler)\n\n\thttp.ListenAndServe(\":8080\", mx)\n}\n\nfunc rota1Handler(w http.ResponseWriter, r *http.Request) {\n\tfmt.Fprintf(w, \"Token-protected Route 1\")\n}\n\nfunc rota2Handler(w http.ResponseWriter, r *http.Request) {\n\tfmt.Fprintf(w, \"Token-protected Route 2\")\n}\n\nfunc rotaPublicaHandler(w http.ResponseWriter, r *http.Request) {\n\tfmt.Fprintf(w, \"Public route accessible without token\")\n}\n\n\n```\n\n\u003cbr/\u003e\n\u003cstrong\u003eHow to add an interceptor in grpc?\u003c/strong\u003e\u003cbr /\u003e  \n\u003cstrong\u003eThis example takes Bearer Token Authentication and skips token validation for functions login,loginAdm\u003c/strong\u003e\u003cbr /\u003e  \n\n  ```go \n\tc, errs := jwtauth.NewCredential(3600, secretkey, []string{\"login\", \"loginAdm\"})\n\n\tif err != nil {\n\t\tpanic(errs)\n\t}\n\n\tgrpcServer := grpc.NewServer(\n\t\tgrpc.UnaryInterceptor(c.UnaryInterceptorBearer),\n\t\tgrpc.StreamInterceptor(c.StreamInterceptorBearer),\n\t)\n```\n\u003cstrong\u003eHow to add an interceptor in grpc? passing the token as a parameter\u003c/strong\u003e\u003cbr /\u003e   \n\n  ```go\n\tcre, err := jwtauth.NewCredential(3600, secretkey, nil)\n\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tclaims := map[string]interface{}{\n\t\t\"username\": username,\n\t\t // ... other claims\n\t}\n\n\ttoken, err := cre.CreateToken(claims)\n\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tgrpcServer := grpc.NewServer(\n\t\tgrpc.UnaryInterceptor(c.JwtUnaryInterceptor(token)),\n\t\tgrpc.StreamInterceptor(c.JwtStreamInterceptor(token)),\n\t)\n\n  ```\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelsouzaribeiro%2Fjwt-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafaelsouzaribeiro%2Fjwt-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelsouzaribeiro%2Fjwt-auth/lists"}