Skip to content

mohankumaronly/LearnFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

56 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Java Authentication Service

A production-style Spring Boot authentication service built with JWT, email verification, password reset, and refresh token support. This project demonstrates how to build a secure and reusable authentication backend that can be integrated into any web or mobile application.


Tech Stack

Java Spring Boot JWT PostgreSQL Docker License

  • Java 21
  • Spring Boot
  • Spring Security
  • JWT (JSON Web Token)
  • PostgreSQL (Neon)
  • Brevo SMTP (Email Service)
  • Maven
  • Docker

Live API Documentation

Explore and test the API using Swagger UI:

πŸ‘‰ Swagger UI

Swagger provides interactive API documentation where you can:

  • Test authentication endpoints
  • View request/response schemas
  • Understand API flows

Features

Authentication

  • User registration with email & password
  • Secure login with JWT authentication
  • Refresh token support
  • Logout with refresh token revocation

Email System

  • Email verification after registration
  • Password reset via email
  • Email delivery using Brevo SMTP

Security

  • BCrypt password hashing
  • JWT authentication filter
  • Stateless authentication
  • Token expiration handling

Database

  • PostgreSQL database
  • JPA / Hibernate ORM
  • Token lifecycle management

Tokens Implemented

  • Access Token (JWT)
  • Refresh Token
  • Email Verification Token
  • Password Reset Token

API Endpoints

Authentication

Method Endpoint Description
POST /api/auth/register Register a new user
POST /api/auth/login Login user
POST /api/auth/refresh Refresh access token
POST /api/auth/logout Logout user

Email Verification

Method Endpoint Description
POST /api/auth/verify-email Verify email using token
GET /api/auth/verify-email Verify email via link

Password Reset

Method Endpoint Description
POST /api/auth/forgot-password Send password reset email
POST /api/auth/reset-password Reset password

Email Flow

Email Verification

  1. User registers
  2. Verification token is generated
  3. Email sent via Brevo
  4. User clicks verification link
  5. Email is marked as verified

Password Reset

  1. User requests password reset
  2. Reset token generated
  3. Email sent with reset link
  4. User sets new password

Run Locally

Run with Maven

./mvnw spring-boot:run

Run with Docker

Build the image:

docker build -t auth-service .

Run the container:

docker run --env-file .env -p 8080:8080 auth-service

Test API

Health check endpoint:

GET http://localhost:8080/test

Expected response:

Rockrangerz Spring Boot Docker Test Successful

Project Structure

authentication-service
β”‚
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ pom.xml
β”œβ”€β”€ README.md
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .env.example
β”œβ”€β”€ mvnw
β”œβ”€β”€ mvnw.cmd
β”‚
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ main
β”‚   β”‚   β”œβ”€β”€ java
β”‚   β”‚   β”‚   └── com
β”‚   β”‚   β”‚       └── rockrager
β”‚   β”‚   β”‚           └── authentication
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ AuthenticationApplication.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ config
β”‚   β”‚   β”‚               β”‚   └── SecurityConfig.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ controller
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ AuthController.java
β”‚   β”‚   β”‚               β”‚   └── TestController.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ dto
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ request
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ RegisterRequest.java
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ LoginRequest.java
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ RefreshTokenRequest.java
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ LogoutRequest.java
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ VerifyEmailRequest.java
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ ForgotPasswordRequest.java
β”‚   β”‚   β”‚               β”‚   β”‚   └── ResetPasswordRequest.java
β”‚   β”‚   β”‚               β”‚   β”‚
β”‚   β”‚   β”‚               β”‚   └── response
β”‚   β”‚   β”‚               β”‚       └── AuthResponse.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ entity
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ User.java
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ RefreshToken.java
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ EmailVerificationToken.java
β”‚   β”‚   β”‚               β”‚   └── PasswordResetToken.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ repository
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ UserRepository.java
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ RefreshTokenRepository.java
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ EmailVerificationTokenRepository.java
β”‚   β”‚   β”‚               β”‚   └── PasswordResetTokenRepository.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ security
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ jwt
β”‚   β”‚   β”‚               β”‚   β”‚   β”œβ”€β”€ JwtAuthenticationFilter.java
β”‚   β”‚   β”‚               β”‚   β”‚   └── JwtService.java
β”‚   β”‚   β”‚               β”‚   β”‚
β”‚   β”‚   β”‚               β”‚   └── user
β”‚   β”‚   β”‚               β”‚       β”œβ”€β”€ CustomUserDetails.java
β”‚   β”‚   β”‚               β”‚       └── CustomUserDetailsService.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               β”œβ”€β”€ service
β”‚   β”‚   β”‚               β”‚   β”œβ”€β”€ AuthService.java
β”‚   β”‚   β”‚               β”‚   └── EmailService.java
β”‚   β”‚   β”‚               β”‚
β”‚   β”‚   β”‚               └── util
β”‚   β”‚   β”‚
β”‚   β”‚   └── resources
β”‚   β”‚       β”œβ”€β”€ application.properties
β”‚   β”‚       β”œβ”€β”€ static
β”‚   β”‚       └── templates
β”‚   β”‚
β”‚   └── test
β”‚       └── java
β”‚           └── com
β”‚               └── rockrager
β”‚                   └── authentication
β”‚                       └── AuthenticationApplicationTests.java

Database Tables

  • users
  • refresh_tokens
  • email_verification_tokens
  • password_reset_tokens

Future Improvements

  • HTML email templates
  • OAuth login (Google / GitHub)
  • API rate limiting
  • Swagger API documentation
  • Deployment to cloud platforms

Author

Mohan Kumar

Backend Developer | Java | Spring Boot

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages