openid_mongodb_store 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,35 +1,14 @@
1
1
  = Openid MongoDB Store
2
2
 
3
- OpenID requires some form of storage for its various cryptographic nuts and bolts. This project lets you use MongoDB (through MongoMapper) for that storage. This was pretty much copied from the ActiveRecord adaptor.
3
+ OpenID requires some form of storage for its various cryptographic nuts and bolts. This project lets you use MongoDB (through the Mongo Ruby library) for that storage. This was pretty largely taken from the ActiveRecord adaptor.
4
4
 
5
5
  == Install
6
6
 
7
7
  gem install openid_mongodb_store
8
8
 
9
- Will inherit whatever MongoMapper settings already exist. If you are using localhost and no username or password, only the database name is required:
10
- require 'mongomapper'
11
- MongoMapper.database = 'my_db_name'
12
-
13
- For MongoHQ and other hosts you may need:
14
- require 'mongomapper'
15
- MongoMapper.connection = Mongo::Connection.new('hostname')
16
- MongoMapper.database = 'my_db_name'
17
- MongoMapper.database.authenticate('username','password')
18
-
19
- == Future plans
20
- * Get MongoMapper out of the picture, interact directly with the MongoDB gem.
21
-
22
-
23
- == Note on Patches/Pull Requests
24
-
25
- * Fork the project.
26
- * Make your feature addition or bug fix.
27
- * Add tests for it. This is important so I don't break it in a
28
- future version unintentionally.
29
- * Commit, do not mess with rakefile, version, or history.
30
- (if you want to have your own version, that is fine but
31
- bump version in a commit by itself I can ignore when I pull)
32
- * Send me a pull request. Bonus points for topic branches.
9
+ db = Mongo::Connection.new('localhost').db('testorama')
10
+ db.authenticate('foo','bar')
11
+ OpenidMongodbStore::Store.new(db)
33
12
 
34
13
  == Copyright
35
14
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
data/config.ru ADDED
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'rack'
3
+ require 'rack/openid'
4
+ require 'easy_rack_open_id'
5
+ require 'lib/openid_mongodb_store'
6
+ require 'ruby-debug'
7
+
8
+ class HelloWorld
9
+ def call(env)
10
+ [200, {"Content-Type" => "text/plain"}, ["Made it through!"]]
11
+ end
12
+ end
13
+
14
+
15
+
16
+ use Rack::Session::Cookie
17
+ use Rack::OpenID, OpenidMongodbStore::Store.new(Mongo::Connection.new.db('testorama'))
18
+ use EasyRackOpenID, :allowed_identifiers => ['http://samsm.com/']
19
+
20
+ run HelloWorld.new
@@ -1,5 +1,5 @@
1
- require File.dirname(__FILE__) + '/nonce'
2
- require File.dirname(__FILE__) + '/association'
1
+ # require File.dirname(__FILE__) + '/nonce'
2
+ # require File.dirname(__FILE__) + '/association'
3
3
 
4
4
  # Again, from the OpenID gem
5
5
  require 'openid/store/interface'
@@ -7,58 +7,79 @@ require 'openid/store/interface'
7
7
 
8
8
  class OpenidMongodbStore::Store < OpenID::Store::Interface
9
9
  include OpenidMongodbStore
10
+
11
+ def initialize(db = nil)
12
+ OpenidMongodbStore.database = db
13
+ end
14
+
15
+ def associations
16
+ @@associations ||= OpenidMongodbStore.database.collection('openid_mongo_store_associations')
17
+ end
18
+
19
+ def nonces
20
+ @@nonces ||= OpenidMongodbStore.database.collection('openid_mongo_store_nonces')
21
+ end
22
+
10
23
  def store_association(server_url, association)
11
24
  remove_association(server_url, association.handle)
12
- Association.create(:server_url => server_url,
13
- :handle => association.handle,
14
- :secret => association.secret,
15
- :issued => association.issued,
16
- :lifetime => association.lifetime,
17
- :assoc_type => association.assoc_type)
25
+ associations.insert(:server_url => server_url,
26
+ :handle => association.handle,
27
+ :secret => association.secret,
28
+ :issued => association.issued,
29
+ :lifetime => association.lifetime,
30
+ :assoc_type => association.assoc_type)
18
31
  end
19
32
 
20
33
  def get_association(server_url, handle=nil)
21
- assocs = if handle.blank?
22
- Association.all(:conditions => {:server_url => server_url})
34
+ assocs = if (handle.nil? or handle.empty?)
35
+ associations.find({'server_url' => server_url})
23
36
  else
24
- Association.all(:conditions => {:server_url => server_url, :handle => handle})
37
+ associations.find({'server_url' => server_url, 'handle' => handle})
25
38
  end
39
+
40
+ assoc_records = assocs.collect {|a| a }
26
41
 
27
- assocs.reverse.each do |assoc|
28
- a = assoc.from_record
29
- if a.expires_in == 0
30
- assoc.destroy
42
+ # TODO: Removed .reverse here, make sure that was reasonable.
43
+ assoc_records.each do |a|
44
+ openid_association = OpenID::Association.new(a['handle'],
45
+ a['secret'],
46
+ a['issued'],
47
+ a['lifetime'],
48
+ a['assoc_type'])
49
+ if openid_association.expires_in == 0
50
+ associations.remove({'_id' => a['_id']})
31
51
  else
32
- return a
52
+ return openid_association
33
53
  end
34
- end if assocs.any? # <- may not be needed
54
+ end if assoc_records.any? # <- may not be needed
35
55
 
36
56
  # Fail if there isn't an acceptable association
37
57
  return nil
38
58
  end
39
59
 
40
60
  def remove_association(server_url, handle)
41
- Association.delete_all(:server_url => server_url, :handle => handle)
61
+ associations.remove({'server_url'=> server_url, 'handle' => handle})
42
62
  end
43
63
 
44
64
  def use_nonce(server_url, timestamp, salt)
45
- return false if Nonce.first(:conditions => {:server_url=>server_url,
46
- :timestamp => timestamp,
47
- :salt => salt})
65
+ return false if nonces.find_one({'server_url'=> server_url,
66
+ 'timestamp' => timestamp,
67
+ 'salt' => salt})
48
68
  return false if (timestamp - Time.now.to_i).abs > OpenID::Nonce.skew
49
- Nonce.create(:server_url => server_url, :timestamp => timestamp, :salt => salt)
69
+ nonces.insert({'server_url' => server_url, 'timestamp' => timestamp, 'salt' => salt})
50
70
  return true
51
71
  end
52
72
 
53
73
  def cleanup_nonces
54
74
  now = Time.now.to_i
55
- Nonce.delete_all({:timestamp => {'$gt'=> (now + OpenID::Nonce.skew),
56
- '$lt'=> (now - OpenID::Nonce.skew)}})
75
+ nonces.remove({'timestamp' => {'$gt'=> (now + OpenID::Nonce.skew),
76
+ '$lt'=> (now - OpenID::Nonce.skew)}})
57
77
  end
58
78
 
59
79
  def cleanup_associations
60
80
  now = Time.now.to_i
61
- Association.delete_all(:expire_at => {'$gt' => now})
81
+ # Association.delete_all(:expire_at => {'$gt' => now})
82
+ associations.remove('expire_at' => {'$gt' => now})
62
83
  end
63
84
 
64
85
  end
@@ -1,7 +1,16 @@
1
1
  require 'openid'
2
- require 'mongomapper'
2
+ require 'mongo'
3
3
 
4
4
  module OpenidMongodbStore
5
+ @@database = nil
6
+ def self.database=(db)
7
+ @@database = db
8
+ end
9
+
10
+ def self.database
11
+ @@database
12
+ end
13
+
5
14
  end
6
15
 
7
16
  require File.dirname(__FILE__) + '/openid_mongodb_store/store'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openid_mongodb_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Schenkman-Moore
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-18 00:00:00 -05:00
12
+ date: 2009-12-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,9 +38,8 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION
41
+ - config.ru
41
42
  - lib/openid_mongodb_store.rb
42
- - lib/openid_mongodb_store/association.rb
43
- - lib/openid_mongodb_store/nonce.rb
44
43
  - lib/openid_mongodb_store/store.rb
45
44
  - test/helper.rb
46
45
  - test/test_openid_mongodb_store.rb
@@ -1,17 +0,0 @@
1
- class OpenidMongodbStore::Association
2
- include MongoMapper::Document
3
-
4
- before_save :compute_expire_at
5
-
6
- key :expire_at, Integer
7
-
8
- def from_record
9
- OpenID::Association.new(handle, secret, issued, lifetime, assoc_type)
10
- end
11
-
12
- protected
13
- def compute_expire_at
14
- self.expire_at = issued + lifetime
15
- end
16
-
17
- end
@@ -1,3 +0,0 @@
1
- class OpenidMongodbStore::Nonce
2
- include MongoMapper::Document
3
- end