exvo-auth 0.6.2 → 0.7.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
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.6.2"
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-20}
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 :options
2
+ attr_reader :params
3
3
  @@cache = ExvoAuth::Autonomous::Cache.new
4
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
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
- validate_options!(:site, :client_id, :client_secret)
11
+ validate_params!(:site, :client_id, :client_secret)
12
12
  end
13
13
 
14
14
  protected
15
15
 
16
- def validate_options!(*keys)
17
- missing = keys - options.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(options = {})
2
+ def initialize(params = {})
3
3
  super
4
- validate_options!(:provider_id)
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 access_token
8
- @@cache.fetch(options) do
9
- access_token!
46
+ def authorization
47
+ @@cache.fetch(params) do
48
+ authorization!
10
49
  end
11
50
  end
12
51
 
13
- def access_token!
14
- response = httparty.get("/apps/consumer/authorizations/#{options[:provider_id]}.json",
15
- :base_uri => options[:site],
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 => options[:client_id],
18
- :password => options[:client_secret]
56
+ :username => params[:client_id],
57
+ :password => params[:client_secret]
19
58
  }
20
59
  )
21
60
 
22
- @@cache.write(options, response["access_token"])
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(options = {})
2
+ def initialize(params = {})
3
3
  super
4
- validate_options!(:consumer_id, :access_token)
4
+ validate_params!(:consumer_id, :access_token)
5
5
  end
6
6
 
7
7
  def scopes
8
- @@cache.fetch(options) do
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/#{options[:consumer_id]}.json",
15
- :base_uri => options[:site],
14
+ response = httparty.get("/apps/provider/authorizations/#{params[:consumer_id]}.json",
15
+ :base_uri => params[:site],
16
16
  :basic_auth => {
17
- :username => options[:client_id],
18
- :password => options[:client_secret]
17
+ :username => params[:client_id],
18
+ :password => params[:client_secret]
19
19
  },
20
- :query => { :access_token => options[: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(options, scope.split)
24
+ @@cache.write(params, scope.split)
25
+ else
26
+ []
25
27
  end
26
28
  end
27
29
  end
@@ -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
- httparty = stub(:get => {"access_token" => "qux"})
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 "qux", c.access_token
15
- assert_equal "qux", c.access_token # second time from cache, without touching httparty
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
- c = ExvoAuth::Autonomous::Provider.new(:consumer_id => "baz", :access_token => "qux")
20
+ p = ExvoAuth::Autonomous::Provider.new(:consumer_id => "baz", :access_token => "qux")
20
21
  httparty = stub(:get => {"scope" => "qux quux"})
21
- c.expects(:httparty).returns(httparty)
22
+ p.expects(:httparty).returns(httparty)
22
23
 
23
- assert_equal ["qux", "quux"], c.scopes
24
- assert_equal ["qux", "quux"], c.scopes # second time from cache, without touching httparty
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
- - 6
8
- - 2
9
- version: 0.6.2
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-20 00:00:00 +02:00
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
data/TODO DELETED
@@ -1,3 +0,0 @@
1
- * Add a way for apps to talk to each other: ssl + basic auth with client_id and client_secret. An app would confirm
2
- creds (of the connecting app) with Auth app using a speedy HEAD request.
3
- * Benchmark the above to measure RTT footprint