exvo-auth 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/exvo-auth.gemspec +3 -5
- data/lib/exvo_auth/autonomous/base.rb +9 -9
- data/lib/exvo_auth/autonomous/consumer.rb +50 -11
- data/lib/exvo_auth/autonomous/provider.rb +11 -9
- data/test/test_exvo_auth.rb +23 -7
- metadata +4 -6
- data/TODO +0 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/exvo-auth.gemspec
CHANGED
@@ -5,24 +5,22 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{exvo-auth}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
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-21}
|
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 = [
|
16
16
|
"LICENSE",
|
17
|
-
"README"
|
18
|
-
"TODO"
|
17
|
+
"README"
|
19
18
|
]
|
20
19
|
s.files = [
|
21
20
|
".gitignore",
|
22
21
|
"LICENSE",
|
23
22
|
"README",
|
24
23
|
"Rakefile",
|
25
|
-
"TODO",
|
26
24
|
"VERSION",
|
27
25
|
"exvo-auth.gemspec",
|
28
26
|
"lib/exvo-auth.rb",
|
@@ -1,20 +1,20 @@
|
|
1
1
|
class ExvoAuth::Autonomous::Base
|
2
|
-
attr_reader :
|
2
|
+
attr_reader :params
|
3
3
|
@@cache = ExvoAuth::Autonomous::Cache.new
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
5
|
+
def initialize(params = {})
|
6
|
+
params[:site] ||= ExvoAuth::Config.host
|
7
|
+
params[:client_id] ||= ExvoAuth::Config.client_id
|
8
|
+
params[:client_secret] ||= ExvoAuth::Config.client_secret
|
9
|
+
@params = params
|
10
10
|
|
11
|
-
|
11
|
+
validate_params!(:site, :client_id, :client_secret)
|
12
12
|
end
|
13
13
|
|
14
14
|
protected
|
15
15
|
|
16
|
-
def
|
17
|
-
missing = keys -
|
16
|
+
def validate_params!(*keys)
|
17
|
+
missing = keys - params.keys
|
18
18
|
raise(ArgumentError, "Please configure following keys: #{missing.join(", ")}") if missing.any?
|
19
19
|
end
|
20
20
|
|
@@ -1,24 +1,63 @@
|
|
1
1
|
class ExvoAuth::Autonomous::Consumer < ExvoAuth::Autonomous::Base
|
2
|
-
def initialize(
|
2
|
+
def initialize(params = {})
|
3
3
|
super
|
4
|
-
|
4
|
+
validate_params!(:provider_id)
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(*args)
|
8
|
+
http.get(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(*args)
|
12
|
+
http.post(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def put(*args)
|
16
|
+
http.put(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(*args)
|
20
|
+
http.delete(*args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def head(*args)
|
24
|
+
http.head(*args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def options(*args)
|
28
|
+
http.options(*args)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
# Url and Token set on each request so expired authorization will cause re-authorization.
|
34
|
+
def http
|
35
|
+
basement.base_uri(authorization["url"])
|
36
|
+
basement.basic_auth(params[:client_id], authorization["access_token"])
|
37
|
+
basement
|
38
|
+
end
|
39
|
+
|
40
|
+
def basement
|
41
|
+
@basement ||= Class.new do
|
42
|
+
include HTTParty
|
43
|
+
end
|
5
44
|
end
|
6
45
|
|
7
|
-
def
|
8
|
-
@@cache.fetch(
|
9
|
-
|
46
|
+
def authorization
|
47
|
+
@@cache.fetch(params) do
|
48
|
+
authorization!
|
10
49
|
end
|
11
50
|
end
|
12
51
|
|
13
|
-
def
|
14
|
-
response = httparty.get("/apps/consumer/authorizations/#{
|
15
|
-
:base_uri =>
|
52
|
+
def authorization!
|
53
|
+
response = httparty.get("/apps/consumer/authorizations/#{params[:provider_id]}.json",
|
54
|
+
:base_uri => params[:site],
|
16
55
|
:basic_auth => {
|
17
|
-
:username =>
|
18
|
-
:password =>
|
56
|
+
:username => params[:client_id],
|
57
|
+
:password => params[:client_secret]
|
19
58
|
}
|
20
59
|
)
|
21
60
|
|
22
|
-
@@cache.write(
|
61
|
+
@@cache.write(params, response["authorization"])
|
23
62
|
end
|
24
63
|
end
|
@@ -1,27 +1,29 @@
|
|
1
1
|
class ExvoAuth::Autonomous::Provider < ExvoAuth::Autonomous::Base
|
2
|
-
def initialize(
|
2
|
+
def initialize(params = {})
|
3
3
|
super
|
4
|
-
|
4
|
+
validate_params!(:consumer_id, :access_token)
|
5
5
|
end
|
6
6
|
|
7
7
|
def scopes
|
8
|
-
@@cache.fetch(
|
8
|
+
@@cache.fetch(params) do
|
9
9
|
scopes!
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def scopes!
|
14
|
-
response = httparty.get("/apps/provider/authorizations/#{
|
15
|
-
:base_uri =>
|
14
|
+
response = httparty.get("/apps/provider/authorizations/#{params[:consumer_id]}.json",
|
15
|
+
:base_uri => params[:site],
|
16
16
|
:basic_auth => {
|
17
|
-
:username =>
|
18
|
-
:password =>
|
17
|
+
:username => params[:client_id],
|
18
|
+
:password => params[:client_secret]
|
19
19
|
},
|
20
|
-
:query => { :access_token =>
|
20
|
+
:query => { :access_token => params[:access_token] }
|
21
21
|
)
|
22
22
|
|
23
23
|
if scope = response["scope"] # only cache positive responses
|
24
|
-
@@cache.write(
|
24
|
+
@@cache.write(params, scope.split)
|
25
|
+
else
|
26
|
+
[]
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/test/test_exvo_auth.rb
CHANGED
@@ -8,19 +8,35 @@ class TestExvoAuth < Test::Unit::TestCase
|
|
8
8
|
|
9
9
|
test "consumer sanity" do
|
10
10
|
c = ExvoAuth::Autonomous::Consumer.new(:provider_id => "baz")
|
11
|
-
|
11
|
+
authorization = { "access_token" => "qux", "url" => "https://foo/api" }
|
12
|
+
httparty = stub(:get => { "authorization" => authorization })
|
12
13
|
c.expects(:httparty).returns(httparty)
|
13
14
|
|
14
|
-
assert_equal
|
15
|
-
assert_equal
|
15
|
+
assert_equal authorization, c.send(:authorization)
|
16
|
+
assert_equal authorization, c.send(:authorization) # second time from cache, without touching httparty
|
16
17
|
end
|
17
18
|
|
18
19
|
test "provider sanity" do
|
19
|
-
|
20
|
+
p = ExvoAuth::Autonomous::Provider.new(:consumer_id => "baz", :access_token => "qux")
|
20
21
|
httparty = stub(:get => {"scope" => "qux quux"})
|
21
|
-
|
22
|
+
p.expects(:httparty).returns(httparty)
|
22
23
|
|
23
|
-
assert_equal ["qux", "quux"],
|
24
|
-
assert_equal ["qux", "quux"],
|
24
|
+
assert_equal ["qux", "quux"], p.scopes
|
25
|
+
assert_equal ["qux", "quux"], p.scopes # second time from cache, without touching httparty
|
26
|
+
end
|
27
|
+
|
28
|
+
test "integration of httparty interface with auth" do
|
29
|
+
c = ExvoAuth::Autonomous::Consumer.new(:provider_id => "baz")
|
30
|
+
basement = mock("basement")
|
31
|
+
basement.expects(:base_uri)
|
32
|
+
basement.expects(:basic_auth)
|
33
|
+
basement.expects(:get).with("/bar").returns(true)
|
34
|
+
c.expects(:basement).at_least_once.returns(basement)
|
35
|
+
assert_true c.get("/bar")
|
36
|
+
end
|
37
|
+
|
38
|
+
test "basement includes httparty" do
|
39
|
+
c = ExvoAuth::Autonomous::Consumer.new(:provider_id => "baz")
|
40
|
+
assert_true c.send(:basement).included_modules.include?(HTTParty)
|
25
41
|
end
|
26
42
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 0.7.0
|
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-21 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -82,13 +82,11 @@ extensions: []
|
|
82
82
|
extra_rdoc_files:
|
83
83
|
- LICENSE
|
84
84
|
- README
|
85
|
-
- TODO
|
86
85
|
files:
|
87
86
|
- .gitignore
|
88
87
|
- LICENSE
|
89
88
|
- README
|
90
89
|
- Rakefile
|
91
|
-
- TODO
|
92
90
|
- VERSION
|
93
91
|
- exvo-auth.gemspec
|
94
92
|
- lib/exvo-auth.rb
|