oauth2 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,109 +1,134 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oauth2
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
4
5
  prerelease:
5
- version: 0.4.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Michael Bleigh
9
+ - Erik Michaels-Ober
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
-
13
- date: 2011-04-22 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: faraday
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
13
+ date: 2011-07-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: &70092424464720 !ruby/object:Gem::Requirement
19
18
  none: false
20
- requirements:
19
+ requirements:
21
20
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: 0.6.1
24
- type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: multi_json
21
+ - !ruby/object:Gem::Version
22
+ version: '0.9'
23
+ type: :development
28
24
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70092424464720
26
+ - !ruby/object:Gem::Dependency
27
+ name: rdoc
28
+ requirement: &70092424463940 !ruby/object:Gem::Requirement
30
29
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 0.0.5
35
- type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: json_pure
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :development
39
35
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70092424463940
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &70092424463400 !ruby/object:Gem::Requirement
41
40
  none: false
42
- requirements:
41
+ requirements:
43
42
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: "1.5"
43
+ - !ruby/object:Gem::Version
44
+ version: '2.6'
46
45
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: rake
50
46
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *70092424463400
48
+ - !ruby/object:Gem::Dependency
49
+ name: simplecov
50
+ requirement: &70092424462900 !ruby/object:Gem::Requirement
52
51
  none: false
53
- requirements:
52
+ requirements:
54
53
  - - ~>
55
- - !ruby/object:Gem::Version
56
- version: "0.8"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.4'
57
56
  type: :development
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: simplecov
61
57
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
58
+ version_requirements: *70092424462900
59
+ - !ruby/object:Gem::Dependency
60
+ name: yard
61
+ requirement: &70092424462440 !ruby/object:Gem::Requirement
63
62
  none: false
64
- requirements:
63
+ requirements:
65
64
  - - ~>
66
- - !ruby/object:Gem::Version
67
- version: "0.4"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.7'
68
67
  type: :development
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
71
- name: rspec
72
68
  prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
69
+ version_requirements: *70092424462440
70
+ - !ruby/object:Gem::Dependency
71
+ name: ZenTest
72
+ requirement: &70092424461860 !ruby/object:Gem::Requirement
74
73
  none: false
75
- requirements:
74
+ requirements:
76
75
  - - ~>
77
- - !ruby/object:Gem::Version
78
- version: "2.5"
76
+ - !ruby/object:Gem::Version
77
+ version: '4.5'
79
78
  type: :development
80
- version_requirements: *id006
81
- - !ruby/object:Gem::Dependency
82
- name: ZenTest
83
79
  prerelease: false
84
- requirement: &id007 !ruby/object:Gem::Requirement
80
+ version_requirements: *70092424461860
81
+ - !ruby/object:Gem::Dependency
82
+ name: multi_xml
83
+ requirement: &70092424461480 !ruby/object:Gem::Requirement
85
84
  none: false
86
- requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- version: "4.5"
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
90
89
  type: :development
91
- version_requirements: *id007
92
- description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style to the original OAuth gem.
93
- email: michael@intridea.com
90
+ prerelease: false
91
+ version_requirements: *70092424461480
92
+ - !ruby/object:Gem::Dependency
93
+ name: faraday
94
+ requirement: &70092424460880 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 0.6.1
100
+ - - <
101
+ - !ruby/object:Gem::Version
102
+ version: '0.8'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: *70092424460880
106
+ - !ruby/object:Gem::Dependency
107
+ name: multi_json
108
+ requirement: &70092424460060 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ~>
112
+ - !ruby/object:Gem::Version
113
+ version: 1.0.0
114
+ type: :runtime
115
+ prerelease: false
116
+ version_requirements: *70092424460060
117
+ description: A Ruby wrapper for the OAuth 2.0 protocol built with a similar style
118
+ to the original OAuth gem.
119
+ email:
120
+ - michael@intridea.com
121
+ - sferik@gmail.com
94
122
  executables: []
95
-
96
123
  extensions: []
97
-
98
124
  extra_rdoc_files: []
99
-
100
- files:
125
+ files:
126
+ - .autotest
101
127
  - .document
102
128
  - .gemtest
103
129
  - .gitignore
104
130
  - .rspec
105
131
  - .travis.yml
106
- - CHANGELOG.md
107
132
  - Gemfile
108
133
  - LICENSE.md
109
134
  - README.md
@@ -111,50 +136,49 @@ files:
111
136
  - lib/oauth2.rb
112
137
  - lib/oauth2/access_token.rb
113
138
  - lib/oauth2/client.rb
114
- - lib/oauth2/response_object.rb
139
+ - lib/oauth2/error.rb
140
+ - lib/oauth2/response.rb
141
+ - lib/oauth2/strategy/auth_code.rb
115
142
  - lib/oauth2/strategy/base.rb
116
143
  - lib/oauth2/strategy/password.rb
117
- - lib/oauth2/strategy/web_server.rb
118
144
  - lib/oauth2/version.rb
119
145
  - oauth2.gemspec
146
+ - spec/helper.rb
120
147
  - spec/oauth2/access_token_spec.rb
121
148
  - spec/oauth2/client_spec.rb
149
+ - spec/oauth2/response_spec.rb
150
+ - spec/oauth2/strategy/auth_code_spec.rb
122
151
  - spec/oauth2/strategy/base_spec.rb
123
152
  - spec/oauth2/strategy/password_spec.rb
124
- - spec/oauth2/strategy/web_server_spec.rb
125
- - spec/spec_helper.rb
126
153
  homepage: http://github.com/intridea/oauth2
127
154
  licenses: []
128
-
129
155
  post_install_message:
130
156
  rdoc_options: []
131
-
132
- require_paths:
157
+ require_paths:
133
158
  - lib
134
- required_ruby_version: !ruby/object:Gem::Requirement
159
+ required_ruby_version: !ruby/object:Gem::Requirement
135
160
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: "0"
140
- required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
166
  none: false
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
145
170
  version: 1.3.6
146
171
  requirements: []
147
-
148
172
  rubyforge_project:
149
- rubygems_version: 1.7.2
173
+ rubygems_version: 1.8.5.1
150
174
  signing_key:
151
175
  specification_version: 3
152
176
  summary: A Ruby wrapper for the OAuth 2.0 protocol.
153
- test_files:
177
+ test_files:
178
+ - spec/helper.rb
154
179
  - spec/oauth2/access_token_spec.rb
155
180
  - spec/oauth2/client_spec.rb
181
+ - spec/oauth2/response_spec.rb
182
+ - spec/oauth2/strategy/auth_code_spec.rb
156
183
  - spec/oauth2/strategy/base_spec.rb
157
184
  - spec/oauth2/strategy/password_spec.rb
158
- - spec/oauth2/strategy/web_server_spec.rb
159
- - spec/spec_helper.rb
160
- has_rdoc:
data/CHANGELOG.md DELETED
@@ -1,21 +0,0 @@
1
- # CHANGELOG
2
-
3
- * [0.4.1 - April 20, 2011](https://github.com/intridea/oauth2/compare/v0.4.0...v0.4.1)
4
- * [0.4.0 - April 20, 2011](https://github.com/intridea/oauth2/compare/v0.3.0...v0.4.0)
5
- * [0.3.0 - April 8, 2011](https://github.com/intridea/oauth2/compare/v0.2.0...v0.3.0)
6
- * [0.2.0 - April 1, 2011](https://github.com/intridea/oauth2/compare/v0.1.1...v0.2.0)
7
- * [0.1.1 - January 12, 2011](https://github.com/intridea/oauth2/compare/v0.1.0...v0.1.1)
8
- * [0.1.0 - October 13, 2010](https://github.com/intridea/oauth2/compare/v0.0.13...v0.1.0)
9
- * [0.0.13 - August 17, 2010](https://github.com/intridea/oauth2/compare/v0.0.12...v0.0.13)
10
- * [0.0.12 - August 17, 2010](https://github.com/intridea/oauth2/compare/v0.0.11...v0.0.12)
11
- * [0.0.11 - August 17, 2010](https://github.com/intridea/oauth2/compare/v0.0.10...v0.0.11)
12
- * [0.0.10 - June 19, 2010](https://github.com/intridea/oauth2/compare/v0.0.9...v0.0.10)
13
- * [0.0.9 - June 18, 2010](https://github.com/intridea/oauth2/compare/v0.0.8...v0.0.9)
14
- * [0.0.8 - April 27, 2010](https://github.com/intridea/oauth2/compare/v0.0.7...v0.0.8)
15
- * [0.0.7 - April 27, 2010](https://github.com/intridea/oauth2/compare/v0.0.6...v0.0.7)
16
- * [0.0.6 - April 25, 2010](https://github.com/intridea/oauth2/compare/v0.0.5...v0.0.6)
17
- * [0.0.5 - April 23, 2010](https://github.com/intridea/oauth2/compare/v0.0.4...v0.0.5)
18
- * [0.0.4 - April 22, 2010](https://github.com/intridea/oauth2/compare/v0.0.3...v0.0.4)
19
- * [0.0.3 - April 22, 2010](https://github.com/intridea/oauth2/compare/v0.0.2...v0.0.3)
20
- * [0.0.2 - April 22, 2010](https://github.com/intridea/oauth2/compare/v0.0.1...v0.0.2)
21
- * [0.0.1 - April 22, 2010](https://github.com/intridea/oauth2/compare/311d9f42e52b832119170d90e818f0f0b0078851...v0.0.1)
@@ -1,58 +0,0 @@
1
- module OAuth2
2
- module ResponseObject
3
- def self.from(response)
4
- object = MultiJson.decode(response.body)
5
-
6
- case object
7
- when Array
8
- ResponseArray.new(response, object)
9
- when Hash
10
- ResponseHash.new(response, object)
11
- else
12
- ResponseString.new(response)
13
- end
14
- rescue
15
- ResponseString.new(response)
16
- end
17
-
18
- def self.included(base)
19
- base.class_eval do
20
- attr_accessor :response
21
- end
22
- end
23
-
24
- def headers; response.headers end
25
- def status; response.status end
26
- end
27
-
28
- class ResponseHash < Hash
29
- include ResponseObject
30
-
31
- def initialize(response, hash)
32
- self.response = response
33
- hash.keys.each{|k| self[k] = hash[k]}
34
- end
35
- end
36
-
37
- class ResponseArray < Array
38
- include ResponseObject
39
-
40
- def initialize(response, array)
41
- self.response = response
42
- super(array)
43
- end
44
- end
45
-
46
- # This special String class is returned from HTTP requests
47
- # and contains the original full response along with convenience
48
- # methods for accessing the HTTP status code and headers. It
49
- # is returned from all access token requests.
50
- class ResponseString < String
51
- include ResponseObject
52
-
53
- def initialize(response)
54
- super(response.body.to_s)
55
- self.response = response
56
- end
57
- end
58
- end
@@ -1,58 +0,0 @@
1
- require 'multi_json'
2
-
3
- module OAuth2
4
- module Strategy
5
- class WebServer < Base
6
- def authorize_params(options={}) #:nodoc:
7
- super(options).merge('response_type' => 'code')
8
- end
9
-
10
- # Retrieve an access token given the specified validation code.
11
- # Note that you must also provide a <tt>:redirect_uri</tt> option
12
- # in order to successfully verify your request for most OAuth 2.0
13
- # endpoints.
14
- def get_access_token(code, options={})
15
- response = @client.request(@client.token_method, @client.access_token_url, access_token_params(code, options))
16
- parse_response(response)
17
- end
18
-
19
- def refresh_access_token(refresh_token, options={})
20
- response = @client.request(@client.token_method, @client.access_token_url, refresh_token_params(refresh_token, options))
21
- parse_response(response, refresh_token)
22
- end
23
-
24
- def access_token_params(code, options={}) #:nodoc:
25
- super(options).merge({
26
- 'grant_type' => 'authorization_code',
27
- 'code' => code,
28
- })
29
- end
30
-
31
- def refresh_token_params(refresh_token, options={}) #:nodoc:
32
- super(options).merge({
33
- 'grant_type' => 'refresh_token',
34
- 'refresh_token' => refresh_token,
35
- })
36
- end
37
-
38
- def parse_response(response, refresh_token = nil)
39
- if response.is_a? Hash
40
- params = response
41
- else
42
- params = MultiJson.decode(response) rescue nil
43
- # the ActiveSupport JSON parser won't cause an exception when
44
- # given a formencoded string, so make sure that it was
45
- # actually parsed in an Hash. This covers even the case where
46
- # it caused an exception since it'll still be nil.
47
- params = Rack::Utils.parse_query(response) unless params.is_a? Hash
48
- end
49
-
50
- access = params.delete('access_token')
51
- refresh = params.delete('refresh_token') || refresh_token
52
- # params['expires'] is only for Facebook
53
- expires_in = params.delete('expires_in') || params.delete('expires')
54
- OAuth2::AccessToken.new(@client, access, refresh, expires_in, params)
55
- end
56
- end
57
- end
58
- end
@@ -1,138 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe OAuth2::Strategy::WebServer do
4
- let(:client) do
5
- cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
6
- cli.connection.build do |b|
7
- b.adapter :test do |stub|
8
- stub.get('/oauth/access_token?client_id=abc&client_secret=def&code=sushi&grant_type=authorization_code') do |env|
9
- case @mode
10
- when "formencoded"
11
- [200, {}, 'expires_in=600&access_token=salmon&refresh_token=trout&extra_param=steve']
12
- when "json"
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']
16
- end
17
- end
18
- stub.post('/oauth/access_token', { 'client_id' => 'abc', 'client_secret' => 'def', 'code' => 'sushi', 'grant_type' => 'authorization_code' }) do |env|
19
- case @mode
20
- when "formencoded"
21
- [200, {}, 'expires_in=600&access_token=salmon&refresh_token=trout&extra_param=steve']
22
- when "json"
23
- [200, {}, '{"expires_in":600,"access_token":"salmon","refresh_token":"trout","extra_param":"steve"}']
24
- when "from_facebook"
25
- [200, {}, 'expires=600&access_token=salmon&refresh_token=trout&extra_param=steve']
26
- end
27
- end
28
- stub.get('/oauth/access_token?client_id=abc&client_secret=def&grant_type=refresh_token&refresh_token=trout') do |env|
29
- case @mode
30
- when "formencoded"
31
- [200, {}, 'expires_in=600&access_token=tuna']
32
- when "json"
33
- [200, {}, '{"expires_in":600,"access_token":"tuna"}']
34
- end
35
- end
36
- stub.post('/oauth/access_token', { 'client_id' => 'abc', 'client_secret' => 'def', 'refresh_token' => 'trout', 'grant_type' => 'refresh_token' }) do |env|
37
- case @mode
38
- when "formencoded"
39
- [200, {}, 'expires_in=600&access_token=tuna']
40
- when "json"
41
- [200, {}, '{"expires_in":600,"access_token":"tuna"}']
42
- end
43
- end
44
- end
45
- end
46
- cli
47
- end
48
- subject{client.web_server}
49
-
50
- describe '#authorize_url' do
51
- it 'should include the client_id' do
52
- subject.authorize_url.should be_include('client_id=abc')
53
- end
54
-
55
- it 'should include the type' do
56
- subject.authorize_url.should be_include('response_type=code')
57
- end
58
-
59
- it 'should include passed in options' do
60
- cb = 'http://myserver.local/oauth/callback'
61
- subject.authorize_url(:redirect_uri => cb).should be_include("redirect_uri=#{Rack::Utils.escape(cb)}")
62
- end
63
- end
64
-
65
- %w(json formencoded from_facebook).each do |mode|
66
- [false, true].each do |parse_json|
67
- [:get, :post].each do |verb|
68
- describe "#get_access_token (#{mode}, token_method=#{verb} parse_json=#{parse_json})" do
69
- before do
70
- @mode = mode
71
- client.json=parse_json
72
- client.token_method=verb
73
- @access = subject.get_access_token('sushi')
74
- end
75
-
76
- it 'returns AccessToken with same Client' do
77
- @access.client.should == client
78
- end
79
-
80
- it 'returns AccessToken with #token' do
81
- @access.token.should == 'salmon'
82
- end
83
-
84
- it 'returns AccessToken with #refresh_token' do
85
- @access.refresh_token.should == 'trout'
86
- end
87
-
88
- it 'returns AccessToken with #expires_in' do
89
- @access.expires_in.should == 600
90
- end
91
-
92
- it 'returns AccessToken with #expires_at' do
93
- @access.expires_at.should be_kind_of(Time)
94
- end
95
-
96
- it 'returns AccessToken with params accessible via []' do
97
- @access['extra_param'].should == 'steve'
98
- end
99
- end
100
- end
101
- end
102
- end
103
-
104
- %w(json formencoded).each do |mode|
105
- [false, true].each do |parse_json|
106
- [:get].each do |verb|
107
- describe "#refresh_access_token (#{mode}, token_method=#{verb} parse_json=#{parse_json})" do
108
- before do
109
- @mode = mode
110
- client.json=parse_json
111
- client.token_method=verb
112
- @access = subject.refresh_access_token('trout')
113
- end
114
-
115
- it 'returns AccessToken with same Client' do
116
- @access.client.should == client
117
- end
118
-
119
- it 'returns AccessToken with #token' do
120
- @access.token.should == 'tuna'
121
- end
122
-
123
- it 'returns AccessToken with #refresh_token' do
124
- @access.refresh_token.should == 'trout'
125
- end
126
-
127
- it 'returns AccessToken with #expires_in' do
128
- @access.expires_in.should == 600
129
- end
130
-
131
- it 'returns AccessToken with #expires_at' do
132
- @access.expires_at.should be_kind_of(Time)
133
- end
134
- end
135
- end
136
- end
137
- end
138
- end