Knock: Allow multiple token lifetimes

Created on 25 Jul 2019  ·  5Comments  ·  Source: nsarno/knock

https://github.com/nsarno/knock/blob/66b60437a5acc28e4863f011ab59324dc1b5d0ae/app/model/knock/auth_token.rb#L55

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.

Most helpful comment

can I take this?

All 5 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

psantos10 picture psantos10  ·  3Comments

rayway30419 picture rayway30419  ·  5Comments

YMonnier picture YMonnier  ·  3Comments

Jcambass picture Jcambass  ·  5Comments

saroar picture saroar  ·  3Comments