oauth2 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.gitignore CHANGED
@@ -26,6 +26,7 @@ log
26
26
  *.gem
27
27
  .bundle
28
28
  pkg
29
+ Gemfile.lock
29
30
 
30
31
  ## RCOV
31
32
  coverage.data
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
1
  --color
2
- --backtrace
3
2
  --format=nested
3
+ --backtrace
data/Rakefile CHANGED
@@ -2,25 +2,10 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
- desc "Run all examples"
6
- RSpec::Core::RakeTask.new(:spec) do |t|
7
- t.rspec_opts = %w[--color]
8
- end
9
-
10
- task :cleanup_rcov_files do
11
- rm_rf 'coverage.data'
12
- end
13
-
14
- namespace :spec do
15
- desc "Run all examples using rcov"
16
- RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
17
- t.rcov = true
18
- t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
19
- t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
20
- end
21
- end
5
+ RSpec::Core::RakeTask.new(:spec)
22
6
 
23
7
  task :default => :spec
8
+ task :test => :spec
24
9
 
25
10
  require 'rake/rdoctask'
26
11
  Rake::RDocTask.new do |rdoc|
@@ -10,7 +10,7 @@ module OAuth2
10
10
  @expires_in = (expires_in.nil? || expires_in == '') ? nil : expires_in.to_i
11
11
  @expires_at = Time.now + @expires_in if @expires_in
12
12
  @params = params
13
- @token_param = 'access_token'
13
+ @token_param = 'oauth_token'
14
14
  end
15
15
 
16
16
  def [](key)
@@ -22,6 +22,10 @@ module OAuth2
22
22
  !!@expires_in
23
23
  end
24
24
 
25
+ def expired?
26
+ expires? && expires_at < Time.now
27
+ end
28
+
25
29
  def request(verb, path, params = {}, headers = {})
26
30
  params = params.merge token_param => @token
27
31
  headers = headers.merge 'Authorization' => "OAuth #{@token}"
data/lib/oauth2/client.rb CHANGED
@@ -2,18 +2,6 @@ require 'faraday'
2
2
 
3
3
  module OAuth2
4
4
  class Client
5
- class << self
6
- def default_connection_adapter
7
- warn '[DEPRECATED] OAuth2::Client#default_connection_adapter is deprecated, use Faraday.default_adapter instead. Will be removed in 0.1.0'
8
- Faraday.default_adapter
9
- end
10
-
11
- def default_connection_adapter=(adapter)
12
- warn '[DEPRECATED] OAuth2::Client#default_connection_adapter is deprecated, use Faraday.default_adapter instead. Will be removed in 0.1.0'
13
- Faraday.default_adapter = adapter
14
- end
15
- end
16
-
17
5
  attr_accessor :id, :secret, :site, :connection, :options
18
6
  attr_writer :json
19
7
 
@@ -62,7 +50,7 @@ module OAuth2
62
50
  else
63
51
  resp = connection.run_request(verb, url, params, headers)
64
52
  end
65
-
53
+
66
54
  case resp.status
67
55
  when 200..299
68
56
  if json?
@@ -14,35 +14,35 @@ module OAuth2
14
14
  rescue
15
15
  ResponseString.new(response)
16
16
  end
17
-
17
+
18
18
  def self.included(base)
19
19
  base.class_eval do
20
20
  attr_accessor :response
21
21
  end
22
22
  end
23
-
23
+
24
24
  def headers; response.headers end
25
25
  def status; response.status end
26
26
  end
27
-
27
+
28
28
  class ResponseHash < Hash
29
29
  include ResponseObject
30
-
30
+
31
31
  def initialize(response, hash)
32
32
  self.response = response
33
33
  hash.keys.each{|k| self[k] = hash[k]}
34
34
  end
35
35
  end
36
-
36
+
37
37
  class ResponseArray < Array
38
38
  include ResponseObject
39
-
39
+
40
40
  def initialize(response, array)
41
41
  self.response = response
42
42
  super(array)
43
43
  end
44
44
  end
45
-
45
+
46
46
  # This special String class is returned from HTTP requests
47
47
  # and contains the original full response along with convenience
48
48
  # methods for accessing the HTTP status code and headers. It
@@ -55,4 +55,4 @@ module OAuth2
55
55
  self.response = response
56
56
  end
57
57
  end
58
- end
58
+ end
@@ -4,7 +4,7 @@ module OAuth2
4
4
  module Strategy
5
5
  class WebServer < Base
6
6
  def authorize_params(options = {}) #:nodoc:
7
- super(options).merge('type' => 'web_server')
7
+ super(options).merge('response_type' => 'code')
8
8
  end
9
9
 
10
10
  # Retrieve an access token given the specified validation code.
@@ -14,16 +14,20 @@ module OAuth2
14
14
  def get_access_token(code, options = {})
15
15
  response = @client.request(:post, @client.access_token_url, access_token_params(code, options))
16
16
 
17
- params = MultiJson.decode(response) rescue nil
18
- # the ActiveSupport JSON parser won't cause an exception when
19
- # given a formencoded string, so make sure that it was
20
- # actually parsed in an Hash. This covers even the case where
21
- # it caused an exception since it'll still be nil.
22
- params = Rack::Utils.parse_query(response) unless params.is_a? Hash
17
+ if response.is_a? Hash
18
+ params=response
19
+ else
20
+ params = MultiJson.decode(response) rescue nil
21
+ # the ActiveSupport JSON parser won't cause an exception when
22
+ # given a formencoded string, so make sure that it was
23
+ # actually parsed in an Hash. This covers even the case where
24
+ # it caused an exception since it'll still be nil.
25
+ params = Rack::Utils.parse_query(response) unless params.is_a? Hash
26
+ end
23
27
 
24
28
  access = params['access_token']
25
29
  refresh = params['refresh_token']
26
- expires_in = params['expires_in']
30
+ expires_in = params['expires_in'] || params['expires'] # params['expires'] is only for facebook
27
31
  OAuth2::AccessToken.new(@client, access, refresh, expires_in, params)
28
32
  end
29
33
 
@@ -35,7 +39,7 @@ module OAuth2
35
39
 
36
40
  def access_token_params(code, options = {}) #:nodoc:
37
41
  super(options).merge({
38
- 'type' => 'web_server',
42
+ 'grant_type' => 'authorization_code',
39
43
  'code' => code
40
44
  })
41
45
  end
@@ -1,3 +1,3 @@
1
1
  module OAuth2
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/oauth2.gemspec CHANGED
@@ -4,7 +4,6 @@ require File.expand_path("../lib/oauth2/version", __FILE__)
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "oauth2"
6
6
  s.version = OAuth2::VERSION
7
- s.rubyforge_project = 'oauth2'
8
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if s.respond_to? :required_rubygems_version=
9
8
  s.authors = ["Michael Bleigh"]
10
9
  s.description = %q{A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.}
@@ -17,10 +16,11 @@ Gem::Specification.new do |s|
17
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
17
  s.files = `git ls-files`.split("\n")
19
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.add_runtime_dependency("faraday", "~> 0.5.0")
19
+ s.add_runtime_dependency("faraday", "~> 0.6.0")
21
20
  s.add_runtime_dependency("multi_json", "~> 0.0.4")
22
- s.add_development_dependency("json_pure", "~> 1.4.6")
21
+ s.add_development_dependency("json_pure", "~> 1.5")
23
22
  s.add_development_dependency("rake", "~> 0.8")
24
- s.add_development_dependency("rcov", "~> 0.9")
25
- s.add_development_dependency("rspec", "~> 2.4.0")
23
+ s.add_development_dependency("simplecov", "~> 0.4")
24
+ s.add_development_dependency("rspec", "~> 2.5")
25
+ s.add_development_dependency("ZenTest", "~> 4.5")
26
26
  end
@@ -5,10 +5,10 @@ describe OAuth2::AccessToken do
5
5
  cli = OAuth2::Client.new('abc', 'def', :site => 'https://api.example.com')
6
6
  cli.connection.build do |b|
7
7
  b.adapter :test do |stub|
8
- stub.get('/client?access_token=monkey') { |env| [200, {}, 'get'] }
9
- stub.post('/client') { |env| [200, {}, 'access_token=' << env[:body]['access_token']] }
10
- stub.put('/client') { |env| [200, {}, 'access_token=' << env[:body]['access_token']] }
11
- stub.delete('/client') { |env| [200, {}, 'access_token=' << env[:body]['access_token']] }
8
+ stub.get('/client?oauth_token=monkey') { |env| [200, {}, 'get'] }
9
+ stub.post('/client') { |env| [200, {}, 'oauth_token=' << env[:body]['oauth_token']] }
10
+ stub.put('/client') { |env| [200, {}, 'oauth_token=' << env[:body]['oauth_token']] }
11
+ stub.delete('/client') { |env| [200, {}, 'oauth_token=' << env[:body]['oauth_token']] }
12
12
  end
13
13
  end
14
14
  cli
@@ -30,7 +30,7 @@ describe OAuth2::AccessToken do
30
30
 
31
31
  %w(post put delete).each do |http_method|
32
32
  it "makes #{http_method.upcase} requests with access token" do
33
- subject.send(http_method.to_sym, 'client').should == 'access_token=monkey'
33
+ subject.send(http_method.to_sym, 'client').should == 'oauth_token=monkey'
34
34
  end
35
35
  end
36
36
  end
@@ -57,4 +57,21 @@ describe OAuth2::AccessToken do
57
57
  subject.expires_at.should == (@now + 600)
58
58
  end
59
59
  end
60
+
61
+ describe '#expired?' do
62
+ it 'should be false if there is no expires_at' do
63
+ OAuth2::AccessToken.new(client, token).should_not be_expired
64
+ end
65
+
66
+ it 'should be false if expires_at is in the future' do
67
+ OAuth2::AccessToken.new(client, token, 'abaca', 10800).should_not be_expired
68
+ end
69
+
70
+ it 'should be true if expires_at is in the past' do
71
+ access = OAuth2::AccessToken.new(client, token, 'abaca', 600)
72
+ @now = Time.now + 10800
73
+ Time.stub!(:now).and_return(@now)
74
+ access.should be_expired
75
+ end
76
+ end
60
77
  end
@@ -11,6 +11,8 @@ describe OAuth2::Strategy::WebServer do
11
11
  [200, {}, 'expires_in=600&access_token=salmon&refresh_token=trout&extra_param=steve']
12
12
  when "json"
13
13
  [200, {}, '{"expires_in":600,"access_token":"salmon","refresh_token":"trout","extra_param":"steve"}']
14
+ when "from_facebook"
15
+ [200, {}, 'expires=600&access_token=salmon&refresh_token=trout&extra_param=steve']
14
16
  end
15
17
  end
16
18
  end
@@ -25,7 +27,7 @@ describe OAuth2::Strategy::WebServer do
25
27
  end
26
28
 
27
29
  it 'should include the type' do
28
- subject.authorize_url.should be_include('type=web_server')
30
+ subject.authorize_url.should be_include('response_type=code')
29
31
  end
30
32
 
31
33
  it 'should include passed in options' do
@@ -34,35 +36,38 @@ describe OAuth2::Strategy::WebServer do
34
36
  end
35
37
  end
36
38
 
37
- %w(json formencoded).each do |mode|
38
- describe "#get_access_token (#{mode})" do
39
- before do
40
- @mode = mode
41
- @access = subject.get_access_token('sushi')
42
- end
39
+ %w(json formencoded from_facebook).each do |mode|
40
+ [false, true].each do |parse_json|
41
+ describe "#get_access_token (#{mode}, parse_json=#{parse_json})" do
42
+ before do
43
+ @mode = mode
44
+ client.json=parse_json
45
+ @access = subject.get_access_token('sushi')
46
+ end
43
47
 
44
- it 'returns AccessToken with same Client' do
45
- @access.client.should == client
46
- end
48
+ it 'returns AccessToken with same Client' do
49
+ @access.client.should == client
50
+ end
47
51
 
48
- it 'returns AccessToken with #token' do
49
- @access.token.should == 'salmon'
50
- end
52
+ it 'returns AccessToken with #token' do
53
+ @access.token.should == 'salmon'
54
+ end
51
55
 
52
- it 'returns AccessToken with #refresh_token' do
53
- @access.refresh_token.should == 'trout'
54
- end
56
+ it 'returns AccessToken with #refresh_token' do
57
+ @access.refresh_token.should == 'trout'
58
+ end
55
59
 
56
- it 'returns AccessToken with #expires_in' do
57
- @access.expires_in.should == 600
58
- end
60
+ it 'returns AccessToken with #expires_in' do
61
+ @access.expires_in.should == 600
62
+ end
59
63
 
60
- it 'returns AccessToken with #expires_at' do
61
- @access.expires_at.should be_kind_of(Time)
62
- end
64
+ it 'returns AccessToken with #expires_at' do
65
+ @access.expires_at.should be_kind_of(Time)
66
+ end
63
67
 
64
- it 'returns AccessToken with params accessible via []' do
65
- @access['extra_param'].should == 'steve'
68
+ it 'returns AccessToken with params accessible via []' do
69
+ @access['extra_param'].should == 'steve'
70
+ end
66
71
  end
67
72
  end
68
73
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rubygems'
1
+ require 'simplecov'
2
+ SimpleCov.start
4
3
  require 'oauth2'
5
4
  require 'rspec'
6
5
  require 'rspec/autorun'
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
4
+ prerelease:
5
+ version: 0.2.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Michael Bleigh
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-12 00:00:00 -06:00
13
+ date: 2011-04-01 00:00:00 -07:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,11 +21,7 @@ dependencies:
25
21
  requirements:
26
22
  - - ~>
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 5
31
- - 0
32
- version: 0.5.0
24
+ version: 0.6.0
33
25
  type: :runtime
34
26
  version_requirements: *id001
35
27
  - !ruby/object:Gem::Dependency
@@ -40,10 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ~>
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 0
46
- - 4
47
35
  version: 0.0.4
48
36
  type: :runtime
49
37
  version_requirements: *id002
@@ -55,11 +43,7 @@ dependencies:
55
43
  requirements:
56
44
  - - ~>
57
45
  - !ruby/object:Gem::Version
58
- segments:
59
- - 1
60
- - 4
61
- - 6
62
- version: 1.4.6
46
+ version: "1.5"
63
47
  type: :development
64
48
  version_requirements: *id003
65
49
  - !ruby/object:Gem::Dependency
@@ -70,24 +54,18 @@ dependencies:
70
54
  requirements:
71
55
  - - ~>
72
56
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- - 8
76
57
  version: "0.8"
77
58
  type: :development
78
59
  version_requirements: *id004
79
60
  - !ruby/object:Gem::Dependency
80
- name: rcov
61
+ name: simplecov
81
62
  prerelease: false
82
63
  requirement: &id005 !ruby/object:Gem::Requirement
83
64
  none: false
84
65
  requirements:
85
66
  - - ~>
86
67
  - !ruby/object:Gem::Version
87
- segments:
88
- - 0
89
- - 9
90
- version: "0.9"
68
+ version: "0.4"
91
69
  type: :development
92
70
  version_requirements: *id005
93
71
  - !ruby/object:Gem::Dependency
@@ -98,13 +76,20 @@ dependencies:
98
76
  requirements:
99
77
  - - ~>
100
78
  - !ruby/object:Gem::Version
101
- segments:
102
- - 2
103
- - 4
104
- - 0
105
- version: 2.4.0
79
+ version: "2.5"
106
80
  type: :development
107
81
  version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: ZenTest
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: "4.5"
91
+ type: :development
92
+ version_requirements: *id007
108
93
  description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.
109
94
  email: michael@intridea.com
110
95
  executables: []
@@ -116,11 +101,11 @@ extra_rdoc_files:
116
101
  - README.rdoc
117
102
  files:
118
103
  - .document
104
+ - .gemtest
119
105
  - .gitignore
120
106
  - .rspec
121
107
  - CHANGELOG.rdoc
122
108
  - Gemfile
123
- - Gemfile.lock
124
109
  - LICENSE
125
110
  - README.rdoc
126
111
  - Rakefile
@@ -137,7 +122,6 @@ files:
137
122
  - spec/oauth2/strategy/base_spec.rb
138
123
  - spec/oauth2/strategy/web_server_spec.rb
139
124
  - spec/spec_helper.rb
140
- - specs.watchr
141
125
  has_rdoc: true
142
126
  homepage: http://github.com/intridea/oauth2
143
127
  licenses: []
@@ -152,23 +136,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
136
  requirements:
153
137
  - - ">="
154
138
  - !ruby/object:Gem::Version
155
- segments:
156
- - 0
157
139
  version: "0"
158
140
  required_rubygems_version: !ruby/object:Gem::Requirement
159
141
  none: false
160
142
  requirements:
161
143
  - - ">="
162
144
  - !ruby/object:Gem::Version
163
- segments:
164
- - 1
165
- - 3
166
- - 6
167
145
  version: 1.3.6
168
146
  requirements: []
169
147
 
170
- rubyforge_project: oauth2
171
- rubygems_version: 1.3.7
148
+ rubyforge_project:
149
+ rubygems_version: 1.6.2
172
150
  signing_key:
173
151
  specification_version: 3
174
152
  summary: A Ruby wrapper for the OAuth 2.0 protocol.
data/Gemfile.lock DELETED
@@ -1,42 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- oauth2 (0.1.1)
5
- faraday (~> 0.5.0)
6
- multi_json (~> 0.0.4)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- addressable (2.1.2)
12
- diff-lcs (1.1.2)
13
- faraday (0.5.0)
14
- addressable (~> 2.1.1)
15
- multipart-post (~> 1.0.1)
16
- rack (~> 1.2.1)
17
- json_pure (1.4.6)
18
- multi_json (0.0.4)
19
- multipart-post (1.0.1)
20
- rack (1.2.1)
21
- rake (0.8.7)
22
- rcov (0.9.9)
23
- rspec (2.4.0)
24
- rspec-core (~> 2.4.0)
25
- rspec-expectations (~> 2.4.0)
26
- rspec-mocks (~> 2.4.0)
27
- rspec-core (2.4.0)
28
- rspec-expectations (2.4.0)
29
- diff-lcs (~> 1.1.2)
30
- rspec-mocks (2.4.0)
31
-
32
- PLATFORMS
33
- ruby
34
-
35
- DEPENDENCIES
36
- faraday (~> 0.5.0)
37
- json_pure (~> 1.4.6)
38
- multi_json (~> 0.0.4)
39
- oauth2!
40
- rake (~> 0.8)
41
- rcov (~> 0.9)
42
- rspec (~> 2.4.0)
data/specs.watchr DELETED
@@ -1,61 +0,0 @@
1
- # Run me with:
2
- #
3
- # $ watchr specs.watchr
4
-
5
- # --------------------------------------------------
6
- # Convenience Methods
7
- # --------------------------------------------------
8
- def all_test_files
9
- Dir['spec/**/*_spec.rb']
10
- end
11
-
12
- def run_test_matching(thing_to_match)
13
- matches = all_test_files.grep(/#{thing_to_match}/i)
14
- if matches.empty?
15
- puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
16
- else
17
- run matches.join(' ')
18
- end
19
- end
20
-
21
- def run(files_to_run)
22
- puts("Running: #{files_to_run}")
23
- system("clear;spec -cfs --backtrace #{files_to_run}")
24
- no_int_for_you
25
- end
26
-
27
- def run_all_tests
28
- # system("clear;rake spec")
29
- run(all_test_files.join(' '))
30
- end
31
-
32
- # --------------------------------------------------
33
- # Watchr Rules
34
- # --------------------------------------------------
35
- watch('^spec/(.*)_spec\.rb') { |m| run_test_matching(m[1]) }
36
- watch('^lib/(.*)\.rb') { |m| run_test_matching(m[1]) }
37
- watch('^sites/(.*)\.rb') { |m| run_test_matching(m[1]) }
38
- watch('^spec/spec_helper\.rb') { run_all_tests }
39
- watch('^spec/support/.*\.rb') { run_all_tests }
40
-
41
- # --------------------------------------------------
42
- # Signal Handling
43
- # --------------------------------------------------
44
-
45
- def no_int_for_you
46
- @sent_an_int = nil
47
- end
48
-
49
- Signal.trap 'INT' do
50
- if @sent_an_int then
51
- puts " A second INT? Ok, I get the message. Shutting down now."
52
- exit
53
- else
54
- puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
55
- @sent_an_int = true
56
- Kernel.sleep 1.5
57
- run_all_tests
58
- end
59
- end
60
-
61
- # vim:ft=ruby