Enhance your application's security with passwordless authentication using Spring Security's One-Time Token (OTT) feature. This project demonstrates magic link authentication, allowing users to securely log in through email-delivered tokens without using a password.
This Spring Boot 3.x application showcases a modern approach to authentication by implementing magic links using Spring Security's OTT functionality.
Workflow:
- Users request a One-Time Token (OTT) by entering their username.
- The system generates a secure, unique token and sends it via email.
- Users click the magic link in the email to log in automatically without a password.
- Users are redirected to a confirmation page or the protected home page upon successful login.
This approach improves security and user experience, eliminating the need for passwords while ensuring safe access.
- βοΈ Email-based One-Time Token Login
- π Passwordless Authentication β secure login without passwords
- π§ Dynamic Email Templates β modern HTML email with magic link
- π Easy Test Setup β InMemoryUserDetailsManager for quick testing
- π Custom OTT Success Handler β redirects after email delivery
- β Passwordless Authentication β Users can log in securely via a one-time token sent to their email, eliminating the need for traditional passwords.
- β Enhanced Security β Reduces the risk of stolen or reused credentials by using time-limited, single-use tokens.
- β Modern Spring Security Integration β Demonstrates how to configure Spring Security for OTT/magic link login flows.
- β Email-Driven Login Flow β Shows practical use of JavaMailSender and template engines (JTE/Thymeleaf) for sending magic links.
- β Production-Ready Reference β Can serve as a blueprint for implementing passwordless authentication in real-world applications.
- β Clean & Maintainable Codebase β Uses best practices with Spring Boot, Lombok, and modular architecture for easy extension.
- β Improved User Experience β Simplifies login for users by removing password management while maintaining strong authentication standards.
-
Home Page (
index.jte)- Welcome page for authenticated users.
-
Magic Link Sent Page (
sent.jte)- Confirmation page indicating that the One-Time Token email has been sent.
-
Email Template (
one_time_token_email.html)- Clean, modern HTML design for sending magic links via email.
- Java 17 or higher
- Spring Boot 3.5.x
- Maven or Gradle build tool
- Email service (MailDev for testing / SendGrid for production)
Key dependencies used in this project:
- Spring Boot Starter Web β for building web applications
- Spring Boot Starter Security β handles OTT login flow
- JavaMailSender / Spring Boot Starter Mail β for email delivery
- JTE (Java Template Engine) β renders HTML email templates
- Spring Boot Docker Compose β running local containers for testing (e.g., MailDev)
- Lombok β reduces boilerplate code
- Spring Boot DevTools β for hot reloading during development
- Spring Boot Actuator β monitoring and application metrics
- π Single-Use, Time-Limited Tokens β Each one-time token (OTT) can only be used once and expires after a short period to prevent replay attacks.
- π Endpoint Protection β All endpoints, except
/ott/sentand/login/ott, require authentication to access. - π οΈ Secure Password Storage β Passwords are stored securely using Spring Security's password encoding mechanisms.
- π§ Email Delivery β Emails containing magic links are sent via MailDev for testing purposes.