{"id":38787220,"url":"https://github.com/smc181002/go-jwt-http-chi","last_synced_at":"2026-01-17T12:35:08.209Z","repository":{"id":56854619,"uuid":"516779699","full_name":"smc181002/go-jwt-http-chi","owner":"smc181002","description":"This repo is an implementation of jwt (json web token) authentication implementation with golang chi router with the built in net/http ","archived":false,"fork":false,"pushed_at":"2022-11-15T17:22:33.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-20T06:32:14.428Z","etag":null,"topics":["auth","authentication","go","go-chi","golang","jwt","jwt-auth","jwt-authentication","router"],"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/smc181002.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}},"created_at":"2022-07-22T14:25:25.000Z","updated_at":"2022-07-30T11:30:27.000Z","dependencies_parsed_at":"2023-01-22T03:20:42.246Z","dependency_job_id":null,"html_url":"https://github.com/smc181002/go-jwt-http-chi","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/smc181002/go-jwt-http-chi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smc181002%2Fgo-jwt-http-chi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smc181002%2Fgo-jwt-http-chi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smc181002%2Fgo-jwt-http-chi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smc181002%2Fgo-jwt-http-chi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smc181002","download_url":"https://codeload.github.com/smc181002/go-jwt-http-chi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smc181002%2Fgo-jwt-http-chi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28508471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T11:50:55.898Z","status":"ssl_error","status_checked_at":"2026-01-17T11:50:55.569Z","response_time":85,"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":["auth","authentication","go","go-chi","golang","jwt","jwt-auth","jwt-authentication","router"],"created_at":"2026-01-17T12:35:08.108Z","updated_at":"2026-01-17T12:35:08.176Z","avatar_url":"https://github.com/smc181002.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang JWT implementation with `net/http` library\n\n## Introduction\n\nAuthentication is one of the common things to be considered\nin building an API. Here is a simple code implementing JWT\napplication in a webserver built with the help go `net/http`\nand using [go-chi](https://github.com/go-chi/chi) for \nhandling the routing.\n\n## Installation\n\nGo version `1.18`\n\nStart cloning the repository with \n\n```bash\ngit clone https://github.com/smc181002/go-jwt-http-chi.git\n```\n\n### Package Installation\n\nThe following package have been used in the repository\n\n* go-chi's chi/v5 router\n* go-chi's cors middleware to handle the cors headers\n* go-chi's render to render JSON data in the API handlers\n* golang-jwt's jwt/v4 package\n\n```bash\ngo get github.com/go-chi/chi/v5 v5.0.7\ngo get github.com/go-chi/cors v1.2.1\ngo get github.com/golang-jwt/jwt/v4 v4.4.2\ngo get github.com/go-chi/render v1.0.1\n\ngo mod tidy\n```\n\n### Starting the server\n\nUse `go run main.go` to run the server\n\n## Testing application\n\nThe user name is fixed as `smc` for this demo but in an \nactual application, the username will be fetched from \ndatabase and the username may be replaced or combined \nwith other parameters like roles.\n\n### Using cURL\n\ncURL is a tool installed in linux distributions by default \nused to fetch data from an endpoint.\n\n**Get JWT token**\n\nwe can get the JWT token by sending `POST` request to \n`/get-token` endpoint.\n\n```bash\ncurl \\\n--data '{\"uname\": \"smc\", \"password\": \"passwd@123\"}' \\\n-H 'Content-Type: application/json' \\\nhttp://localhost:8080/get-token\n```\n\nsave the output value in environmental variables from the \nresponse JSON in the above request which will be something \nlike below.\n\n```json\n{\"token\":\"eyJh...XVCJ9.eyJ1...4ODQ0NH0.BZZltUp...2-Urx0HUfb-I\",\"error\":null}\n```\n\n\nTo request public endpoint, send `GET` request to `/posts`\n\n```bash\ncurl http://localhost:8080/posts/\nTo get the protected routes, we can send the token through \nAuthorization Header as Bearer token.\n```\n\n```bash\ncurl \\\n-H \"Authorization: Bearer $TOKEN\" \\\nhttp://localhost:8080/secret-posts\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmc181002%2Fgo-jwt-http-chi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmc181002%2Fgo-jwt-http-chi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmc181002%2Fgo-jwt-http-chi/lists"}