This project is a robust JWT-based Authentication and Authorization Service built with Spring Boot. It provides secure user registration, authentication, and protected endpoint access.
- User registration with email and password
- User authentication and JWT token generation
- Secure endpoint protection using Spring Security
- JWT token validation for authenticated requests
- MySQL database integration for user storage
- Java 11
- Spring Boot 2.7.x
- Spring Security
- JSON Web Tokens (JWT)
- MySQL
- JPA / Hibernate
- Maven
src/main/java/com/example/authservice/Application.java: Main Spring Boot application classController/: Contains REST controllersService/: Service layer for business logicRepository/: Data access layerEntity/: JPA entitiesModel/: Data transfer objectsConfig/: Configuration classesFilter/: Custom filtersUtil/: Utility classes
- Clone the repository:
git clone https://github.com/SID9927/Authentication_Authorization_Service.git
- Navigate to the project directory:
cd auth-service
- Configure MySQL database:
- Create a MySQL database named
auth_service - Update
src/main/resources/application.propertieswith your MySQL credentials
- Build the project:
mvn clean install
- Run the application:
mvn spring-boot:run
The service will start running on http://localhost:8080.
- POST
/register: Register a new user - POST
/authenticate: Authenticate a user and receive a JWT - GET
/home: A protected endpoint that requires authentication
- Register a new user:
POST /register { "username": "[email protected]", "email": "[email protected]", "password": "password123" }
- Authenticate and receive a JWT:
POST /authenticate { "username": "[email protected]", "password": "password123" }
- Access protected endpoint:
GET /home Header: Authorization: Bearer <your_jwt_token>
- Passwords are encrypted using BCrypt before storing in the database
- JWTs are signed with a secret key and have an expiration time
- Protected endpoints require a valid JWT for access
- Implement refresh token functionality
- Add role-based access control
- Integrate with OAuth2 for third-party authentication
- Implement email verification for new user registrations
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.