Class: Masq::ActiveRecordStore
- Inherits:
-
OpenID::Store::Interface
- Object
- OpenID::Store::Interface
- Masq::ActiveRecordStore
- Defined in:
- lib/masq/active_record_openid_store/openid_ar_store.rb
Overview
not in OpenID module to avoid namespace conflict
Instance Method Summary collapse
- #cleanup_associations ⇒ Object
- #cleanup_nonces ⇒ Object
- #get_association(server_url, handle = nil) ⇒ Object
- #remove_association(server_url, handle) ⇒ Object
- #store_association(server_url, assoc) ⇒ Object
- #use_nonce(server_url, timestamp, salt) ⇒ Object
Instance Method Details
#cleanup_associations ⇒ Object
53 54 55 56 |
# File 'lib/masq/active_record_openid_store/openid_ar_store.rb', line 53 def cleanup_associations now = Time.now.to_i Association.where("issued + lifetime > ?", now).delete_all end |
#cleanup_nonces ⇒ Object
48 49 50 51 |
# File 'lib/masq/active_record_openid_store/openid_ar_store.rb', line 48 def cleanup_nonces now = Time.now.to_i Nonce.where("timestamp > ? OR timestamp < ?", now + OpenID::Nonce.skew, now - OpenID::Nonce.skew).delete_all end |
#get_association(server_url, handle = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/masq/active_record_openid_store/openid_ar_store.rb', line 18 def get_association(server_url, handle = nil) assocs = if handle.blank? Association.where(server_url: server_url) else Association.where(server_url: server_url, handle: handle) end assocs.reverse_each do |assoc| a = assoc.from_record if a.expires_in == 0 assoc.destroy else return a end end if assocs.any? nil end |
#remove_association(server_url, handle) ⇒ Object
37 38 39 |
# File 'lib/masq/active_record_openid_store/openid_ar_store.rb', line 37 def remove_association(server_url, handle) Association.where("server_url = ? AND handle = ?", server_url, handle).delete_all > 0 end |
#store_association(server_url, assoc) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/masq/active_record_openid_store/openid_ar_store.rb', line 6 def store_association(server_url, assoc) remove_association(server_url, assoc.handle) Association.create( server_url: server_url, handle: assoc.handle, secret: assoc.secret, issued: assoc.issued, lifetime: assoc.lifetime, assoc_type: assoc.assoc_type, ) end |
#use_nonce(server_url, timestamp, salt) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/masq/active_record_openid_store/openid_ar_store.rb', line 41 def use_nonce(server_url, , salt) return false if Nonce.find_by(server_url: server_url, timestamp: , salt: salt) return false if ( - Time.now.to_i).abs > OpenID::Nonce.skew Nonce.create(server_url: server_url, timestamp: , salt: salt) true end |