As mentioned here https://github.com/nsarno/knock/issues/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.
that’s exactly what I want to do, @diakonvm
On Mon, Aug 12, 2019 at 12:19 AM diakonovm notifications@github.com wrote:
This would be a good feature as a simple use case would be setting a very
short administrator token lifetime in comparison to a normal application
user.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/nsarno/knock/issues/241?email_source=notifications&email_token=AAYNQ3YFJRBNJEYNHEJP6NDQEDQGHA5CNFSM4IG4Z7IKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4BRFBQ#issuecomment-520295046,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAYNQ32ALMI6GWVVSOQTWJTQEDQGHANCNFSM4IG4Z7IA
.>
Sent from a phone
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.
```ruby
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
@nsarno
I'm assigning @renatamarques97 to handle this 👍
can I take this?
Most helpful comment
can I take this?