Helps you manage all of those keys you're giving out.
- run
rails g hotel:install
- edit the file found at
config/initializers/hotel.rb
- add a
config/redis.yml
keyed with the application environment, these options will be piped directly toRedis.new
production:
...
development:
...
- u dun
Here are the basic methods you can call to perform various operations
Hotel.token.generate(your_custom_claim_hash)
Hotel.token.invalidate(some_token)
Hotel.token.refresh(token)
Hotel.token.validate(token)
Hotel.token.validate!(token)
Hotel.token.valid?(token)
JSON Web Tokens by nature cannot be invalidated, there are few methods for rotating out compromised ones such as
- shortening the time to expire
- storing a whitelist of issued tokens in your DDL
- tracking which tokens you've issued to who
So I made Hotel. The way we invalidate tokens is by storing a blacklist of compromised tokens in redis. Tokens only need to be stored until their expiry, after that they are, well, expired and no longer need to be tracked. Redis provides a nice feature called expire. So all we have to do is set the redis expiry for the record equal to the difference of the tokens expiry and the current time.
This approach provides for nice self cleaning records and doesn't require any change to your DDL.