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
62 63 64 65 |
# File 'lib/openid_couchdb_store.rb', line 62 def initialize(couch_database) association.use_database(couch_database) nonce.use_database(couch_database) end |
Instance Method Details
#association ⇒ Object
67 68 69 |
# File 'lib/openid_couchdb_store.rb', line 67 def association OpenidCouchdbStore::Association end |
#cleanup_associations ⇒ Object
135 136 137 138 |
# File 'lib/openid_couchdb_store.rb', line 135 def cleanup_associations now = Time.now.to_i Association.expired.each {|a| a.destroy } end |
#cleanup_nonces ⇒ Object
131 132 133 |
# File 'lib/openid_couchdb_store.rb', line 131 def cleanup_nonces nonce.expired.each {|n| n.destroy } end |
#get_association(server_url, handle = nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/openid_couchdb_store.rb', line 93 def get_association(server_url, handle=nil) assoc_records = if (handle.nil? or handle.empty?) Association.by_server_url(:key => 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
71 72 73 |
# File 'lib/openid_couchdb_store.rb', line 71 def nonce OpenidCouchdbStore::Nonce end |
#remove_association(server_url, handle) ⇒ Object
118 119 120 121 122 |
# File 'lib/openid_couchdb_store.rb', line 118 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/openid_couchdb_store.rb', line 75 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
124 125 126 127 128 129 |
# File 'lib/openid_couchdb_store.rb', line 124 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 |