Class: OpenidCouchdbStore::Store
- Inherits:
-
OpenID::Store::Interface
- Object
- OpenID::Store::Interface
- OpenidCouchdbStore::Store
- Defined in:
- lib/openid_couchdb_store.rb
Instance Method Summary collapse
- #association ⇒ Object
- #cleanup_associations ⇒ Object
- #cleanup_nonces ⇒ Object
- #get_association(server_url, handle = nil) ⇒ Object
-
#initialize(couch_database) ⇒ Store
constructor
A new instance of Store.
- #nonce ⇒ Object
- #remove_association(server_url, handle) ⇒ Object
- #store_association(server_url, association) ⇒ Object
- #use_nonce(server_url, timestamp, salt) ⇒ Object
Constructor Details
#initialize(couch_database) ⇒ Store
Returns a new instance of Store.
61 62 63 64 |
# File 'lib/openid_couchdb_store.rb', line 61 def initialize(couch_database) association.use_database(couch_database) nonce.use_database(couch_database) end |
Instance Method Details
#association ⇒ Object
66 67 68 |
# File 'lib/openid_couchdb_store.rb', line 66 def association OpenidCouchdbStore::Association end |
#cleanup_associations ⇒ Object
134 135 136 137 |
# File 'lib/openid_couchdb_store.rb', line 134 def cleanup_associations now = Time.now.to_i Association.expired.each {|a| a.destroy } end |
#cleanup_nonces ⇒ Object
130 131 132 |
# File 'lib/openid_couchdb_store.rb', line 130 def cleanup_nonces nonce.expired.each {|n| n.destroy } end |
#get_association(server_url, handle = nil) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/openid_couchdb_store.rb', line 92 def get_association(server_url, handle=nil) assoc_records = if (handle.nil? or handle.empty?) Association.by_server_url(server_url) else Association.by_server_url_and_handle(server_url,handle) end # TODO: Removed .reverse here, make sure that was reasonable. assoc_records.each do |a| openid_association = OpenID::Association.new(a['handle'], OpenID::Util.from_base64(a['secret']), a['issued'], a['lifetime'], a['assoc_type']) if openid_association.expires_in == 0 a.destroy else return openid_association end end if assoc_records.any? # <- may not be needed # Fail if there isn't an acceptable association return nil end |
#nonce ⇒ Object
70 71 72 |
# File 'lib/openid_couchdb_store.rb', line 70 def nonce OpenidCouchdbStore::Nonce end |
#remove_association(server_url, handle) ⇒ Object
117 118 119 120 121 |
# File 'lib/openid_couchdb_store.rb', line 117 def remove_association(server_url, handle) Association.by_server_url_and_handle(server_url,handle).each do |association| association.destroy end end |
#store_association(server_url, association) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/openid_couchdb_store.rb', line 74 def store_association(server_url, association) remove_association(server_url, association.handle) issued = if association.issued.to_s =~ /\A\d+\Z/ association.issued else Time.parse(association.issued.to_s).to_i end assoc = OpenidCouchdbStore::Association.create('server_url' => server_url, 'handle' => association.handle, 'secret' => OpenID::Util.to_base64(association.secret), 'issued' => issued, 'lifetime' => association.lifetime, 'assoc_type' => association.assoc_type) assoc end |
#use_nonce(server_url, timestamp, salt) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/openid_couchdb_store.rb', line 123 def use_nonce(server_url, , salt) return false if Nonce.first_nonce(server_url, ,salt) return false if ( - Time.now.to_i).abs > OpenID::Nonce.skew Nonce.create({'server_url' => server_url, 'timestamp' => , 'salt' => salt}) return true end |