{"id":26276271,"url":"https://github.com/nasruddin/spring-boot-3-jwt-auth","last_synced_at":"2025-05-06T20:22:07.913Z","repository":{"id":52380014,"uuid":"51244983","full_name":"Nasruddin/spring-boot-3-jwt-auth","owner":"Nasruddin","description":":key: Sample Spring boot application secured using JWT auth in custom header(X-Auth-Token).","archived":false,"fork":false,"pushed_at":"2023-09-28T19:47:39.000Z","size":1272,"stargazers_count":110,"open_issues_count":0,"forks_count":32,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-31T02:34:33.480Z","etag":null,"topics":["authentication","authorization","custom-jwt","custom-jwt-auth","jwt","jwt-tokens","openapi3","spring-boot","spring-boot-3","spring-security","spring-security-jwt","swagger-documentation","swagger-ui"],"latest_commit_sha":null,"homepage":"","language":"Java","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/Nasruddin.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}},"created_at":"2016-02-07T11:17:36.000Z","updated_at":"2025-03-17T20:56:56.000Z","dependencies_parsed_at":"2023-09-26T05:33:11.000Z","dependency_job_id":null,"html_url":"https://github.com/Nasruddin/spring-boot-3-jwt-auth","commit_stats":null,"previous_names":["nasruddin/spring-boot-jwt-auth"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nasruddin%2Fspring-boot-3-jwt-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nasruddin%2Fspring-boot-3-jwt-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nasruddin%2Fspring-boot-3-jwt-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nasruddin%2Fspring-boot-3-jwt-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nasruddin","download_url":"https://codeload.github.com/Nasruddin/spring-boot-3-jwt-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252761766,"owners_count":21800206,"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":["authentication","authorization","custom-jwt","custom-jwt-auth","jwt","jwt-tokens","openapi3","spring-boot","spring-boot-3","spring-security","spring-security-jwt","swagger-documentation","swagger-ui"],"created_at":"2025-03-14T11:17:29.910Z","updated_at":"2025-05-06T20:22:07.880Z","avatar_url":"https://github.com/Nasruddin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spring-boot-3-jwt-auth\n:key: Sample Spring boot 3 application for Authentication and Authorization\n\n## Features\n* Customizable header(X-Auth-Token) to pass Auth token.\n* JWT for token creation and validation.\n* Role based authorization.\n* Device based auth.\n* Custom Validators\n* Spring doc.\n\n\n## Running the sample app\n```\nmvn spring-boot:run\n```\n\n## Registering a User\n```\ncurl -X POST \"http://localhost:9000/api/auth/register\" -H  \"accept: */*\" -H  \"Content-Type: application/json\" -d \"{\\\"username\\\":\\\"nasruddin\\\",\\\"password\\\":\\\"p@ssw00d\\\",\\\"device\\\":\\\"web\\\",\\\"email\\\":\\\"nasruddin@gmail.com\\\"}\"\n```\n\n```\n{\n    \"id\":2,\n    \"username\":\"nasruddin\",\n    \"password\":\"$2a$10$U3CR4T1Gowd50Q.0yK/UuOh.XWVx0BYIe7BiAmymXZ.MYPUtU5F.e\",\n    \"email\":\"nasruddin@gmail.com\",\n    \"lastPasswordReset\":\"2023-09-14T08:41:10.080+00:00\",\n    \"authorities\":\"ADMIN\"\n}\n```\nH2-console can be accessed at \u003chttp://localhost:9000/api/h2-console\u003e\n![JWT Decoded](https://github.com/Nasruddin/spring-boot-jwt-auth/blob/pom-update/images/h2-console.png?raw=true)\n\n## Login a User / Fetch Token\n```\ncurl -X POST \"http://localhost:9000/api/auth\" -H  \"accept: */*\" -H  \"Content-Type: application/json\" -d \"{\\\"username\\\":\\\"nasruddin\\\",\\\"password\\\":\\\"p@ssw00d\\\",\\\"device\\\":\\\"web\\\"}\"\n```\n```\n{\"token\":\"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJuYXNydWRkaW4iLCJhdWRpZW5jZSI6IndlYiIsImNyZWF0ZWQiOjE2OTQ2ODE2ODE3MDUsImV4cCI6MTY5NTI4NjQ4MX0.MydwIWzN3SgCvB8cYozKcR2tHMCM5nrIPXUBtx4o82ot1taL_NQM5TRHZ4yOc9uUcZFrz1XQAL_fDNXAIwmZxw\"}\n```\n\n![JWT Decoded](https://github.com/Nasruddin/spring-boot-3-jwt-auth/blob/master/images/decoded-jwt.png?raw=true)\n\n## Accessing User/Protected API\n\nWithout setting X-AUTH-TOKEN\n```\ncurl -X GET \"http://localhost:9000/api/user/nasruddin\" -H  \"accept: */*\"\n```\n```\n{\n    \"timestamp\":\"2023-09-14T08:57:08.403+00:00\",\n    \"status\":401,\n    \"error\":\"Unauthorized\",\n    \"path\":\"/api/user/nasruddin\"\n} \n```\n\nWith setting X-AUTH-TOKEN\n```\ncurl -X GET \"http://localhost:9000/api/users/nasruddin\" -H  \"accept: */*\" -H  \"X-Auth-Token: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJuYXNydWRkaW4iLCJhdWRpZW5jZSI6IndlYiIsImNyZWF0ZWQiOjE2OTQ2ODE2ODE3MDUsImV4cCI6MTY5NTI4NjQ4MX0.MydwIWzN3SgCvB8cYozKcR2tHMCM5nrIPXUBtx4o82ot1taL_NQM5TRHZ4yOc9uUcZFrz1XQAL_fDNXAIwmZxw\"\n```\n```\n{\n    \"id\":1,\n    \"username\":\"nasruddin\",\n    \"password\":\"$2a$10$dq6uFlehtetsfI6glLkA.OaeoIEu5PPqIVNZHDMCCiEej8b/0vhWa\",\"email\":\"nasruddin@gmail.com\",\n    \"lastPasswordReset\":\"2023-09-14T08:42:37.758+00:00\",\n    \"authorities\":\"ADMIN\"\n} \n```\n\n## Admin API\n```\ncurl -X GET \"http://localhost:9000/api/admin\" -H  \"accept: */*\" -H  \"X-Auth-Token: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJuYXNydWRkaW4iLCJhdWRpZW5jZSI6IndlYiIsImNyZWF0ZWQiOjE2OTQ2ODE2ODE3MDUsImV4cCI6MTY5NTI4NjQ4MX0.MydwIWzN3SgCvB8cYozKcR2tHMCM5nrIPXUBtx4o82ot1taL_NQM5TRHZ4yOc9uUcZFrz1XQAL_fDNXAIwmZxw\"\n```\n```\n:O\n```\n\n## OpenAPI Swagger\n1. Swagger can be accessed at \u003chttp://localhost:9000/api/swagger-ui/index.html\u003e\n\n![Swagger](https://github.com/Nasruddin/spring-boot-jwt-auth/blob/pom-update/images/swagger.png?raw=true)\n\n2. API Docs can be accessed at \u003chttp://localhost:9000/api/api-docs\u003e\n![API Docs](https://github.com/Nasruddin/spring-boot-jwt-auth/blob/pom-update/images/open-api.png?raw=true)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnasruddin%2Fspring-boot-3-jwt-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnasruddin%2Fspring-boot-3-jwt-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnasruddin%2Fspring-boot-3-jwt-auth/lists"}