{"id":18023608,"url":"https://github.com/jeffotoni/jwt-example","last_synced_at":"2025-06-24T16:37:41.768Z","repository":{"id":134047440,"uuid":"100667311","full_name":"jeffotoni/jwt-example","owner":"jeffotoni","description":"The purpose of this project is to make a simplified version using JWT for educational purposes.","archived":false,"fork":false,"pushed_at":"2017-08-18T20:00:31.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T16:03:18.761Z","etag":null,"topics":["go","go-jwt","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeffotoni.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":"2017-08-18T03:04:16.000Z","updated_at":"2017-08-19T10:13:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"1f391155-7140-4e64-9098-22385aacf33a","html_url":"https://github.com/jeffotoni/jwt-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jeffotoni/jwt-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fjwt-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fjwt-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fjwt-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fjwt-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeffotoni","download_url":"https://codeload.github.com/jeffotoni/jwt-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeffotoni%2Fjwt-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261715364,"owners_count":23198749,"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":["go","go-jwt","golang","jwt"],"created_at":"2024-10-30T07:10:00.221Z","updated_at":"2025-06-24T16:37:41.724Z","avatar_url":"https://github.com/jeffotoni.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jwt example\n\nThe purpose of this project is to make a simplified version using JWT for educational purposes.\n\nWe will create a simplistic version for understanding, we will generate a token and the expiration date and send in json format to the requester.\n\nThe requester would have to have a way to register the user before using our authenticated API.\n\nThis part of the registry we will leave last, first we will simulate with keys that we create in the server for tests purposes.\n\nWe will Generate the Token and with the same token we will validate our handlers to see if they can be executed.\n\n# Packages\n\n```go\n\ngo get -u github.com/dgrijalva/jwt-go\n\n```\n\n# Generate the keys\n\n```sh\n\n$ openssl genrsa -out private.rsa 1024\n\n$ openssl rsa -in private.rsa -pubout \u003e public.rsa.pub\n\n```\n\n# Install\n\n```go\n$ go build main.go\n\n$ sudo cp main /usr/bin/jwt\n\n```\n\n# Simulate \n\n```go\n\n$ go run simulate_ping.go\n\n```\n\n# Simulate Curl\n\n```sh\n\n$ curl -X POST -H \"Content-Type: application/json\" \\\n-H \"Authorization: Basic ZTg5NjFlZDczYTQzMzE0YWYyY2NlNDdhNGY1YjY1ZGI=:ZGExMjRhMDAwNTE1MDUyYzFlNWJjNmU0NzQ4Yzc3ZTU=\" \\\nlocalhost:9001/token\n\n$ curl -X POST -H \"Content-Type: application/json\" \\\n-H \"Authorization: Bearer \u003cTOKEN\u003e\" \\\nlocalhost:9001/ping\n\n$ curl -X POST -H \"Content-Type: application/json\" \\\n-H \"Authorization: Bearer \u003cTOKEN\u003e\" \\\nlocalhost:9001/hello\n\n```\n\n# Main function\n\n```go\n\n//\n// start\n//\nfunc main() {\n\n\t//\n\t//\n\t//\n\tShowScreen()\n\n\t// Creating limiter for all handlers\n\t// or one for each handler. Your choice.\n\t// This limiter basically says: allow at most NewLimiter request per 1 second.\n\tlimiter := tollbooth.NewLimiter(NewLimiter, time.Second)\n\n\t// Limit only GET and POST requests.\n\tlimiter.Methods = []string{\"GET\", \"POST\"}\n\n\t//\n\t//\n\t//\n\tmux := http.NewServeMux()\n\n\tmux.Handle(HandlerPing, tollbooth.LimitFuncHandler(limiter, HandlerFuncAuth(jwt.HandlerValidate, Ping)))\n\n\tmux.Handle(HandlerHello, tollbooth.LimitFuncHandler(limiter, HandlerFuncAuth(jwt.HandlerValidate, Hello)))\n\n\t//\n\t// Off the default mux\n\t// Does not need authentication, only user key and token\n\t//\n\tmux.Handle(HandlerToken, tollbooth.LimitFuncHandler(limiter, jwt.AuthBasic))\n\n\t//\n\t//\n\t//\n\tconfServer = \u0026http.Server{\n\n\t\tAddr: \":\" + ServerPort,\n\n\t\tHandler: mux,\n\t\t//ReadTimeout:    30 * time.Second,\n\t\t//WriteTimeout:   20 * time.Second,\n\t\tMaxHeaderBytes: 1 \u003c\u003c 23, // Size accepted by package\n\t}\n\n\tlog.Fatal(confServer.ListenAndServe())\n\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fjwt-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeffotoni%2Fjwt-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeffotoni%2Fjwt-example/lists"}