/SpringBootRefreshTokenJWT

Refresh Token with JWT in Spring Boot

Primary LanguageJava

Spring Boot Refresh Token with JWT

Main Information

📖 Information

  • Once the JWT has expired, the user/system will make a call to another url suppose /refreshtoken. Also along with this request the expired JWT should be passed. The Server will then return a new JWT which can be used by the user/system
  • Here is the explanation of the project
    • Implement the process of registering for user by default of its defined role
    • Implement the process of signing in the system for user
    • Implement the process of refreshing token when JWT has expired
    • Implement the process of opening page with respect to user's defined role
    • Implement the process of signing out from the system for user

🔨 Run the App

1 ) Download your project from this link https://github.com/Rapter1990/SpringBootRefreshTokenJWT

2 ) Go to the project's home directory : cd SpringBootRefreshTokenJWT

3 ) Create a jar file though this command mvn clean install

4 ) Run the project though this command mvn spring-boot:run

5 ) Explore Rest APIs

Method Url Description Valid Request Body Valid Header
POST /signup Sign Up Info
POST /signin Sign In Info
POST /logout Logout Info
POST /refreshtoken Refresh Token Info
GET /pages/all Show Public Content Info
GET /pages/user Show User Content Info
GET /pages/admin Show Admin Content Info
GET /pages/moderator Show Moderator Content Info

Used Dependencies

  • Spring Boot Web
  • Spring Security
  • Spring Boot Test
  • Spring Boot Starter Validation
  • JSON Web Token
  • Google Code JSON
  • Lombok
  • Mysql
  • Swagger

Swagger

Access : http://localhost:1221/swagger-ui.html

Valid Request Body

    {
        "username" : "User1",
        "password" : "user1",
        "email" : "user@refreshtoken.com"
    }
    {
        "username" : "User1",
        "password" : "user1",
        "email" : "user1_role_user@refreshtoken.com",
        "roles" : [
            "ROLE_USER"
        ]
    }
    {
        "username" : "User1",
        "password" : "user1",
        "email" : "user1_role_user@refreshtoken.com",
        "roles" : [
            "ROLE_USER", "ROLE_MODERATOR"
        ]
    }
   {
       "username" : "User1",
       "password" : "user1"
   }
   {
       "refreshToken" : "a93444ea-5c0f-4130-8f80-0cce82d53155"
   }

Valid Header

   http://localhost:1221/api/auth/logout

   Authorization : Bearer {accessToken}
   http://localhost:1221/api/pages/all
   http://localhost:1221/api/pages/user

   Authorization : Bearer {accessToken} 
   http://localhost:1221/api/pages/admin

   Authorization : Bearer {accessToken} 
   http://localhost:1221/api/pages/moderator

   Authorization : Bearer {accessToken}

Screenshots

Click here to show the screenshots of project

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

Figure 12

Figure 13