openid_mongodb_store 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/openid_mongodb_store/association.rb +17 -0
- data/lib/openid_mongodb_store/nonce.rb +3 -0
- data/lib/openid_mongodb_store/store.rb +64 -0
- data/lib/openid_mongodb_store.rb +7 -0
- data/test/helper.rb +9 -0
- data/test/test_openid_mongodb_store.rb +7 -0
- metadata +77 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Sam Schenkman-Moore
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= Openid MongoDB Store
|
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.
|
4
|
+
|
5
|
+
Will inherit whatever MongoMapper settings already exist. If you are using localhost and no username or password, only the database name is required:
|
6
|
+
require 'mongomapper'
|
7
|
+
MongoMapper.database = 'my_db_name'
|
8
|
+
|
9
|
+
For MongoHQ and other hosts you may need:
|
10
|
+
require 'mongomapper'
|
11
|
+
MongoMapper.connection = Mongo::Connection.new('hostname')
|
12
|
+
MongoMapper.database = 'my_db_name'
|
13
|
+
MongoMapper.database.authenticate('username','password')
|
14
|
+
|
15
|
+
== Future plans
|
16
|
+
* Get MongoMapper out of the picture, interact directly with the MongoDB gem.
|
17
|
+
|
18
|
+
|
19
|
+
== Note on Patches/Pull Requests
|
20
|
+
|
21
|
+
* Fork the project.
|
22
|
+
* Make your feature addition or bug fix.
|
23
|
+
* Add tests for it. This is important so I don't break it in a
|
24
|
+
future version unintentionally.
|
25
|
+
* Commit, do not mess with rakefile, version, or history.
|
26
|
+
(if you want to have your own version, that is fine but
|
27
|
+
bump version in a commit by itself I can ignore when I pull)
|
28
|
+
* Send me a pull request. Bonus points for topic branches.
|
29
|
+
|
30
|
+
== Copyright
|
31
|
+
|
32
|
+
Copyright (c) 2009 Sam Schenkman-Moore. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "openid_mongodb_store"
|
8
|
+
gem.summary = "An adaptor for storing OpenID nonces and associations with MongoMapper"
|
9
|
+
gem.description = "Like the ActiveRecord Store, but for MongoMapper."
|
10
|
+
gem.email = "samsm@samsm.com"
|
11
|
+
gem.homepage = "http://github.com/samsm/openid_mongodb_store"
|
12
|
+
gem.authors = ["Sam Schenkman-Moore"]
|
13
|
+
gem.add_development_dependency "yard", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
begin
|
46
|
+
require 'yard'
|
47
|
+
YARD::Rake::YardocTask.new
|
48
|
+
rescue LoadError
|
49
|
+
task :yardoc do
|
50
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
51
|
+
end
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/nonce'
|
2
|
+
require File.dirname(__FILE__) + '/association'
|
3
|
+
|
4
|
+
# Again, from the OpenID gem
|
5
|
+
require 'openid/store/interface'
|
6
|
+
|
7
|
+
|
8
|
+
class OpenidMongodbStore::Store < OpenID::Store::Interface
|
9
|
+
include OpenidMongodbStore
|
10
|
+
def store_association(server_url, association)
|
11
|
+
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)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_association(server_url, handle=nil)
|
21
|
+
assocs = if handle.blank?
|
22
|
+
Association.all(:conditions => {:server_url => server_url})
|
23
|
+
else
|
24
|
+
Association.all(:conditions => {:server_url => server_url, :handle => handle})
|
25
|
+
end
|
26
|
+
|
27
|
+
assocs.reverse.each do |assoc|
|
28
|
+
a = assoc.from_record
|
29
|
+
if a.expires_in == 0
|
30
|
+
assoc.destroy
|
31
|
+
else
|
32
|
+
return a
|
33
|
+
end
|
34
|
+
end if assocs.any? # <- may not be needed
|
35
|
+
|
36
|
+
# Fail if there isn't an acceptable association
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_association(server_url, handle)
|
41
|
+
Association.delete_all(:server_url => server_url, :handle => handle)
|
42
|
+
end
|
43
|
+
|
44
|
+
def use_nonce(server_url, timestamp, salt)
|
45
|
+
return false if Nonce.first(:conditions => {:server_url=>server_url,
|
46
|
+
:timestamp => timestamp,
|
47
|
+
:salt => salt})
|
48
|
+
return false if (timestamp - Time.now.to_i).abs > OpenID::Nonce.skew
|
49
|
+
Nonce.create(:server_url => server_url, :timestamp => timestamp, :salt => salt)
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
def cleanup_nonces
|
54
|
+
now = Time.now.to_i
|
55
|
+
Nonce.delete_all({:timestamp => {'$gt'=> (now + OpenID::Nonce.skew),
|
56
|
+
'$lt'=> (now - OpenID::Nonce.skew)}})
|
57
|
+
end
|
58
|
+
|
59
|
+
def cleanup_associations
|
60
|
+
now = Time.now.to_i
|
61
|
+
Association.delete_all(:expire_at => {'$gt' => now})
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openid_mongodb_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Schenkman-Moore
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-18 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: yard
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: Like the ActiveRecord Store, but for MongoMapper.
|
26
|
+
email: samsm@samsm.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lib/openid_mongodb_store.rb
|
42
|
+
- lib/openid_mongodb_store/association.rb
|
43
|
+
- lib/openid_mongodb_store/nonce.rb
|
44
|
+
- lib/openid_mongodb_store/store.rb
|
45
|
+
- test/helper.rb
|
46
|
+
- test/test_openid_mongodb_store.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/samsm/openid_mongodb_store
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: An adaptor for storing OpenID nonces and associations with MongoMapper
|
75
|
+
test_files:
|
76
|
+
- test/helper.rb
|
77
|
+
- test/test_openid_mongodb_store.rb
|