Skip to content

A Spring Boot project demonstrating One-Time Token (OTT) authentication, sending secure magic links via email for passwordless login.

Notifications You must be signed in to change notification settings

drissiOmar98/Spring-Security-One-Time-Token-Login

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Spring Security One-Time Token (OTT) Authentication

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.

πŸ“– Overview

This Spring Boot 3.x application showcases a modern approach to authentication by implementing magic links using Spring Security's OTT functionality.

Workflow:

  1. Users request a One-Time Token (OTT) by entering their username.
  2. The system generates a secure, unique token and sends it via email.
  3. Users click the magic link in the email to log in automatically without a password.
  4. 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.

πŸš€ Features

  • βœ‰οΈ 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

✨ Benefits of Using This Project

  • βœ… 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.

πŸ–₯ Pages / Flow

  1. Home Page (index.jte)

    • Welcome page for authenticated users.
  2. Magic Link Sent Page (sent.jte)

    • Confirmation page indicating that the One-Time Token email has been sent.
  3. Email Template (one_time_token_email.html)

    • Clean, modern HTML design for sending magic links via email.

βš™οΈ Project Requirements

  • Java 17 or higher
  • Spring Boot 3.5.x
  • Maven or Gradle build tool
  • Email service (MailDev for testing / SendGrid for production)

🧩 Dependencies

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

πŸ›‘οΈ Security Considerations

  • πŸ”‘ 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/sent and /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.

About

A Spring Boot project demonstrating One-Time Token (OTT) authentication, sending secure magic links via email for passwordless login.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published