class OpenID::Store::Redis
Attributes
prefix[R]
Public Class Methods
new(client = ::Redis.current, prefix = "openid-store")
click to toggle source
# File lib/openid/store/redis.rb, line 9 def initialize(client = ::Redis.current, prefix = "openid-store") @redis = client @prefix = prefix end
Public Instance Methods
cleanup()
click to toggle source
cleanup_associations()
click to toggle source
cleanup_nonces()
click to toggle source
get_association(server_url, handle=nil)
click to toggle source
Fetch and deserialize an Association object from Redis
# File lib/openid/store/redis.rb, line 24 def get_association(server_url, handle=nil) if serialized = @redis.get(assoc_key(server_url, handle)) deserialize(serialized) else nil end end
remove_association(url, handle)
click to toggle source
Remove matching association from Redis
return true when data is removed, otherwise false
# File lib/openid/store/redis.rb, line 35 def remove_association(url, handle) deleted = @redis.del(assoc_key(url, handle)) assoc = get_association(url) if assoc && assoc.handle == handle deleted + @redis.del(assoc_key(url)) else deleted end > 0 end
store_association(server_url, association)
click to toggle source
use_nonce(server_url, timestamp, salt)
click to toggle source
Use nonce and store that it has been used in Redis
temporarily
Returns true if nonce has not been used before and is still usable,
# File lib/openid/store/redis.rb, line 49 def use_nonce(server_url, timestamp, salt) return false if (timestamp - Time.now.to_i).abs > Nonce.skew ts = timestamp.to_s # base 10 seconds since epoch nonce_key = prefix + ':n:' + server_url + ':' + ts + ':' + salt if @redis.setnx(nonce_key, '') @redis.expire(nonce_key, Nonce.skew + 5) true else false end end
Private Instance Methods
assoc_key(server_url, assoc_handle=nil)
click to toggle source
# File lib/openid/store/redis.rb, line 90 def assoc_key(server_url, assoc_handle=nil) key = prefix + ':a:' + server_url if assoc_handle key + ':' + assoc_handle else key end end
deserialize(assoc_str)
click to toggle source
# File lib/openid/store/redis.rb, line 103 def deserialize(assoc_str) Marshal.load(assoc_str) end
remove_keys(pattern)
click to toggle source
# File lib/openid/store/redis.rb, line 84 def remove_keys(pattern) @redis.keys(prefix + pattern).each do |key| @redis.del(key) end end
serialize(assoc)
click to toggle source
# File lib/openid/store/redis.rb, line 99 def serialize(assoc) Marshal.dump(assoc) end