Class: Lita::RedisTokenStore
- Inherits:
-
Object
- Object
- Lita::RedisTokenStore
- Defined in:
- lib/lita/redis_token_store.rb
Overview
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.
Constant Summary collapse
- KEY_PREFIX =
'g-user-token:'
Instance Method Summary collapse
- #delete(id) ⇒ Object
-
#initialize(redis) ⇒ RedisTokenStore
constructor
Create a new store with the supplied redis client.
- #load(id) ⇒ Object
- #store(id, token) ⇒ Object
Constructor Details
#initialize(redis) ⇒ RedisTokenStore
Create a new store with the supplied redis client.
21 22 23 |
# File 'lib/lita/redis_token_store.rb', line 21 def initialize(redis) @redis = redis end |
Instance Method Details
#delete(id) ⇒ Object
35 36 37 38 |
# File 'lib/lita/redis_token_store.rb', line 35 def delete(id) key = key_for(id) @redis.del(key) end |
#load(id) ⇒ Object
25 26 27 28 |
# File 'lib/lita/redis_token_store.rb', line 25 def load(id) key = key_for(id) @redis.get(key) end |
#store(id, token) ⇒ Object
30 31 32 33 |
# File 'lib/lita/redis_token_store.rb', line 30 def store(id, token) key = key_for(id) @redis.set(key, token) end |