-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customize OneTimeToken expire time #16291
Comments
Thanks for the suggestion, @R4N, and for the earlier PR. One thing we might consider is adding @Bean
GenerateOneTimeTokenRequestResolver resolve() {
return (request) -> new GenerateOneTimeTokenRequest(...);
} Then, all services could be updated to look for an expiry in This follows a similar pattern when generating other request objects in Spring Security like This also makes it easier to delegate; something that is a little tricky with a service that persists: @Bean
GenerateOneTimeTokenRequestResolver resolve() {
DefaultGenerateOneTimeTokenRequestResolver delegate = new DefaultOneTimeTokenRequestResolver();
return (request) -> {
GenerateOneTimeTokenRequest generate = delegate.resolve(request);
return new GenerateOneTimeTokenRequest(generate.getUsername(), myExpiresIn());
}
} It also gives one place for setters, should we want to go that route to further simplify: DefaultGeneratorOneTimeTokenRequestResolver#setExpiresIn(Duration) So that every implementation of @franticticktick, I saw your comment on the PR. Please feel free to weigh in with your thoughts here. |
We have already discussed this possibility here. @marcusdacoregio suggested:
I think this is a good idea. |
@jzheaux this solution will not work. Don’t forget that we use an instance
This will lead to the fact that the time can be generated on one
|
Can you clarify for me why the following doesn't work? (pseudocode follows)
It seems that the service's clock would be used for both. What am I missing? |
I understand what you mean and as it stands, yes, this is a good solution. I considered the solution where the generation of |
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
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 callingsuper.insertOneTimeToken(OneTimeToken)
Specify OneTimeTokenSettings in OneTimeTokenLoginConfigurer
OneTimeTokenService would need some way of fetching the setting for timeToLive duration from OneTimeTokenSettings specified to the OneTimeTokenLoginConfigurer.
The text was updated successfully, but these errors were encountered: