{"id":22782419,"url":"https://github.com/kdhttps/jwt-auth","last_synced_at":"2025-03-30T14:41:58.052Z","repository":{"id":102317497,"uuid":"208630873","full_name":"kdhttps/jwt-auth","owner":"kdhttps","description":"JWT Token authentication - Kong Plugin ","archived":false,"fork":false,"pushed_at":"2019-09-21T17:20:19.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-05T16:24:31.999Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kdhttps.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":"2019-09-15T17:32:18.000Z","updated_at":"2019-09-21T16:46:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"2d688e0f-5216-47b7-833f-6572a03ebf5b","html_url":"https://github.com/kdhttps/jwt-auth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdhttps%2Fjwt-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdhttps%2Fjwt-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdhttps%2Fjwt-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdhttps%2Fjwt-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kdhttps","download_url":"https://codeload.github.com/kdhttps/jwt-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246333931,"owners_count":20760638,"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":[],"created_at":"2024-12-11T21:11:49.687Z","updated_at":"2025-03-30T14:41:58.026Z","avatar_url":"https://github.com/kdhttps.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jwt-auth\n\nJWT Authenticaion plugin for Kong Lua plugin\n\n# Setup\n\n## Clone\n\nPlugin use some third party libs so need to clone repository recursively. \nWith version 2.13 of Git and later\n```\ngit clone --recurse-submodules git@github.com:3gthtech/jwt-auth.git\n```\n\nWith version 1.9 of Git up until version 2.12\n```\ngit clone --recursive git@github.com:3gthtech/jwt-auth.git\n```\n\n## Kong Configuration\n\n### Take a file from your local clone repo `/third-party` folder.\n\n```\n$ sudo cp -R /third-party/lua-resty-lrucache/lib/resty/ /usr/local/share/lua/5.1/resty\n\n$ sudo cp /third-party/lua-resty-lrucache/lib/resty/lrucache.lua /usr/local/share/lua/5.1/resty\n\n$ sudo cp -a /third-party/lua-resty-jwt/lib/resty/. /usr/local/share/lua/5.1/resty\n\n$ sudo cp -a /third-party/lua-resty-hmac/lib/resty/. /usr/local/share/lua/5.1/resty\n```\n\n### Install our `jwt-auth` with kong plugin\n\n```\n$ sudo cp -R /kong/plugins/jwt-auth /usr/local/share/lua/5.1/kong/plugins\n```\n\nEnable plugin by adding plugin name in `/etc/kong/kong.conf`\n\n```\nplugins = bundled, jwt-auth\n```\n\n`bundled` is for kong default plugins. After adding this name, restart kong `sudo kong restart`.\n\n# Configuration\n\n1. Add service\n\n```\n$ curl --fail -sS -X POST --url http://localhost:8001/services/ --header 'content-type: application/json' --data '{\"name\":\"demo-service\",\"url\":\"http://backend\"}'\n```\n\n2. Add Route\n\n```\n$ curl --fail -i -sS -X POST  --url http://localhost:8001/services/demo-service/routes --data 'hosts[]=backend.com'\n```\n\nBefore add plugin check proxy with your upstream API\n\n```\ncurl -i -sS -X GET --url http://localhost:8000/v1/user --header 'Host: backend.com'\n```\n\n3. Add Plugin\n\n```\n$ curl -v -i -sS -X POST  --url http://localhost:8001/plugins/  --header 'content-type: application/json;charset=UTF-8' --data '{\"config\":{\"check_jwt_expire\":60,\"login_endpoint\":\"/tokens\",\"refresh_token_endpoint\":\"/tokens\",\"upstream_url\":\"http://localhost:8081\"},\"name\":\"jwt-auth\",\"service\":{\"id\":\"dc862e47-4475-4cb0-ac48-9f9d4f1eb869\"}}'\n```\n\nSchema details\n\n| Title | Description |\n|-------|-------------|\n| upstream_url | Your upstream service example: `http://localhost:8081` |\n| login_endpoint | Authotization endpoint from your upstream service from where you get JWT. Example: `/tokens` |\n| refresh_token_endpoint | Refresh token endpoint from your upstream service from where you get new JWT by refresh token. Example: `/tokens` |\n| check_jwt_expire | Time in second to check old JWT expire time before it expired. This time in seconds. Default value is 60 seconds. |\n\n# Usage\n\nRequest to login_endpoint through kong proxy to upstream service.\n\n```\n$ curl -sS -X POST --url http://localhost:8000/tokens --header 'Host: backend.com'  --header 'content-type: application/json' --data '{\"email\":\"admin@gmail.com\", \"password\": \"admin\"}'\n```\n\nGet a new token from this and request to access protected resources.\n\n```\ncurl -i -sS -X GET --url http://localhost:8000/v1/user --header 'Host: backend.com' --header 'Authorization: Bearer \u003cyour_jwt_token\u003e'\n```\n\n# Test\n\n[Test cases](./t)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdhttps%2Fjwt-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkdhttps%2Fjwt-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdhttps%2Fjwt-auth/lists"}