g5_authentication_client 0.5.1 → 0.5.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0feb9bbacf734abc8f82d494f5b2e0d19342e851
4
- data.tar.gz: 1c671a19a12f098fdc271ef64fbe6f3ec62b3645
3
+ metadata.gz: c53ebcac18a16bd552178866980fafac5c8a0ae4
4
+ data.tar.gz: 17ca20696af027a5535bc29e4d3e8d7ef23b7ab6
5
5
  SHA512:
6
- metadata.gz: b0a1a80419a069ebe94d04204fe1f3cf5f53a2454e4cd94ecdb6a86b7e8996dad81245758a1f856ff5517ca9f804b8288df2ec7eafedd8a27a4b11dbd6faa88d
7
- data.tar.gz: b4450179fffa6f0bffa364bf5c28b02c6564c9be166efcc2f80c4e166506116a76fa84910ddedbeac68ba90c0203f303835bc9cb7276a70e74ac8371ed1273eb
6
+ metadata.gz: e8ec55c0c2826bcd192a1920ac3dc53d51df2edea1ef00464ef889b3a4e8cdb079f6e0ff391e19c679cefb1451e661755e64470b79cd0cf045b215288bef81f7
7
+ data.tar.gz: 088cf07f5d346f9b5de42d412a936fd1b676296d9f734e309f3536b166a43d660e034c70c033563aa9e4a402e5815e940a34d1b303752f2073c4651884c714e7
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.6
1
+ 2.2.2
@@ -0,0 +1,16 @@
1
+ module G5AuthenticationClient::AuthTokenHelper
2
+ # Return response to 'yield'
3
+ # Yield response should have a 'code' method for the http status code
4
+ def do_with_username_pw_access_token
5
+ response = yield cached_username_pw_access_token
6
+ if 401 == response.code.to_i
7
+ @cached_username_pw_access_token = nil
8
+ response = yield cached_username_pw_access_token
9
+ end
10
+ response
11
+ end
12
+
13
+ def cached_username_pw_access_token
14
+ @cached_username_pw_access_token ||= G5AuthenticationClient::Client.new.username_pw_access_token.token
15
+ end
16
+ end
@@ -184,6 +184,11 @@ module G5AuthenticationClient
184
184
  response.parsed.collect { |parsed_role| Role.new(parsed_role) }
185
185
  end
186
186
 
187
+ def username_pw_access_token
188
+ raise 'allow_password_credentials must be enabled for username/pw access' unless allow_password_credentials?
189
+ oauth_client.password.get_token(username, password)
190
+ end
191
+
187
192
  private
188
193
 
189
194
  def user_hash(h)
@@ -201,7 +206,7 @@ module G5AuthenticationClient
201
206
  elsif authorization_code
202
207
  oauth_client.auth_code.get_token(authorization_code, redirect_uri: redirect_uri)
203
208
  elsif allow_password_credentials?
204
- oauth_client.password.get_token(username,password)
209
+ username_pw_access_token
205
210
  else
206
211
  raise "Insufficient credentials for access token. Supply a username/password or authentication code"
207
212
  end
@@ -1,3 +1,3 @@
1
1
  module G5AuthenticationClient
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -4,6 +4,7 @@ require 'g5_authentication_client/configuration'
4
4
  require 'g5_authentication_client/user'
5
5
  require 'g5_authentication_client/token_info'
6
6
  require 'g5_authentication_client/role'
7
+ require 'g5_authentication_client/auth_token_helper'
7
8
 
8
9
  module G5AuthenticationClient
9
10
  extend Configuration
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe G5AuthenticationClient::AuthTokenHelper do
4
+ class TestDummy
5
+ include G5AuthenticationClient::AuthTokenHelper
6
+ end
7
+ subject { TestDummy.new }
8
+ describe '#do_with_username_pw_access_token' do
9
+ let(:response) { double(:response, code: code) }
10
+ let(:token) { double(:token, token: 'asdf') }
11
+ before do
12
+ allow(G5AuthenticationClient::Client).to receive(:new).and_return(double(:client, username_pw_access_token: token))
13
+ end
14
+ let(:call) do
15
+ subject.do_with_username_pw_access_token do |token|
16
+ response
17
+ end
18
+ end
19
+
20
+ context '200' do
21
+ let(:code) { '200' }
22
+ it 'responds with the yielded response' do
23
+ expect(call).to eq(response)
24
+ end
25
+
26
+ context 'subsequent calls' do
27
+ before do
28
+ call
29
+ call
30
+ end
31
+ it 'responds with the yieleded response' do
32
+ expect(call).to eq(response)
33
+ end
34
+ it 'calls username_pw_access_token once' do
35
+ expect(G5AuthenticationClient::Client).to have_received(:new).once
36
+ end
37
+ end
38
+ end
39
+
40
+ context '401' do
41
+ let(:code) { '401' }
42
+ before do
43
+ allow(G5AuthenticationClient::Client).to receive(:new).and_return(double(:client, username_pw_access_token: token))
44
+ call
45
+ end
46
+ it 'responds with the yielded response' do
47
+ expect(call).to eq(response)
48
+ end
49
+ it 'calls username_pw_access_token once' do
50
+ expect(G5AuthenticationClient::Client).to have_received(:new).twice
51
+ end
52
+ end
53
+ end
54
+ end
@@ -127,6 +127,10 @@ describe G5AuthenticationClient::Client do
127
127
  it 'should have default allow_password_credentials' do
128
128
  expect(client.allow_password_credentials).to eq('true')
129
129
  end
130
+
131
+ it 'username_pw_access_token raises error when password credentials not enabled' do
132
+ expect { client.username_pw_access_token }.to raise_error('allow_password_credentials must be enabled for username/pw access')
133
+ end
130
134
  end
131
135
 
132
136
  context 'with non-default configuration' do
@@ -518,4 +522,23 @@ describe G5AuthenticationClient::Client do
518
522
  it_should_behave_like 'an oauth protected resource', G5AuthenticationClient::Role
519
523
  end
520
524
  end
525
+
526
+ context 'stubbed get token' do
527
+ let(:token) {'asdf'}
528
+ before do
529
+ oauth_client = double(OAuth2::AccessToken, password: double(:pw, get_token: token))
530
+ allow(client).to receive(:oauth_client).and_return(oauth_client)
531
+ end
532
+
533
+ describe '#username_pw_access_token' do
534
+ let(:returned_token) { {access_token: 'asdf'} }
535
+ before do
536
+ client.allow_password_credentials = 'true'
537
+ end
538
+
539
+ it 'delegates token retrieval to oauth_client' do
540
+ expect(client.username_pw_access_token).to eq(token)
541
+ end
542
+ end
543
+ end
521
544
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g5_authentication_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Revels
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-21 00:00:00.000000000 Z
12
+ date: 2015-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: modelish
@@ -212,12 +212,14 @@ files:
212
212
  - Rakefile
213
213
  - g5_authentication_client.gemspec
214
214
  - lib/g5_authentication_client.rb
215
+ - lib/g5_authentication_client/auth_token_helper.rb
215
216
  - lib/g5_authentication_client/client.rb
216
217
  - lib/g5_authentication_client/configuration.rb
217
218
  - lib/g5_authentication_client/role.rb
218
219
  - lib/g5_authentication_client/token_info.rb
219
220
  - lib/g5_authentication_client/user.rb
220
221
  - lib/g5_authentication_client/version.rb
222
+ - spec/g5_authentication_client/auth_token_helper_spec.rb
221
223
  - spec/g5_authentication_client/client_spec.rb
222
224
  - spec/g5_authentication_client/configuration_spec.rb
223
225
  - spec/g5_authentication_client/role_spec.rb
@@ -246,11 +248,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
248
  version: '0'
247
249
  requirements: []
248
250
  rubyforge_project: g5_authentication_client
249
- rubygems_version: 2.4.6
251
+ rubygems_version: 2.4.5
250
252
  signing_key:
251
253
  specification_version: 4
252
254
  summary: Client for the G5 Auth service
253
255
  test_files:
256
+ - spec/g5_authentication_client/auth_token_helper_spec.rb
254
257
  - spec/g5_authentication_client/client_spec.rb
255
258
  - spec/g5_authentication_client/configuration_spec.rb
256
259
  - spec/g5_authentication_client/role_spec.rb