oauth2-client 1.0.0 → 1.1.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.
@@ -147,10 +147,10 @@ describe OAuth2::Client do
147
147
 
148
148
  context "with custom connection options" do
149
149
  it "returns custom connection" do
150
- # custom_http = Struct.new('CustomHttpClient')
151
- # conn_options = { :connection_client => custom_http }
152
- # oauth_client = OAuth2::Client.new('example.com', @client_id, @client_secret, conn_options)
153
- # expect(oauth_client.send(:connection)).to be_instance_of custom_http
150
+ custom_http = Struct.new('CustomHttpClient', :url, :connection_options)
151
+ conn_options = { :connection_client => custom_http }
152
+ oauth_client = OAuth2::Client.new('example.com', @client_id, @client_secret, conn_options)
153
+ expect(oauth_client.send(:connection)).to be_instance_of custom_http
154
154
  end
155
155
  end
156
156
  end
@@ -4,26 +4,28 @@ require 'ostruct'
4
4
  describe OAuth2::HttpConnection do
5
5
 
6
6
  subject do
7
- @conn = OAuth2::HttpConnection.new('https://yammer.com')
7
+ @conn = OAuth2::HttpConnection.new('https://example.com')
8
8
  end
9
9
 
10
- context "with user options" do
10
+ context "with user specified options" do
11
11
  before do
12
- @conn = OAuth2::HttpConnection.new('https://microsoft.com', {
13
- :accept => 'application/xml',
14
- :user_agent => "OAuth2 Test Client",
12
+ @conn_opts = {
13
+ :headers => {
14
+ :accept => 'application/json',
15
+ :user_agent => 'OAuth2 Test Client'
16
+ },
15
17
  :ssl => {:verify => false},
16
18
  :max_redirects => 2
17
- })
19
+ }
20
+ @conn = OAuth2::HttpConnection.new('https://example.com', @conn_opts)
18
21
  end
19
22
 
20
23
  describe "connection options" do
21
- # it " " do
22
- # options = OAuth2::HttpConnection.default_options
23
- # options.keys.each do |key|
24
- # expect(@conn.instance_variable_get(:"@#{key}")).to eq options[key]
25
- # end
26
- # end
24
+ it "sets user options" do
25
+ OAuth2::HttpConnection.default_options.keys.each do |key|
26
+ expect(@conn.instance_variable_get(:"@#{key}")).to eq @conn_opts[key]
27
+ end
28
+ end
27
29
  end
28
30
  end
29
31
 
@@ -66,7 +68,7 @@ describe OAuth2::HttpConnection do
66
68
 
67
69
  describe "#host" do
68
70
  it "returns the host server" do
69
- expect(subject.host).to eq 'yammer.com'
71
+ expect(subject.host).to eq 'example.com'
70
72
  end
71
73
  end
72
74
 
@@ -104,13 +106,13 @@ describe OAuth2::HttpConnection do
104
106
  describe "#absolute_url" do
105
107
  context "with no parameters" do
106
108
  it "returns a uri without path" do
107
- expect(subject.absolute_url).to eq "https://yammer.com"
109
+ expect(subject.absolute_url).to eq "https://example.com"
108
110
  end
109
111
  end
110
112
 
111
113
  context "with parameters" do
112
114
  it "returns a uri with path" do
113
- expect(subject.absolute_url('/oauth/v2/authorize')).to eq "https://yammer.com/oauth/v2/authorize"
115
+ expect(subject.absolute_url('/oauth/v2/authorize')).to eq "https://example.com/oauth/v2/authorize"
114
116
  end
115
117
  end
116
118
  end
@@ -150,7 +152,7 @@ describe OAuth2::HttpConnection do
150
152
  @http_redirect = OpenStruct.new(
151
153
  :code => '301',
152
154
  :body => 'redirect',
153
- :header => {'Location' => "http://yammer.com/members"}
155
+ :header => {'Location' => "http://example.com/members"}
154
156
  )
155
157
  end
156
158
 
@@ -162,55 +164,66 @@ describe OAuth2::HttpConnection do
162
164
 
163
165
  context "when method is get" do
164
166
  it "returns an http response" do
165
- path = '/oauth/authorize'
166
167
  params = {:client_id => '001337', :client_secret => 'abcxyz'}
167
- method = :get
168
168
 
169
- normalized_path = '/oauth/authorize?client_id=001337&client_secret=abcxyz'
170
-
171
- Net::HTTP.any_instance.should_receive(:get).with(normalized_path, subject.default_headers).and_return(@http_ok)
172
- response = subject.send_request(method, path, :params => params)
173
-
169
+ stub_get('/oauth/authorize').with(
170
+ :query => params,
171
+ :header => {
172
+ 'Accept' => 'application/json',
173
+ 'User-Agent' => "OAuth2 Ruby Gem #{OAuth2::Version}",
174
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
175
+ }
176
+ )
177
+ response = subject.send_request(:get, '/oauth/authorize', :params => params)
174
178
  expect(response.code).to eq '200'
175
179
  end
176
180
  end
177
181
 
178
182
  context "when method is delete" do
179
183
  it "returns an http response" do
180
- path = '/users/1'
181
- method = 'delete'
182
-
183
- Net::HTTP.any_instance.should_receive(:delete).with(path, subject.default_headers).and_return(@http_ok)
184
- response = subject.send_request(method, path)
185
-
184
+ stub_delete('/users/1').with(
185
+ :header => {
186
+ 'Accept' => 'application/json',
187
+ 'User-Agent' => "OAuth2 Ruby Gem #{OAuth2::Version}",
188
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'
189
+ }
190
+ )
191
+ response = subject.send_request(:delete, '/users/1')
186
192
  expect(response.code).to eq '200'
187
193
  end
188
194
  end
189
195
 
190
196
  context "when method is post" do
191
197
  it "returns an http response" do
192
- path = '/users'
193
198
  params = {:first_name => 'john', :last_name => 'smith'}
194
- query = Addressable::URI.form_encode(params)
195
- headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
196
-
197
- Net::HTTP.any_instance.should_receive(:post).with(path, query, headers).and_return(@http_ok)
198
- response =subject.send_request(:post, path, :params => params)
199
-
199
+ stub_post('/users').with(
200
+ :body => params,
201
+ :header => {
202
+ 'Accept' => 'application/json',
203
+ 'User-Agent' => "OAuth2 Ruby Gem #{OAuth2::Version}",
204
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
205
+ 'Content-Type' => 'application/x-www-form-urlencoded'
206
+ }
207
+ )
208
+ response =subject.send_request(:post, '/users', :params => params)
200
209
  expect(response.code).to eq '200'
201
210
  end
202
211
  end
203
212
 
204
213
  context "when method is put" do
205
214
  it "returns an http response" do
206
- path = '/users/1'
207
215
  params = {:first_name => 'jane', :last_name => 'doe'}
208
- query = Addressable::URI.form_encode(params)
209
- headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.default_headers)
210
-
211
- Net::HTTP.any_instance.should_receive(:put).with(path, query, headers).and_return(@http_ok)
212
216
 
213
- response = subject.send_request(:put, path, :params => params)
217
+ stub_put('/users/1').with(
218
+ :body => params,
219
+ :header => {
220
+ 'Accept' => 'application/json',
221
+ 'User-Agent' => "OAuth2 Ruby Gem #{OAuth2::Version}",
222
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
223
+ 'Content-Type' => 'application/x-www-form-urlencoded'
224
+ }
225
+ )
226
+ response = subject.send_request(:put, '/users/1', :params => params)
214
227
 
215
228
  expect(response.code).to eq '200'
216
229
  end
@@ -253,7 +266,7 @@ describe OAuth2::HttpConnection do
253
266
  http_303 = OpenStruct.new(
254
267
  :code => '303',
255
268
  :body => 'redirect',
256
- :header => {'Location' => "http://yammer.com/members"}
269
+ :header => {'Location' => "http://example.com/members"}
257
270
  )
258
271
  path = '/users'
259
272
  params = {:first_name => 'jane', :last_name => 'doe'}
@@ -75,14 +75,19 @@ describe OAuth2::Grant::AuthorizationCode do
75
75
 
76
76
  describe "#fetch_authorization_url" do
77
77
  it "returns response authorization page from oauth server" do
78
- subject.should_receive(:make_request).with(:get, "/oauth2/authorize", {:params=> {:response_type=>"code", :client_id=>"s6BhdRkqt3"}})
78
+ subject.should_receive(:make_request).with(:get, "/oauth2/authorize", {
79
+ :params=> {:response_type=>"code", :client_id=>"s6BhdRkqt3"}
80
+ })
79
81
  subject.fetch_authorization_url
80
82
  end
81
83
  end
82
84
 
83
85
  describe "#get_token" do
84
86
  it "exchanges authorization code for access token" do
85
- subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:scope=>"abc xyz", :state=>"state", :code=>"G3Y6jU3a"}, :authenticate=>:headers})
87
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {
88
+ :params => {:scope => "abc xyz", :state => "state", :code=>"G3Y6jU3a", :grant_type => "authorization_code"},
89
+ :authenticate => :headers
90
+ })
86
91
  subject.get_token('G3Y6jU3a', :params => {:scope => 'abc xyz', :state => 'state'})
87
92
  end
88
93
  end
@@ -21,7 +21,10 @@ describe OAuth2::Grant::ClientCredentials do
21
21
 
22
22
  describe "#get_token" do
23
23
  it "exchanges authorization code for access token" do
24
- subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:grant_type=>"client_credentials"}, :authenticate=>:headers})
24
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {
25
+ :params => {:grant_type=>"client_credentials"},
26
+ :authenticate=>:headers
27
+ })
25
28
  subject.get_token
26
29
  end
27
30
  end
@@ -21,14 +21,19 @@ describe OAuth2::Grant::DeviceCode do
21
21
 
22
22
  describe "#get_code" do
23
23
  it "gets user code" do
24
- subject.should_receive(:make_request).with(:post, "/oauth2/device/code", {:params=>{:client_id=>"s6BhdRkqt3"}})
24
+ subject.should_receive(:make_request).with(:post, "/oauth2/device/code", {
25
+ :params => {:client_id=>"s6BhdRkqt3"}
26
+ })
25
27
  subject.get_code
26
28
  end
27
29
  end
28
30
 
29
31
  describe "#get_token" do
30
32
  it "gets access token" do
31
- subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:code=>"G3Y6jU3a", :grant_type=>"http://oauth.net/grant_type/device/1.0"}, :authenticate=>:headers})
33
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {
34
+ :params => {:code=>"G3Y6jU3a", :grant_type=>"http://oauth.net/grant_type/device/1.0"},
35
+ :authenticate => :headers
36
+ })
32
37
  subject.get_token('G3Y6jU3a')
33
38
  end
34
39
  end
@@ -29,7 +29,10 @@ describe OAuth2::Grant::Implicit do
29
29
 
30
30
  describe "#get_token" do
31
31
  it "gets access token" do
32
- subject.should_receive(:make_request).with(:get, "/oauth2/token", {:params=>{:scope=>"xyz", :state=>"abc xyz", :response_type=>"token", :client_id=>"s6BhdRkqt3"}, :authenticate=>:headers})
32
+ subject.should_receive(:make_request).with(:get, "/oauth2/token", {
33
+ :params => {:scope=>"xyz", :state=>"abc xyz", :response_type=>"token", :client_id=>"s6BhdRkqt3"},
34
+ :authenticate => :headers
35
+ })
33
36
  subject.get_token(:params => {:scope => 'xyz', :state => 'abc xyz'})
34
37
  end
35
38
  end
@@ -21,7 +21,10 @@ describe OAuth2::Grant::Password do
21
21
 
22
22
  describe "#get_token" do
23
23
  it "gets access token" do
24
- subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:grant_type=>"password", :username=>"benutzername", :password=>"passwort"}, :authenticate=>:headers})
24
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {
25
+ :params => {:grant_type=>"password", :username=>"benutzername", :password=>"passwort"},
26
+ :authenticate=>:headers
27
+ })
25
28
  subject.get_token('benutzername', 'passwort')
26
29
  end
27
30
  end
@@ -20,7 +20,10 @@ describe OAuth2::Grant::RefreshToken do
20
20
 
21
21
  describe "#get_token" do
22
22
  it "gets access token" do
23
- subject.should_receive(:make_request).with(:post, "/oauth2/token", {:params=>{:grant_type=>"refresh_token", :refresh_token=>"2YotnFZFEjr1zCsicMWpAA"}, :authenticate=>:headers})
23
+ subject.should_receive(:make_request).with(:post, "/oauth2/token", {
24
+ :params => {:grant_type=>"refresh_token", :refresh_token=>"2YotnFZFEjr1zCsicMWpAA"},
25
+ :authenticate => :headers
26
+ })
24
27
  subject.get_token('2YotnFZFEjr1zCsicMWpAA')
25
28
  end
26
29
  end
@@ -1,10 +1,11 @@
1
1
  $:.unshift File.expand_path('../../examples', __FILE__)
2
2
 
3
3
  # require 'simplecov'
4
- # SimpleCov.start
4
+ # SimpleCov.start
5
5
 
6
6
  require 'rspec'
7
7
  require 'rspec/autorun'
8
+ require 'webmock/rspec'
8
9
  require 'oauth2'
9
10
 
10
11
  RSpec.configure do |config|
@@ -12,4 +13,20 @@ RSpec.configure do |config|
12
13
  config.expect_with :rspec do |c|
13
14
  c.syntax = :expect
14
15
  end
16
+ end
17
+
18
+ def stub_delete(path)
19
+ stub_request(:delete, 'https://example.com' + path)
20
+ end
21
+
22
+ def stub_get(path)
23
+ stub_request(:get, 'https://example.com' + path)
24
+ end
25
+
26
+ def stub_post(path)
27
+ stub_request(:post, 'https://example.com' + path)
28
+ end
29
+
30
+ def stub_put(path)
31
+ stub_request(:put, 'https://example.com' + path)
15
32
  end
metadata CHANGED
@@ -1,18 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kevin Mutyaba
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Create quick and dirty OAuth2 clients for many services. Google OAuth2
15
- client included
11
+ date: 2013-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bcrypt-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: addressable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description: Create quick and dirty OAuth2 clients
16
70
  email: tiabasnk@gmail.com
17
71
  executables: []
18
72
  extensions: []
@@ -22,12 +76,13 @@ files:
22
76
  - .travis.yml
23
77
  - Gemfile
24
78
  - Gemfile.lock
25
- - LICENSE
79
+ - LICENSE.md
26
80
  - README.md
27
81
  - Rakefile
28
- - TODO
29
82
  - doc/README
83
+ - examples/github_client.rb
30
84
  - examples/google_client.rb
85
+ - examples/yammer_client.rb
31
86
  - lib/oauth2.rb
32
87
  - lib/oauth2/client.rb
33
88
  - lib/oauth2/connection.rb
@@ -43,9 +98,9 @@ files:
43
98
  - lib/oauth2/helper.rb
44
99
  - lib/oauth2/version.rb
45
100
  - oauth2-client.gemspec
46
- - spec/.DS_Store
101
+ - spec/examples/github_client_spec.rb
47
102
  - spec/examples/google_client_spec.rb
48
- - spec/mocks/oauth_client.yml
103
+ - spec/examples/yammer_client_spec.rb
49
104
  - spec/oauth2/client_spec.rb
50
105
  - spec/oauth2/connection_spec.rb
51
106
  - spec/oauth2/grant/authorization_code_spec.rb
@@ -56,28 +111,28 @@ files:
56
111
  - spec/oauth2/grant/password_spec.rb
57
112
  - spec/oauth2/grant/refresh_token_spec.rb
58
113
  - spec/spec_helper.rb
59
- homepage: ''
60
- licenses: []
114
+ homepage: http://tiabas.github.com/oauth2-client/
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
61
118
  post_install_message:
62
119
  rdoc_options: []
63
120
  require_paths:
64
121
  - lib
65
122
  required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
123
  requirements:
68
124
  - - ! '>='
69
125
  - !ruby/object:Gem::Version
70
126
  version: '0'
71
127
  required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
128
  requirements:
74
129
  - - ! '>='
75
130
  - !ruby/object:Gem::Version
76
- version: '0'
131
+ version: 1.3.6
77
132
  requirements: []
78
133
  rubyforge_project:
79
- rubygems_version: 1.8.24
134
+ rubygems_version: 2.0.0
80
135
  signing_key:
81
- specification_version: 3
82
- summary: OAuth2 Ruby Client
136
+ specification_version: 4
137
+ summary: OAuth2 client wrapper in Ruby
83
138
  test_files: []