Class: OpenIdAuthentication::MemCacheStore
- Inherits:
-
OpenID::Store::Interface
- Object
- OpenID::Store::Interface
- OpenIdAuthentication::MemCacheStore
- Defined in:
- lib/plugins/open_id_authentication/lib/open_id_authentication/mem_cache_store.rb
Overview
Instance Method Summary collapse
- #get_association(server_url, handle = nil) ⇒ Object
-
#initialize(*addresses) ⇒ MemCacheStore
constructor
A new instance of MemCacheStore.
- #remove_association(server_url, handle) ⇒ Object
- #store_association(server_url, assoc) ⇒ Object
- #use_nonce(server_url, timestamp, salt) ⇒ Object
Constructor Details
#initialize(*addresses) ⇒ MemCacheStore
Returns a new instance of MemCacheStore
6 7 8 |
# File 'lib/plugins/open_id_authentication/lib/open_id_authentication/mem_cache_store.rb', line 6 def initialize(*addresses) @connection = ActiveSupport::Cache::MemCacheStore.new(addresses) end |
Instance Method Details
#get_association(server_url, handle = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/plugins/open_id_authentication/lib/open_id_authentication/mem_cache_store.rb', line 21 def get_association(server_url, handle = nil) if handle @connection.read(association_key(server_url, handle)) else server_key = association_server_key(server_url) assocs = @connection.read(server_key) return if assocs.nil? last_key = assocs[assocs.keys.sort.last] @connection.read(last_key) end end |
#remove_association(server_url, handle) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plugins/open_id_authentication/lib/open_id_authentication/mem_cache_store.rb', line 34 def remove_association(server_url, handle) server_key = association_server_key(server_url) assoc_key = association_key(server_url, handle) assocs = @connection.read(server_key) return false unless assocs && assocs.has_value?(assoc_key) assocs = assocs.delete_if { |key, value| value == assoc_key } @connection.write(server_key, assocs) @connection.delete(assoc_key) return true end |
#store_association(server_url, assoc) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/plugins/open_id_authentication/lib/open_id_authentication/mem_cache_store.rb', line 10 def store_association(server_url, assoc) server_key = association_server_key(server_url) assoc_key = association_key(server_url, assoc.handle) assocs = @connection.read(server_key) || {} assocs[assoc.issued] = assoc_key @connection.write(server_key, assocs) @connection.write(assoc_key, assoc, :expires_in => assoc.lifetime) end |
#use_nonce(server_url, timestamp, salt) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/plugins/open_id_authentication/lib/open_id_authentication/mem_cache_store.rb', line 49 def use_nonce(server_url, , salt) return false if @connection.read(nonce_key(server_url, salt)) return false if ( - Time.now.to_i).abs > OpenID::Nonce.skew @connection.write(nonce_key(server_url, salt), , :expires_in => OpenID::Nonce.skew) return true end |