class Lita::RedisTokenStore
This is a local, simplified copy of Google::Auth::Stores::RedisTokenStore.
After a user authenticates via Google OAuth we need to store a copy of their tokens in redis so we can call the Google APIs on their behalf. The googleauth library can store the tokens using any class that conforms to the Google::Auth::TokenStore contract.
The RedisTokenStore
provided by the googleauth gem works well enough, but it assumes that the provided redis object is a plain Redis instance. Lita
wraps the Redis instance in a Redis::Namespace, so we need this custom store implementation.
A nice side-effect is that we can rely on the Redis::Namespace instance to prefix keys for us which removes some complexity from the class.
Constants
- KEY_PREFIX
Public Class Methods
Create a new store with the supplied redis client.
# File lib/lita/redis_token_store.rb, line 21 def initialize(redis) @redis = redis end
Public Instance Methods
# File lib/lita/redis_token_store.rb, line 35 def delete(id) key = key_for(id) @redis.del(key) end
# File lib/lita/redis_token_store.rb, line 25 def load(id) key = key_for(id) @redis.get(key) end
# File lib/lita/redis_token_store.rb, line 30 def store(id, token) key = key_for(id) @redis.set(key, token) end
Private Instance Methods
Generate a redis key from a token ID
# File lib/lita/redis_token_store.rb, line 44 def key_for(id) KEY_PREFIX + id end