ruby-openid-store-mongo 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/openid/store/mongo.rb +109 -0
- data/ruby-openid-store-mongo.gemspec +23 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee6b1ca2f43441ff015d0bddf7571196e6dd19b2
|
4
|
+
data.tar.gz: b8ca9df83a1d5dbe46850109c9e5851160509764
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38d5910c627fb51674dfebfaee34cc4a3f43a84b38460a9b81dd662b2d4f646e2309654bda5b36a83c933fa300023161bfad9e3ed01a61235effc78557442b23
|
7
|
+
data.tar.gz: d2e807f02fd2ab0b0c4d6df081cb0ec2b989f0bf25924dfd729c325659ffb26435d7a74a40393189c8e5233239fc898391510f423c32824aa636960e66d39499
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kevin McGrath
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# OpenID::Store::Mongo
|
2
|
+
|
3
|
+
MongoDB store for ruby-openid
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ruby-openid-store-mongo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ruby-openid-store-mongo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Initialize the store with a Mongo collection. A TTL index will be created on the collection which will
|
22
|
+
automatically remove expired entries. This requires a Mongo instance of 2.2 or greater.
|
23
|
+
|
24
|
+
client = MongoClient.new('localhost', 27017)
|
25
|
+
db = client['sample-db']
|
26
|
+
coll = db['ruby_openid']
|
27
|
+
OpenID::Store::Mongo.new(:collection => coll)
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'pathname'
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
require 'openid/util'
|
8
|
+
require 'openid/store/interface'
|
9
|
+
require 'openid/association'
|
10
|
+
|
11
|
+
module OpenID
|
12
|
+
module Store
|
13
|
+
class Mongo < OpenID::Store::Interface
|
14
|
+
VERSION = "0.0.2"
|
15
|
+
|
16
|
+
attr_accessor :collection
|
17
|
+
|
18
|
+
def initialize(options = {})
|
19
|
+
self.collection = options[:collection]
|
20
|
+
self.collection.ensure_index('expiry',{ :expireAfterSeconds => 0 })
|
21
|
+
end
|
22
|
+
|
23
|
+
# Put a Association object into storage.
|
24
|
+
# When implementing a store, don't assume that there are any limitations
|
25
|
+
# on the character set of the server_url. In particular, expect to see
|
26
|
+
# unescaped non-url-safe characters in the server_url field.
|
27
|
+
def store_association(server_url, association)
|
28
|
+
[nil, association.handle].each do |handle|
|
29
|
+
key = assoc_key(server_url, handle)
|
30
|
+
collection.save({:_id => key, :value => association.serialize, :expiry => expiry(association.lifetime)})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns a Association object from storage that matches
|
35
|
+
# the server_url. Returns nil if no such association is found or if
|
36
|
+
# the one matching association is expired. (Is allowed to GC expired
|
37
|
+
# associations when found.)
|
38
|
+
def get_association(server_url, handle=nil)
|
39
|
+
doc = collection.find_one({:_id => assoc_key(server_url, handle)})
|
40
|
+
if doc
|
41
|
+
return OpenID::Association.deserialize(doc['value'])
|
42
|
+
else
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# If there is a matching association, remove it from the store and
|
48
|
+
# return true, otherwise return false.
|
49
|
+
def remove_association(server_url, handle)
|
50
|
+
deleted = delete(assoc_key(server_url, handle))
|
51
|
+
server_assoc = get_association(server_url)
|
52
|
+
if server_assoc && server_assoc.handle == handle
|
53
|
+
deleted = delete(assoc_key(server_url)) | deleted
|
54
|
+
end
|
55
|
+
return deleted
|
56
|
+
end
|
57
|
+
|
58
|
+
# Return true if the nonce has not been used before, and store it
|
59
|
+
# for a while to make sure someone doesn't try to use the same value
|
60
|
+
# again. Return false if the nonce has already been used or if the
|
61
|
+
# timestamp is not current.
|
62
|
+
# You can use OpenID::Store::Nonce::SKEW for your timestamp window.
|
63
|
+
# server_url: URL of the server from which the nonce originated
|
64
|
+
# timestamp: time the nonce was created in seconds since unix epoch
|
65
|
+
# salt: A random string that makes two nonces issued by a server in
|
66
|
+
# the same second unique
|
67
|
+
def use_nonce(server_url, timestamp, salt)
|
68
|
+
return false if (timestamp - Time.now.to_i).abs > Nonce.skew
|
69
|
+
ts = timestamp.to_s # base 10 seconds since epoch
|
70
|
+
nonce_key = 'N' + server_url + '|' + ts + '|' + salt
|
71
|
+
begin
|
72
|
+
result = collection.insert({:_id=>nonce_key, :expiry => expiry(Nonce.skew + 5)})
|
73
|
+
return true
|
74
|
+
rescue
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def assoc_key(server_url, assoc_handle=nil)
|
80
|
+
key = 'A' + server_url
|
81
|
+
if assoc_handle
|
82
|
+
key += '|' + assoc_handle
|
83
|
+
end
|
84
|
+
return key
|
85
|
+
end
|
86
|
+
|
87
|
+
def cleanup_nonces
|
88
|
+
end
|
89
|
+
|
90
|
+
def cleanup
|
91
|
+
end
|
92
|
+
|
93
|
+
def cleanup_associations
|
94
|
+
end
|
95
|
+
|
96
|
+
protected
|
97
|
+
|
98
|
+
def delete(key)
|
99
|
+
result = collection.remove({:_id => key})
|
100
|
+
end
|
101
|
+
|
102
|
+
# Convert a lifetime in seconds into a expiry value
|
103
|
+
def expiry(t)
|
104
|
+
Time.now + t
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ruby-openid-store-mongo"
|
7
|
+
spec.version = "0.0.3"
|
8
|
+
spec.authors = ["Kevin McGrath"]
|
9
|
+
spec.email = ["kevin.mcgrath@sungard.com"]
|
10
|
+
spec.description = %q{MongoDB store for ruby-openid}
|
11
|
+
spec.summary = %q{MongoDB store for ruby-openid}
|
12
|
+
spec.homepage = "https://github.com/kmcgrath/ruby-openid-store-mongo"
|
13
|
+
spec.licenses = ["Ruby", "Apache Software License 2.0"]
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_dependency "ruby-openid", ["~> 2.1"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-openid-store-mongo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin McGrath
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-openid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
description: MongoDB store for ruby-openid
|
56
|
+
email:
|
57
|
+
- kevin.mcgrath@sungard.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/openid/store/mongo.rb
|
68
|
+
- ruby-openid-store-mongo.gemspec
|
69
|
+
homepage: https://github.com/kmcgrath/ruby-openid-store-mongo
|
70
|
+
licenses:
|
71
|
+
- Ruby
|
72
|
+
- Apache Software License 2.0
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.0.rc.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: MongoDB store for ruby-openid
|
94
|
+
test_files: []
|