exvo-auth 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +3 -1
- data/VERSION +1 -1
- data/exvo-auth.gemspec +12 -5
- data/lib/exvo-auth.rb +1 -0
- data/lib/exvo_auth/autonomous/base.rb +25 -0
- data/lib/exvo_auth/autonomous/cache.rb +14 -2
- data/lib/exvo_auth/autonomous/consumer.rb +4 -14
- data/lib/exvo_auth/autonomous/provider.rb +7 -15
- data/lib/exvo_auth/controllers/base.rb +4 -0
- data/lib/exvo_auth/controllers/merb.rb +4 -2
- data/lib/exvo_auth/controllers/rails.rb +4 -2
- data/test/helper.rb +2 -1
- data/test/test_exvo_auth.rb +21 -2
- metadata +33 -4
data/Rakefile
CHANGED
@@ -10,7 +10,9 @@ begin
|
|
10
10
|
gem.homepage = "http://github.com/Exvo/Auth"
|
11
11
|
gem.authors = ["Jacek Becela"]
|
12
12
|
gem.add_dependency "oa-oauth", "0.0.1"
|
13
|
-
gem.add_dependency "httparty", "0.6.1"
|
13
|
+
gem.add_dependency "httparty", ">= 0.6.1"
|
14
|
+
gem.add_development_dependency "mocha", ">= 0.9.8"
|
15
|
+
gem.add_development_dependency "test-unit", ">= 2.1.0"
|
14
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
17
|
end
|
16
18
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.2
|
data/exvo-auth.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{exvo-auth}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jacek Becela"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-20}
|
13
13
|
s.description = %q{Sign in with Exvo account}
|
14
14
|
s.email = %q{jacek.becela@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"exvo-auth.gemspec",
|
28
28
|
"lib/exvo-auth.rb",
|
29
|
+
"lib/exvo_auth/autonomous/base.rb",
|
29
30
|
"lib/exvo_auth/autonomous/cache.rb",
|
30
31
|
"lib/exvo_auth/autonomous/consumer.rb",
|
31
32
|
"lib/exvo_auth/autonomous/provider.rb",
|
@@ -56,14 +57,20 @@ Gem::Specification.new do |s|
|
|
56
57
|
|
57
58
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
58
59
|
s.add_runtime_dependency(%q<oa-oauth>, ["= 0.0.1"])
|
59
|
-
s.add_runtime_dependency(%q<httparty>, ["
|
60
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
61
|
+
s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
|
62
|
+
s.add_development_dependency(%q<test-unit>, [">= 2.1.0"])
|
60
63
|
else
|
61
64
|
s.add_dependency(%q<oa-oauth>, ["= 0.0.1"])
|
62
|
-
s.add_dependency(%q<httparty>, ["
|
65
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
66
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
67
|
+
s.add_dependency(%q<test-unit>, [">= 2.1.0"])
|
63
68
|
end
|
64
69
|
else
|
65
70
|
s.add_dependency(%q<oa-oauth>, ["= 0.0.1"])
|
66
|
-
s.add_dependency(%q<httparty>, ["
|
71
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
72
|
+
s.add_dependency(%q<mocha>, [">= 0.9.8"])
|
73
|
+
s.add_dependency(%q<test-unit>, [">= 2.1.0"])
|
67
74
|
end
|
68
75
|
end
|
69
76
|
|
data/lib/exvo-auth.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
class ExvoAuth::Autonomous::Base
|
2
|
+
attr_reader :options
|
3
|
+
@@cache = ExvoAuth::Autonomous::Cache.new
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
options[:site] ||= ExvoAuth::Config.host
|
7
|
+
options[:client_id] ||= ExvoAuth::Config.client_id
|
8
|
+
options[:client_secret] ||= ExvoAuth::Config.client_secret
|
9
|
+
@options = options
|
10
|
+
|
11
|
+
validate_options!(:site, :client_id, :client_secret)
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def validate_options!(*keys)
|
17
|
+
missing = keys - options.keys
|
18
|
+
raise(ArgumentError, "Please configure following keys: #{missing.join(", ")}") if missing.any?
|
19
|
+
end
|
20
|
+
|
21
|
+
# Makes testing easy
|
22
|
+
def httparty
|
23
|
+
HTTParty
|
24
|
+
end
|
25
|
+
end
|
@@ -4,11 +4,17 @@ class ExvoAuth::Autonomous::Cache
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def read(key)
|
7
|
-
@data[key]
|
7
|
+
o = @data[key]
|
8
|
+
o[:value] if o && (now - o[:timestamp]) < 3600 # cache for one hour
|
8
9
|
end
|
9
10
|
|
10
11
|
def write(key, value)
|
11
|
-
@data[key] =
|
12
|
+
@data[key] = {
|
13
|
+
:value => value,
|
14
|
+
:timestamp => now
|
15
|
+
}
|
16
|
+
|
17
|
+
value
|
12
18
|
end
|
13
19
|
|
14
20
|
def fetch(key)
|
@@ -18,4 +24,10 @@ class ExvoAuth::Autonomous::Cache
|
|
18
24
|
read(key)
|
19
25
|
end
|
20
26
|
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def now
|
31
|
+
Time.now
|
32
|
+
end
|
21
33
|
end
|
@@ -1,17 +1,7 @@
|
|
1
|
-
class ExvoAuth::Autonomous::Consumer
|
2
|
-
attr_reader :options
|
3
|
-
@@cache = ExvoAuth::Autonomous::Cache.new
|
4
|
-
|
1
|
+
class ExvoAuth::Autonomous::Consumer < ExvoAuth::Autonomous::Base
|
5
2
|
def initialize(options = {})
|
6
|
-
|
7
|
-
|
8
|
-
options[:client_secret] ||= ExvoAuth::Config.client_secret
|
9
|
-
|
10
|
-
if options[:site].nil? || options[:client_id].nil? || options[:client_secret].nil? || options[:provider_id].nil?
|
11
|
-
raise(ArgumentError, "Please configure site, client_id, client_secret and provider_id")
|
12
|
-
end
|
13
|
-
|
14
|
-
@options = options
|
3
|
+
super
|
4
|
+
validate_options!(:provider_id)
|
15
5
|
end
|
16
6
|
|
17
7
|
def access_token
|
@@ -21,7 +11,7 @@ class ExvoAuth::Autonomous::Consumer
|
|
21
11
|
end
|
22
12
|
|
23
13
|
def access_token!
|
24
|
-
response =
|
14
|
+
response = httparty.get("/apps/consumer/authorizations/#{options[:provider_id]}.json",
|
25
15
|
:base_uri => options[:site],
|
26
16
|
:basic_auth => {
|
27
17
|
:username => options[:client_id],
|
@@ -1,17 +1,7 @@
|
|
1
|
-
class ExvoAuth::Autonomous::Provider
|
2
|
-
attr_reader :options
|
3
|
-
@@cache = ExvoAuth::Autonomous::Cache.new
|
4
|
-
|
1
|
+
class ExvoAuth::Autonomous::Provider < ExvoAuth::Autonomous::Base
|
5
2
|
def initialize(options = {})
|
6
|
-
|
7
|
-
|
8
|
-
options[:client_secret] ||= ExvoAuth::Config.client_secret
|
9
|
-
|
10
|
-
if options[:site].nil? || options[:client_id].nil? || options[:client_secret].nil? || options[:consumer_id].nil? || options[:access_token].nil?
|
11
|
-
raise(ArgumentError, "Please configure site, client_id, client_secret, consumer_id and access_token")
|
12
|
-
end
|
13
|
-
|
14
|
-
@options = options
|
3
|
+
super
|
4
|
+
validate_options!(:consumer_id, :access_token)
|
15
5
|
end
|
16
6
|
|
17
7
|
def scopes
|
@@ -21,7 +11,7 @@ class ExvoAuth::Autonomous::Provider
|
|
21
11
|
end
|
22
12
|
|
23
13
|
def scopes!
|
24
|
-
response =
|
14
|
+
response = httparty.get("/apps/provider/authorizations/#{options[:consumer_id]}.json",
|
25
15
|
:base_uri => options[:site],
|
26
16
|
:basic_auth => {
|
27
17
|
:username => options[:client_id],
|
@@ -30,6 +20,8 @@ class ExvoAuth::Autonomous::Provider
|
|
30
20
|
:query => { :access_token => options[:access_token] }
|
31
21
|
)
|
32
22
|
|
33
|
-
|
23
|
+
if scope = response["scope"] # only cache positive responses
|
24
|
+
@@cache.write(options, scope.split)
|
25
|
+
end
|
34
26
|
end
|
35
27
|
end
|
@@ -46,6 +46,10 @@ module ExvoAuth::Controllers::Base
|
|
46
46
|
return @current_user if defined?(@current_user)
|
47
47
|
@current_user = session[:user_id] && find_user_by_id(session[:user_id])
|
48
48
|
end
|
49
|
+
|
50
|
+
def current_consumer_id
|
51
|
+
@current_consumer_id
|
52
|
+
end
|
49
53
|
|
50
54
|
def signed_in?
|
51
55
|
!!current_user
|
@@ -12,12 +12,14 @@ module ExvoAuth::Controllers::Merb
|
|
12
12
|
|
13
13
|
def authenticate_app_in_scope!(scope)
|
14
14
|
basic_authentication do |consumer_id, access_token|
|
15
|
-
|
15
|
+
current_scopes = ExvoAuth::Autonomous::Provider.new(
|
16
16
|
:consumer_id => consumer_id,
|
17
17
|
:access_token => access_token
|
18
18
|
).scopes
|
19
19
|
|
20
|
-
@
|
20
|
+
@current_consumer_id = consumer_id
|
21
|
+
|
22
|
+
current_scopes.include?(scope)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -8,12 +8,14 @@ module ExvoAuth::Controllers::Rails
|
|
8
8
|
module InstanceMethods
|
9
9
|
def authenticate_app_in_scope!(scope)
|
10
10
|
authenticate_or_request_with_http_basic do |consumer_id, access_token|
|
11
|
-
|
11
|
+
current_scopes = ExvoAuth::Autonomous::Provider.new(
|
12
12
|
:consumer_id => consumer_id,
|
13
13
|
:access_token => access_token
|
14
14
|
).scopes
|
15
15
|
|
16
|
-
@
|
16
|
+
@current_consumer_id = consumer_id
|
17
|
+
|
18
|
+
current_scopes.include?(scope)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
data/test/helper.rb
CHANGED
data/test/test_exvo_auth.rb
CHANGED
@@ -1,7 +1,26 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestExvoAuth < Test::Unit::TestCase
|
4
|
-
def
|
5
|
-
|
4
|
+
def setup
|
5
|
+
ExvoAuth::Config.client_id = "foo"
|
6
|
+
ExvoAuth::Config.client_secret = "bar"
|
7
|
+
end
|
8
|
+
|
9
|
+
test "consumer sanity" do
|
10
|
+
c = ExvoAuth::Autonomous::Consumer.new(:provider_id => "baz")
|
11
|
+
httparty = stub(:get => {"access_token" => "qux"})
|
12
|
+
c.expects(:httparty).returns(httparty)
|
13
|
+
|
14
|
+
assert_equal "qux", c.access_token
|
15
|
+
assert_equal "qux", c.access_token # second time from cache, without touching httparty
|
16
|
+
end
|
17
|
+
|
18
|
+
test "provider sanity" do
|
19
|
+
c = ExvoAuth::Autonomous::Provider.new(:consumer_id => "baz", :access_token => "qux")
|
20
|
+
httparty = stub(:get => {"scope" => "qux quux"})
|
21
|
+
c.expects(:httparty).returns(httparty)
|
22
|
+
|
23
|
+
assert_equal ["qux", "quux"], c.scopes
|
24
|
+
assert_equal ["qux", "quux"], c.scopes # second time from cache, without touching httparty
|
6
25
|
end
|
7
26
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 0.6.
|
8
|
+
- 2
|
9
|
+
version: 0.6.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jacek Becela
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
prerelease: false
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
segments:
|
42
42
|
- 0
|
@@ -45,6 +45,34 @@ dependencies:
|
|
45
45
|
version: 0.6.1
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mocha
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 9
|
58
|
+
- 8
|
59
|
+
version: 0.9.8
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: test-unit
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 2
|
71
|
+
- 1
|
72
|
+
- 0
|
73
|
+
version: 2.1.0
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
48
76
|
description: Sign in with Exvo account
|
49
77
|
email: jacek.becela@gmail.com
|
50
78
|
executables: []
|
@@ -64,6 +92,7 @@ files:
|
|
64
92
|
- VERSION
|
65
93
|
- exvo-auth.gemspec
|
66
94
|
- lib/exvo-auth.rb
|
95
|
+
- lib/exvo_auth/autonomous/base.rb
|
67
96
|
- lib/exvo_auth/autonomous/cache.rb
|
68
97
|
- lib/exvo_auth/autonomous/consumer.rb
|
69
98
|
- lib/exvo_auth/autonomous/provider.rb
|