aptible-auth 0.11.15 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Rakefile +6 -2
- data/lib/aptible/auth/token.rb +20 -11
- data/lib/aptible/auth/version.rb +1 -1
- data/spec/aptible/auth/token_spec.rb +30 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d1a369415687169cb1c1b3e7719962c376ad90e
|
4
|
+
data.tar.gz: 76977a7c3bba157abb62d95c67a0b4acdca812e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9084781288cbb151cb96dcd37ef751e98b31f89a658dd6df2f6dc6e1cc0c4b44f084b58f99c2ec48a4b44eb99e4c2401a81924469db81e4e78aedfbf2ae90dc8
|
7
|
+
data.tar.gz: 8407ed89866dcbe80c8f691083252c6674194c5a1ed2bc2e66d154cb3a6561f8da83fb95fed56f8857b82f8ad96b7d3852aa540cf3e2e57e03755fd26d8660e5
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
data/lib/aptible/auth/token.rb
CHANGED
@@ -60,14 +60,7 @@ module Aptible
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def authenticate_impersonate(subject_token, subject_token_type, options)
|
63
|
-
|
64
|
-
actor_token = \
|
65
|
-
case actor_token = options.delete(:token)
|
66
|
-
when Aptible::Resource::Base then actor_token.access_token
|
67
|
-
when Fridge::AccessToken then actor_token.to_s
|
68
|
-
when String then actor_token
|
69
|
-
else bearer_token
|
70
|
-
end
|
63
|
+
actor_token = token_as_string(options.delete(:token)) || bearer_token
|
71
64
|
|
72
65
|
# TODO: Do we want to check whether the token is non-nil at this stage?
|
73
66
|
options[:scope] ||= 'manage'
|
@@ -75,6 +68,7 @@ module Aptible
|
|
75
68
|
actor_token, 'urn:ietf:params:oauth:token-type:jwt',
|
76
69
|
subject_token, subject_token_type, options
|
77
70
|
)
|
71
|
+
|
78
72
|
apply_oauth_response(oauth_token)
|
79
73
|
end
|
80
74
|
|
@@ -106,10 +100,12 @@ module Aptible
|
|
106
100
|
authenticate_impersonate(href, 'aptible:organization:href', options)
|
107
101
|
elsif (email = options.delete(:user_email))
|
108
102
|
authenticate_impersonate(email, 'aptible:user:email', options)
|
103
|
+
elsif (user_token = options.delete(:user_token))
|
104
|
+
authenticate_impersonate(
|
105
|
+
token_as_string(user_token), 'aptible:token', options
|
106
|
+
)
|
109
107
|
else
|
110
|
-
|
111
|
-
fail 'Unrecognized options'
|
112
|
-
# rubocop:enable Style/SignalException
|
108
|
+
raise 'Unrecognized options'
|
113
109
|
end
|
114
110
|
end
|
115
111
|
|
@@ -169,6 +165,19 @@ module Aptible
|
|
169
165
|
# http://stackoverflow.com/questions/13747212
|
170
166
|
private_key.n.num_bytes * 8
|
171
167
|
end
|
168
|
+
|
169
|
+
def token_as_string(tok)
|
170
|
+
# TODO: This duplicates aptible-resource, is it worth extracting?
|
171
|
+
return nil if tok.nil?
|
172
|
+
|
173
|
+
case tok
|
174
|
+
when Aptible::Resource::Base then tok.access_token
|
175
|
+
when Fridge::AccessToken then tok.to_s
|
176
|
+
when String then tok
|
177
|
+
else
|
178
|
+
raise "Unrecognized token: #{tok.class}: #{tok}"
|
179
|
+
end
|
180
|
+
end
|
172
181
|
end
|
173
182
|
end
|
174
183
|
end
|
data/lib/aptible/auth/version.rb
CHANGED
@@ -31,6 +31,7 @@ describe Aptible::Auth::Token do
|
|
31
31
|
Aptible::Auth::Token.any_instance.should_receive(
|
32
32
|
:authenticate_client
|
33
33
|
).with 'id', 'secret', 'user@example.com', {}
|
34
|
+
|
34
35
|
described_class.create(
|
35
36
|
client_id: 'id',
|
36
37
|
client_secret: 'secret',
|
@@ -38,6 +39,34 @@ describe Aptible::Auth::Token do
|
|
38
39
|
)
|
39
40
|
end
|
40
41
|
|
42
|
+
it 'should #authenticate_impersonate if passed user_href' do
|
43
|
+
Aptible::Auth::Token.any_instance.should_receive(
|
44
|
+
:authenticate_impersonate
|
45
|
+
).with('foo.href', 'aptible:user:href', {})
|
46
|
+
described_class.create(user_href: 'foo.href')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should #authenticate_impersonate if passed organization_href' do
|
50
|
+
Aptible::Auth::Token.any_instance.should_receive(
|
51
|
+
:authenticate_impersonate
|
52
|
+
).with('foo.href', 'aptible:organization:href', {})
|
53
|
+
described_class.create(organization_href: 'foo.href')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should #authenticate_impersonate if passed user_email' do
|
57
|
+
Aptible::Auth::Token.any_instance.should_receive(
|
58
|
+
:authenticate_impersonate
|
59
|
+
).with('foo@com', 'aptible:user:email', {})
|
60
|
+
described_class.create(user_email: 'foo@com')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should #authenticate_impersonate if passed user_token' do
|
64
|
+
Aptible::Auth::Token.any_instance.should_receive(
|
65
|
+
:authenticate_impersonate
|
66
|
+
).with('tok tok tok', 'aptible:token', {})
|
67
|
+
described_class.create(user_token: 'tok tok tok')
|
68
|
+
end
|
69
|
+
|
41
70
|
it 'should not alter the hash it receives' do
|
42
71
|
options = { email: 'some email' }
|
43
72
|
options_before = options.dup
|
@@ -140,7 +169,7 @@ describe Aptible::Auth::Token do
|
|
140
169
|
end
|
141
170
|
end
|
142
171
|
|
143
|
-
describe '#authenticate_impersonate' do
|
172
|
+
describe '#authenticate_impersonate (user email)' do
|
144
173
|
let(:args) { ['foo@bar.com', 'aptible:user:email', {}] }
|
145
174
|
before { oauth.stub_chain(:token_exchange, :get_token) { response } }
|
146
175
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptible-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Macreery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aptible-billing
|
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
221
|
version: '0'
|
222
222
|
requirements: []
|
223
223
|
rubyforge_project:
|
224
|
-
rubygems_version: 2.
|
224
|
+
rubygems_version: 2.6.13
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: Ruby client for auth.aptible.com
|