Member-only story
Spring Boot passwordless login using OTT, along with custom UI.
4 min readJan 5, 2025
BASIC
Spring Boot 3.4.x had came up with best features overall, the most important one being passkeys(webauthn) while the other one is one time token aka OTT.
To enable the OTT in a spring boot secured app, one has to just add the following piece of code & that is it
// an in memory user details service, with a user - user and another = admin
@Bean
public UserDetailsService userDetailsService() {
var userDetailsService = new InMemoryUserDetailsManager();
String testPassword = "{noop}test";
userDetailsService.createUser(User.withUsername("user").password(testPassword).build());
userDetailsService.createUser(User.withUsername("admin").password(testPassword).build());
return userDetailsService;
}
// default config for the onetimepinlogin.
@Bean
@SneakyThrows
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
http.authorizeHttpRequests(ar -> {
ar.anyRequest().authenticated();
});
http.formLogin(Customizer.withDefaults());
http.logout(Customizer.withDefaults());
http.csrf(Customizer.withDefaults());
// if loaded by not providing a OneTimeTokenGenerationSuccessHandler, the below error shows up
// A OneTimeTokenGenerationSuccessHandler is required to enable oneTimeTokenLogin().
// Please provide it as a bean or…