Skip to content

Customize OneTimeToken expire time #16291

Closed
@R4N

Description

@R4N

Expected Behavior

To be able to utilize the default JdbcOneTimeTokenService and set a custom expire time for the OneTImeToken within the generate method.

Current Behavior

OneTimeToken expire time is hard coded to 5 minutes in the JdbcOneTimeTokenService and InMemoryOneTimeTokenService.

Context

We've started implementing OneTimeTokenLogin after its recent inclusion in Spring Security and appreciate this great feature addition.

During testing, the default expiration time (5 minutes) seems to be sufficient. As we move towards production usage we've started considering more scenarios which we think may warrant increasing it: delayed mail delivery, user doesn't check the email right away, etc. Because of this, we're planning on increasing the expiration time slightly (to 10 or 15 minutes).

We've switched over to using JdbcOneTimeTokenService for production, but when looking for a spot to modify the expiration time, we saw that there wasn't an option present to do so.

After consulting the documentation, there is mention of modifying the one-time token expire time by creating a Custom OneTimeTokenService.

A full custom implementation to only override the expire time is potentially risky as it requires implementing/duplicating the majority of the logic (in JdbcOneTimeTokenService) which doesn't need to change in order to fulfill this type of behavior.

Implementation Ideas

Overloaded Constructors for OneTimeTokenService(s)

PR details here: #16260

  1. Add OneTimeTokenSettings class which has a property for OneTimeToken timeToLive Duration (default to 5 minutes)
  2. Pass OneTimeTokenSettings into overloaded JdbcOneTimeTokenService/InMemoryTokenService constructors
  3. Utilize clock.now() + timeToLive Duration for expire time in generate methods of OneTimeTokenServices.

Set in project's application.properties

Property for OneTimeToken timeToLive Duration fetched from application.properties and utilized in OneTimeTokenServices generate method (defaults to 5m if not set).

Switch JdbcOneTimeTokenService's insertOneTimeToken(OneTimeToken) to protected

This would allow subclassing of JdbcOneTimeTokenService and specifying the CustomOneTImeTokenService as a bean and overriding the generate method within CustomOneTimeTokenService to specify the expire time then calling super.insertOneTimeToken(OneTimeToken)

Specify OneTimeTokenSettings in OneTimeTokenLoginConfigurer

OneTimeTokenService would need some way of fetching the setting for timeToLive duration from OneTimeTokenSettings specified to the OneTimeTokenLoginConfigurer.

Metadata

Metadata

Assignees

Labels

in: webAn issue in web modules (web, webmvc)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions