openid_dm_store 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Jed Hurt
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 ADDED
@@ -0,0 +1,48 @@
1
+ =DataMapper OpenID Store
2
+
3
+ (Ported from Dag Arneson's active_record_openid_store plugin)
4
+
5
+ A store is required by an OpenID server and optionally by the consumer
6
+ to store associations, nonces, and auth key information across
7
+ requests and processes. If an application is distributed across several
8
+ machines, they must must all have access to the same OpenID store
9
+ data, so the FilesystemStore won't do.
10
+
11
+ This gem enables an app to use a database backed OpenID store
12
+ through DataMapper.
13
+
14
+ ==Install
15
+
16
+ 1) Install the gem:
17
+
18
+ gem install meekish-openid_dm_store --source http://gems.github.com
19
+
20
+ 2) Require it in your app
21
+
22
+ require 'rubygems'
23
+ require 'openid_dm_store'
24
+
25
+ 3) Issue the commands (script/console, merb -i, etc.) to create the needed tables in your database:
26
+
27
+ OpenIDDataMapper::Association.auto_migrate!
28
+ OpenIDDataMapper::Nonce.auto_migrate!
29
+
30
+ 4) Change your app to use the OpenIDDataMapper Store:
31
+
32
+ store = OpenIDDataMapper::DataMapperStore.new
33
+ consumer = OpenID::Consumer.new(session, store)
34
+
35
+ 5) That's it! All your OpenID state will now be stored in the database.
36
+
37
+ ==What about garbage collection?
38
+
39
+ You may garbage collect unused nonces and expired associations using the cleanup
40
+ instance method of OpenIDDataMapper::DataMapperStore.
41
+
42
+ OpenIDDataMapper::DataMapperStore.new.cleanup
43
+
44
+ Throw that into a rake task and add it to your crontab and you're all set.
45
+
46
+ ==Questions?
47
+
48
+ Contact Jed Hurt: jed dot hurt at gmail dot com
@@ -0,0 +1,25 @@
1
+ require 'openid/association'
2
+
3
+ module OpenIDDataMapper
4
+
5
+ class Association
6
+ include DataMapper::Resource
7
+
8
+ property :id, Serial
9
+ property :handle, String
10
+ property :secret, Object # TODO: replace with Blob
11
+ property :issued, Integer
12
+ property :lifetime, Integer
13
+ property :assoc_type, String
14
+ property :server_url, Object # TODO: replace with Blob
15
+
16
+ def self.default_storage_name
17
+ "OpenIdAssociation"
18
+ end
19
+
20
+ def from_record
21
+ OpenID::Association.new(handle, secret, issued, lifetime, assoc_type)
22
+ end
23
+ end
24
+
25
+ end
data/lib/nonce.rb ADDED
@@ -0,0 +1,17 @@
1
+ module OpenIDDataMapper
2
+
3
+ class Nonce
4
+ include DataMapper::Resource
5
+
6
+ property :id, Serial
7
+ property :salt, String, :nullable => false
8
+ property :server_url, String, :nullable => false
9
+ property :timestamp, Integer, :nullable => false
10
+
11
+ def self.default_storage_name
12
+ "OpenIdNonce"
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,68 @@
1
+ require 'association'
2
+ require 'nonce'
3
+ require 'openid/store/interface'
4
+
5
+ module OpenIDDataMapper
6
+
7
+ class DataMapperStore < OpenID::Store::Interface
8
+ def store_association(server_url, assoc)
9
+ remove_association(server_url, assoc.handle)
10
+ Association.create(:server_url => server_url,
11
+ :handle => assoc.handle,
12
+ :secret => assoc.secret,
13
+ :issued => assoc.issued,
14
+ :lifetime => assoc.lifetime,
15
+ :assoc_type => assoc.assoc_type)
16
+ end
17
+
18
+ def get_association(server_url, handle=nil)
19
+ assocs = if handle.blank?
20
+ # Association.find_all_by_server_url(server_url)
21
+ Association.all(:server_url => server_url)
22
+ else
23
+ # Association.find_all_by_server_url_and_handle(server_url, handle)
24
+ Association.all(:server_url => server_url, :handle => handle)
25
+ end
26
+
27
+ # assocs.reverse.each do |assoc|
28
+ assocs.to_a.reverse.each do |assoc|
29
+ a = assoc.from_record
30
+ if a.expires_in == 0
31
+ # assoc.destroy
32
+ assoc.destroy
33
+ else
34
+ return a
35
+ end
36
+ end if assocs.any?
37
+
38
+ return nil
39
+ end
40
+
41
+ def remove_association(server_url, handle)
42
+ # Association.delete_all(['server_url = ? AND handle = ?', server_url, handle]) > 0
43
+ Association.all(:server_url => server_url, :handle => handle).destroy
44
+ end
45
+
46
+ def use_nonce(server_url, timestamp, salt)
47
+ # return false if Nonce.find_by_server_url_and_timestamp_and_salt(server_url, timestamp, salt)
48
+ return false if Nonce.first(:server_url => server_url, :timestamp => timestamp, :salt => salt)
49
+ return false if (timestamp - Time.now.to_i).abs > OpenID::Nonce.skew
50
+ Nonce.create(:server_url => server_url, :timestamp => timestamp, :salt => salt)
51
+ return true
52
+ end
53
+
54
+ def cleanup_nonces
55
+ now = Time.now.to_i
56
+ # Nonce.delete_all(["timestamp > ? OR timestamp < ?", now + OpenID::Nonce.skew, now - OpenID::Nonce.skew])
57
+ Nonce.all(:conditions => ["timestamp > ? OR timestamp < ?", now + OpenID::Nonce.skew, now - OpenID::Nonce.skew]).destroy
58
+ end
59
+
60
+ def cleanup_associations
61
+ now = Time.now.to_i
62
+ # Association.delete_all(['issued + lifetime > ?',now])
63
+ Association.all(:conditions => ['issued + lifetime > ?', now]).destroy
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'openid'
3
+ $:.unshift(File.dirname(__FILE__) + '/lib')
4
+ require 'lib/openid_dm_store'
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openid_dm_store
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Jed Hurt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-17 14:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-openid
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: dm-core
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Adds a DataMapper store to ruby-openid
36
+ email: jed.hurt@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - LICENSE
44
+ files:
45
+ - LICENSE
46
+ - README
47
+ - openid_dm_store.rb
48
+ - lib/association.rb
49
+ - lib/nonce.rb
50
+ - lib/openid_dm_store.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/meekish/openid_dm_store
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.8.4
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 2
78
+ summary: Adds a DataMapper store to ruby-openid
79
+ test_files: []
80
+