This is a simple Spring Boot application that implements a user authentication service using Spring Security and JWT (JSON Web Tokens).
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Java Development Kit (JDK) 21
- Maven
- Clone the repository:
git clone https://github.com/your-username/spring-boot-user-authentication.git
- Navigate into the project directory:
cd spring-boot-user-authentication
- Build the project using Maven:
mvn clean install
You can run the application using Maven:
mvn spring-boot:run
The application will start at http://localhost:8080
.
Once the application is running, you can interact with it using any HTTP client such as cURL or Postman. Below are some example requests:
Send a POST request to /auth/register
with a JSON body containing the user details:
{
"name": "Example User",
"email": "exampleuser@example.com",
"password": "examplepassword",
"role": "USER"
}
Send a POST request to /auth/login
with the user credentials:
{
"email": "exampleuser@example.com",
"password": "examplepassword"
}
If the credentials are correct, you will receive a JWT token in the response.
To access a protected resource, include the JWT token in the Authorization
header of your requests:
Authorization: Bearer <JWT token>
- Spring Boot - Framework for creating Spring applications
- Spring Web - Build web, including RESTful, applications using Spring MVC
- Spring Data JPA - Simplifies data access for relational databases
- Spring Security - Authentication and access control framework
- PostgreSQL - Open source object-relational database system
- Project Lombok - Java library that helps to reduce boilerplate code
- Auth0 Java JWT - Library for working with JSON Web Tokens (JWT) in Java
- Flyway - Database migration tool for java