This repository contains a simple Spring Boot application that demonstrates user authentication and authorization using Spring Security. It provides a RESTful API for user registration and login, utilizing JWT (JSON Web Tokens) for secure token-based authentication.
- User registration with password hashing
- User login with JWT token generation
- Role-based access control
- Secure API endpoints
- In-memory database for demonstration purposes
- Spring Boot: Framework for building Java applications.
- Spring Security: Provides authentication and authorization.
- JWT: For secure token-based authentication.
Make sure you have the following installed:
- Java 11 or higher
- Maven
git clone https://github.com/asiripr/spring-boot-auth.git
cd spring-boot-authRun the following command to build the application:
mvn clean installYou can run the application using:
mvn spring-boot:runThe application will start on http://localhost:8080.
- POST
/api/auth/register- Request Body:
{ "username": "exampleUser", "password": "examplePassword" }
- Request Body:
- POST
/api/auth/login- Request Body:
{ "username": "exampleUser", "password": "examplePassword" } - Response:
{ "token": "your_jwt_token" }
- Request Body: