Allow multiple token lifetimes
vcavallo opened this issue · comments
knock/app/model/knock/auth_token.rb
Line 55 in 66b6043
As mentioned here #233 it could be useful to have different token lifetimes for different use cases in the same application.
I'm thinking that this config option could (optionally) be a hash of various time values, keyed to whatever makes sense for the business logic of the given application. I've only poked around the source code a little, but it seems like the change is relatively straightforward.
If I have time, I'll make a pull request. Opening this partially as a gauge of interest in the feature.
This would be a good feature as a simple use case would be setting a very short token lifetime for an administrator in comparison to a normal application user.
Knock.token_lifetime = 7.days
Knock.token_lifetime = {
admin: 1.hour,
user: 1.day
}
...would be a good interface in the initializer
, just set the key to the entity_name
. If it is not a Hash
, then just default back to the current setting.
def token_lifetime
if Knock.token_lifetime.is_a?(Hash)
Knock.token_lifetime[entity_class.to_s.parameterize.underscore.to_sym].from_now.to_i if verify_lifetime?
else
Knock.token_lifetime.from_now.to_i if verify_lifetime?
end
end
I'm assigning @renatamarques97 to handle this 👍
can I take this?