Skip to content

Simple JWT Authentication using Spring Boot OAuth2 Resource Server

License

Notifications You must be signed in to change notification settings

lochuung/simple-jwt-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple JWT Authentication using Spring Boot OAuth2 Resource Server

This is a simple Spring Boot application that demonstrates how to implement user authentication using JSON Web Tokens (JWT) in Spring Boot OAuth2 Resource Server and Spring Security. The application also includes a access token and refresh token functionality.

⭐ If you find this project useful, please consider giving us a star on GitHub! Your support helps us continue to innovate and deliver exciting features.

Number of GitHub contributors Number of GitHub issues that are open Number of GitHub stars Number of GitHub closed issues Number of GitHub pull requests that are open GitHub release; latest by date GitHub commit activity GitHub license which is APGL license Follow me on Facebook

Built With

Features

  • User authentication via JWT
  • Refresh token functionality

Setup and Running

  1. Clone the repository
  2. Edit the application.properties file to configure the database and JWT information:
# ===============================
# = JWT CONFIGURATION
# ===============================
# Below are the configurations for JWT

# JWT Access Token Expiration Time
jwt.access-token.expiration-time=3600
# JWT Refresh Token Expiration Time
jwt.refresh-token.expiration-time=86400

# ===============================
# = SERVER
# ===============================
# Set here configurations for the web server

server.port=8080
  1. Navigate to the project directory
  2. Run the application using the command ./mvnw spring-boot:run

API Endpoints

  • POST /api/auth/login: Authenticate a user and return an access and refresh token.

Request Body

{
  "email": "admin@cnj.vn",
  "password": "123"
}

Response Body

{
  "access_token": "access_token",
  "refresh_token": "refresh_token"
}
  • POST /api/auth/refresh-token: Refresh the access token.

Request Header

Authorization: Bearer <refresh_token>

Response Body

{
  "access_token": "access_token",
  "refresh_token": "refresh_token"
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT