Spring Security has a built-in filter and authentication provider to handle One-Time Token (OTT) validation.
- The user clicks on the magic link or enters the token manually.
- The request is sent to
/login/ott
with the token as a query parameter.
OneTimeTokenAuthenticationFilter
(part of Spring Security) intercepts the request.- It extracts the token value from the request (
token=XYZ
).
- Spring Security delegates the token to
OneTimeTokenAuthenticationProvider
.
β Checks if the token exists in the database or token storage.
β Validates token expiry (time-limited).
β Verifies token association with the correct user.
β
If valid β Spring Security authenticates the user and starts a session.
β If invalid/expired β Returns an authentication error (401 Unauthorized).
This structure makes it clear, professional, and easy to read for GitHub users. Let me know if you need any changes! π