{"id":20807818,"url":"https://github.com/devrezaur/jwt-refresh-token-spring-boot","last_synced_at":"2025-04-09T22:10:24.498Z","repository":{"id":182459637,"uuid":"379017648","full_name":"DevRezaur/JWT-refresh-token-spring-boot","owner":"DevRezaur","description":"Ready to use implementation of JWT with refresh token using Spring Boot","archived":false,"fork":false,"pushed_at":"2021-06-25T20:08:00.000Z","size":428,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T23:51:35.970Z","etag":null,"topics":["refresh-token","spring-boot","spring-security-jwt"],"latest_commit_sha":null,"homepage":"","language":"Java","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/DevRezaur.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}},"created_at":"2021-06-21T17:51:04.000Z","updated_at":"2024-07-31T05:53:51.000Z","dependencies_parsed_at":"2023-07-20T04:37:37.855Z","dependency_job_id":null,"html_url":"https://github.com/DevRezaur/JWT-refresh-token-spring-boot","commit_stats":null,"previous_names":["devrezaur/jwt-refresh-token-spring-boot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2FJWT-refresh-token-spring-boot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2FJWT-refresh-token-spring-boot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2FJWT-refresh-token-spring-boot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRezaur%2FJWT-refresh-token-spring-boot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevRezaur","download_url":"https://codeload.github.com/DevRezaur/JWT-refresh-token-spring-boot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119294,"owners_count":21050755,"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":["refresh-token","spring-boot","spring-security-jwt"],"created_at":"2024-11-17T19:42:48.144Z","updated_at":"2025-04-09T22:10:24.468Z","avatar_url":"https://github.com/DevRezaur.png","language":"Java","readme":"# JWT Auth with Refresh Token using Spring Boot\n\nThis is a ready to use template code for implementing `JWT based authentication` with `refresh token` using Spring Boot.\n\n\u003cbr /\u003e\n\n## Documentation and Usage\n\n### Authentication API\n\n`POST` URI: `localhost:8080/auth/authenticate`\n\n\u003cbr /\u003e\n\n![authenticate-api](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/authenticate-api.PNG)\n\n### Access User Controller\n\n`GET` URI: `localhost:8080/user/`\n\n\u003cbr /\u003e\n\n![user-content](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/user-content.PNG)\n\n### Access Admin Controller\n\n`GET` URI: `localhost:8080/admin/`\n\n\u003cbr /\u003e\n\n![admin-content](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/admin-content.PNG)\n\n### Token Expired / Access Denied Example\n\n`GET` URI: `localhost:8080/admin/`\n\n\u003cbr /\u003e\n\n![access-denied](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/access-denied.PNG)\n\n### Request New Token API\n\n`POST` URI: `localhost:8080/auth/refreshtoken`\n\n\u003cbr /\u003e\n\n![token-refresh-api](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/token-refresh-api.PNG)\n\n### Refresh Token Expired Example\n\n`POST` URI: `localhost:8080/auth/refreshtoken`\n\n\u003cbr /\u003e\n\n![refresh-token-expired](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/refresh-token-expired.PNG)\n\n### User Registration API\n\n`POST` URI: `localhost:8080/user/registerUser`\n\n\u003cbr /\u003e\n\n![user-registration](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/user-registration.PNG)\n\n### Admin Registration API\n\nSince admin registration is a `admin privileged` feature, we protected it via `/admin/` mapping. So sending authentication header is required with this request.\n\n`POST` URI: `localhost:8080/admin/registerAdmin`\n\n\u003cbr /\u003e\n\n![admin-registration](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/admin-registration.PNG)\n\n### Logout from server API\n\n`POST` URI: `localhost:8080/auth/logout`\n\n\u003cbr /\u003e\n\n![logout](https://github.com/DevRezaur/JWT-refresh-token-spring-boot/blob/main/screenshots/logout.PNG)\n\n\u003cbr /\u003e\n\n## Migrate to MySQL\n\nBy default this module uses H2 database. To use MySQL edit the following configuration.\n\n\u003cbr /\u003e\n\nOpen `pom.xml` and configure it as below:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\txsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n\t\u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n\t\u003cparent\u003e\n\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\u003cartifactId\u003espring-boot-starter-parent\u003c/artifactId\u003e\n\t\t\u003cversion\u003e2.5.0\u003c/version\u003e\n\t\t\u003crelativePath/\u003e \u003c!-- lookup parent from repository --\u003e\n\t\u003c/parent\u003e\n\t\u003cgroupId\u003ecom.devrezaur\u003c/groupId\u003e\n\t\u003cartifactId\u003eJWT-refresh-token-spring-boot\u003c/artifactId\u003e\n\t\u003cversion\u003ev-1.0 alpha\u003c/version\u003e\n\t\u003cname\u003eJWT-refresh-token-spring-boot\u003c/name\u003e\n\t\u003cdescription\u003eReady to use implementation of JWT refresh token using Spring Boot\u003c/description\u003e\n\t\u003cproperties\u003e\n\t\t\u003cjava.version\u003e15\u003c/java.version\u003e\n\t\u003c/properties\u003e\n\t\u003cdependencies\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-data-jpa\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-security\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-web\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eio.jsonwebtoken\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003ejjwt\u003c/artifactId\u003e\n\t\t\t\u003cversion\u003e0.9.1\u003c/version\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-devtools\u003c/artifactId\u003e\n\t\t\t\u003cscope\u003eruntime\u003c/scope\u003e\n\t\t\t\u003coptional\u003etrue\u003c/optional\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003emysql\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003emysql-connector-java\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003ecom.fasterxml.jackson.module\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003ejackson-module-kotlin\u003c/artifactId\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-boot-starter-test\u003c/artifactId\u003e\n\t\t\t\u003cscope\u003etest\u003c/scope\u003e\n\t\t\u003c/dependency\u003e\n\t\t\u003cdependency\u003e\n\t\t\t\u003cgroupId\u003eorg.springframework.security\u003c/groupId\u003e\n\t\t\t\u003cartifactId\u003espring-security-test\u003c/artifactId\u003e\n\t\t\t\u003cscope\u003etest\u003c/scope\u003e\n\t\t\u003c/dependency\u003e\n\t\u003c/dependencies\u003e\n\n\t\u003cbuild\u003e\n\t\t\u003cplugins\u003e\n\t\t\t\u003cplugin\u003e\n\t\t\t\t\u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n\t\t\t\t\u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n\t\t\t\u003c/plugin\u003e\n\t\t\u003c/plugins\u003e\n\t\u003c/build\u003e\n\n\u003c/project\u003e\n```\n\n\u003cbr /\u003e\n\nAfter that open `src/main/resources/application.properties` and configure like below:\n\n```properties\nserver.port=8080\nspring.jpa.open-in-view=false\nspring.h2.console.enabled=true\nspring.datasource.url=jdbc:mysql://localhost:3306/database_name\nspring.datasource.username=username\nspring.datasource.password=password\nspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect\nspring.jpa.show-sql=true\nspring.jpa.defer-datasource-initialization=true\n\n# JWT secret key\njwt.secret=secret\n# Access token lifespan (5 min)\njwt.jwtExp=300000\n# Refresh token lifespan (24 hours)\njwt.refreshExp=86400000\n```\n\n\u003cbr /\u003e\n\n## Additional Configuration\n\n`src/main/resources/data.sql` file is used to insert initial data to the database. This file is not mandatory. Feel free to `modify/delete` this `data.sql` file.\n\n```sql\nINSERT INTO roles\nVALUES(1, 'ROLE_ADMIN');\n\nINSERT INTO roles\nVALUES(2, 'ROLE_USER');\n\nINSERT INTO users (user_id, fullname, username, password)\nVALUES('101', 'Rezaur Rahman', 'DevRezaur', 'iamadmin');\n\nINSERT INTO users (user_id, fullname, username, password)\nVALUES('102', 'Sanzida Sultana', 'SanzidaSultana', 'iamuser');\n\nINSERT INTO user_role\nVALUES('101', 1);\n\nINSERT INTO user_role\nVALUES('101', 2);\n\nINSERT INTO user_role\nVALUES('102', 2);\n```\n\n\u003cbr /\u003e\n\n## Run the Project\n\n* `Clone the repository`\n* `Update maven build (Project \u003e Maven \u003e Update Project)`\n* `Run (Project \u003e Run As \u003e Spring Boot App)`\n\n\u003cbr /\u003e\n\n## Relevant Projects\n\n\u003e [JWT Auth with Spring Boot (No Refresh Token)](https://github.com/DevRezaur/spring-security-JWT-module)\n\n\u003cbr /\u003e\n\nFeel free to leave a star if you find this helpful :smile:\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrezaur%2Fjwt-refresh-token-spring-boot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevrezaur%2Fjwt-refresh-token-spring-boot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrezaur%2Fjwt-refresh-token-spring-boot/lists"}