aptible-auth 1.0.0 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ede2aea57edbfadb1a51756f9fa295e9f1c8b30c
4
- data.tar.gz: 53b4f0c8b17c5a02656b8b4ed46bdb179e0db132
2
+ SHA256:
3
+ metadata.gz: 41cc5579815eeb97458ce8ec7331660f45d72a4060048253561dc35f9e2d915f
4
+ data.tar.gz: 792e65542c8a8d367ae7c50217b19bc60fa37696f39c265bed0acb4b513e8f31
5
5
  SHA512:
6
- metadata.gz: ccc21dfad37bfb72ba7fc3023f722f0d2735bc7810b184d74d06e6574c78a6dfa2e8a0c59ef7c8c21678e1f70a2f9e7f4bdcf9799ba15911bc5ea553f6e8c9e9
7
- data.tar.gz: e9c29c5181097c1d90155086144c013453c7d11ffd5c1cfe3d6c922b025d28412adaea44e2ce7fa3da354b622a303e02878ff8778bb440b495f94edc33089a70
6
+ metadata.gz: ecadb75dec853d60d059c4d75202da98187e343482d93629c2919ee8cd4289d018f20f6ca58dc4cf99d3f5abf62fc565e1ee2f5d95882d3cf1a7b09d0ab2dff5
7
+ data.tar.gz: 967e56ed114a1580dba1affaeb12d55a1d7cb34e3535c19f775ab6c6793494a378f19f552d2b2ab339dab4b6b0e39a6c20a26d49da498ed431f4c3e82d890985
@@ -0,0 +1 @@
1
+ * @dawenster
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea
@@ -1,7 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - "2.0"
5
- - "2.1"
6
4
  - "2.2"
7
- - jruby-9.0.5.0
5
+ - "2.3"
6
+ - "2.5"
7
+ - "2.6"
data/Gemfile CHANGED
@@ -1,7 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- gem 'activesupport', '~> 4.0'
4
- gem 'rack', '~> 1.6'
5
-
6
- # Specify your gem's dependencies in aptible-auth.gemspec
7
2
  gemspec
data/README.md CHANGED
@@ -14,8 +14,6 @@ Add the following line to your application's Gemfile.
14
14
 
15
15
  And then run `bundle install`.
16
16
 
17
- A forked version of the OAuth2 gem is necessary until [intridea/oauth2#165](https://github.com/intridea/oauth2/pull/165) and [intridea/oauth2#166](https://github.com/intridea/oauth2/pull/166) are merged.
18
-
19
17
  ## Usage
20
18
 
21
19
  First, get a token:
@@ -60,7 +58,5 @@ end
60
58
 
61
59
  MIT License, see [LICENSE](LICENSE.md) for details.
62
60
 
63
- Copyright (c) 2014 [Aptible](https://www.aptible.com) and contributors.
64
-
65
- [<img src="https://s.gravatar.com/avatar/9b58236204e844e3181e43e05ddb0809?s=60" style="border-radius: 50%;" alt="@sandersonet" />](https://github.com/sandersonet)
61
+ Copyright (c) 2019 [Aptible](https://www.aptible.com) and contributors.
66
62
 
data/Rakefile CHANGED
@@ -4,5 +4,5 @@ begin
4
4
  require 'aptible/tasks'
5
5
  Aptible::Tasks.load_tasks
6
6
  rescue LoadError
7
- $stderr.puts 'Skipping Aptible::Tasks initialization...'
7
+ warn 'Skipping Aptible::Tasks initialization...'
8
8
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
@@ -19,16 +20,14 @@ Gem::Specification.new do |spec|
19
20
  spec.test_files = spec.files.grep(%r{^spec/})
20
21
  spec.require_paths = ['lib']
21
22
 
22
- spec.add_dependency 'aptible-billing'
23
- spec.add_dependency 'aptible-resource', '~> 1.0.0'
23
+ spec.add_dependency 'aptible-resource', '~> 1.0'
24
24
  spec.add_dependency 'gem_config'
25
- spec.add_dependency 'oauth2-aptible', '~> 0.10.0'
25
+ spec.add_dependency 'oauth2', '~> 1.4'
26
26
 
27
- spec.add_development_dependency 'bundler', '~> 1.3'
28
- spec.add_development_dependency 'aptible-tasks', '>= 0.2.0'
27
+ spec.add_development_dependency 'aptible-tasks', '>= 0.6.0'
28
+ spec.add_development_dependency 'pry'
29
29
  spec.add_development_dependency 'rake'
30
- spec.add_development_dependency 'rspec', '~> 2.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
31
  spec.add_development_dependency 'rspec-its'
32
- spec.add_development_dependency 'pry'
33
32
  spec.add_development_dependency 'timecop', '~> 0.8.1'
34
33
  end
@@ -1,11 +1,10 @@
1
- require 'aptible/billing'
2
-
3
1
  module Aptible
4
2
  module Auth
5
3
  class Organization < Resource
6
4
  has_many :roles
7
5
  has_many :users
8
6
  has_many :invitations
7
+ has_many :whitelist_memberships
9
8
  belongs_to :security_officer
10
9
 
11
10
  field :id
@@ -22,17 +21,8 @@ module Aptible
22
21
  field :security_alert_email
23
22
  field :ops_alert_email
24
23
  field :security_officer_id
25
-
26
- def billing_detail
27
- @billing_detail ||= Aptible::Billing::BillingDetail.find(
28
- id, token: token, headers: headers
29
- )
30
- end
31
-
32
- def can_manage_compliance?
33
- return false unless billing_detail
34
- %w(production pilot).include?(billing_detail.plan)
35
- end
24
+ field :enterprise
25
+ field :sso_enforced
36
26
 
37
27
  def privileged_roles
38
28
  roles.select(&:privileged?)
@@ -40,6 +30,7 @@ module Aptible
40
30
 
41
31
  def accounts
42
32
  return @accounts if @accounts
33
+
43
34
  require 'aptible/api'
44
35
 
45
36
  accounts = Aptible::Api::Account.all(token: token, headers: headers)
@@ -47,6 +38,17 @@ module Aptible
47
38
  (link = account.links[:organization]) && link.href == href
48
39
  end
49
40
  end
41
+
42
+ # SamlConfiguration is a dependent object that does not
43
+ # have a link until created. So, we create the link for it
44
+ # to allow HyperResource to successfully create the object.
45
+ # Afterwords, we can directly manage the SamlConfiguration
46
+ def create_saml_configuration!(params)
47
+ HyperResource::Link.new(
48
+ self,
49
+ 'href' => "#{href}/saml_configurations"
50
+ ).post(self.class.normalize_params(params))
51
+ end
50
52
  end
51
53
  end
52
54
  end
@@ -0,0 +1,6 @@
1
+ module Aptible
2
+ module Auth
3
+ class ReauthenticateOrganization < Resource
4
+ end
5
+ end
6
+ end
@@ -23,3 +23,6 @@ require 'aptible/auth/session'
23
23
  require 'aptible/auth/token'
24
24
  require 'aptible/auth/user'
25
25
  require 'aptible/auth/ssh_key'
26
+ require 'aptible/auth/saml_configuration'
27
+ require 'aptible/auth/whitelist_membership'
28
+ require 'aptible/auth/reauthenticate_organization'
@@ -0,0 +1,16 @@
1
+ module Aptible
2
+ module Auth
3
+ class SamlConfiguration < Resource
4
+ belongs_to :organization
5
+
6
+ field :id
7
+ field :entity_id
8
+ field :sign_in_url
9
+ field :name_format
10
+ field :certificate
11
+ field :handle
12
+ field :created_at, type: Time
13
+ field :updated_at, type: Time
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,6 @@
1
1
  require 'oauth2'
2
+ require 'oauth2/response_parser'
3
+ require 'oauth2/strategy/token_exchange'
2
4
 
3
5
  module Aptible
4
6
  module Auth
@@ -144,7 +146,7 @@ module Aptible
144
146
  private_key = parse_private_key(secret)
145
147
  {
146
148
  private_key: private_key,
147
- algorithm: "RS#{key_length(private_key) / 2}"
149
+ algorithm: "RS#{key_length(private_key) / 2}"
148
150
  }
149
151
  end
150
152
 
@@ -3,6 +3,7 @@ module Aptible
3
3
  class User < Resource
4
4
  has_many :roles
5
5
  has_many :ssh_keys
6
+ has_many :whitelist_memberhips
6
7
 
7
8
  field :id
8
9
  field :name
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module Auth
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.2.3'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1,11 @@
1
+ module Aptible
2
+ module Auth
3
+ class WhitelistMembership < Resource
4
+ belongs_to :organization
5
+ embeds_one :user
6
+
7
+ field :id
8
+ field :created_at, type: Time
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # rubocop:disable all
2
+ # NOTE: This code has been in oauth2 master since 2018 but is awaiting a 2.0 release of oauth2
3
+ OAuth2::Response.register_parser(:json, ['application/json', 'text/javascript', 'application/hal+json', 'application/vnd.collection+json', 'application/vnd.api+json']) do |body|
4
+ MultiJson.load(body) rescue body # rubocop:disable RescueModifier
5
+ end
@@ -0,0 +1,40 @@
1
+ # rubocop:disable all
2
+ module OAuth2
3
+ module Strategy
4
+ # The Token Exchange strategy
5
+ #
6
+ # @see https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-03#section-4.1
7
+ class TokenExchange < Base
8
+ GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:token-exchange'
9
+
10
+ # Not used for this strategy
11
+ #
12
+ # @raise [NotImplementedError]
13
+ def authorize_url
14
+ fail(NotImplementedError, 'The authorization endpoint is not used in this strategy')
15
+ end
16
+
17
+ # Retrieve an access token given the specified End User username and password.
18
+ #
19
+ # @param [String] username the End User username
20
+ # @param [String] password the End User password
21
+ # @param [Hash] params additional params
22
+ def get_token(actor_token, actor_token_type, subject_token, subject_token_type, params = {}, opts = {})
23
+ params = {'grant_type' => GRANT_TYPE,
24
+ 'actor_token' => actor_token,
25
+ 'actor_token_type' => actor_token_type,
26
+ 'subject_token' => subject_token,
27
+ 'subject_token_type' => subject_token_type
28
+ }.merge(params)
29
+ @client.get_token(params, opts)
30
+ end
31
+ end
32
+ end
33
+
34
+ # Add strategy to OAuth2::Client
35
+ class Client
36
+ def token_exchange
37
+ @token_exchange ||= OAuth2::Strategy::TokenExchange.new(self)
38
+ end
39
+ end
40
+ end
@@ -1,36 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Aptible::Auth::Organization do
4
- describe '#can_manage_compliance?' do
5
- before { subject.stub(:billing_detail) { billing_detail } }
6
-
7
- context 'without a billing detail' do
8
- let(:billing_detail) { nil }
9
- it 'should return false' do
10
- expect(subject.can_manage_compliance?).to eq false
11
- end
12
- end
13
-
14
- context 'with a billing detail' do
15
- let(:billing_detail) { double Aptible::Billing::BillingDetail }
16
-
17
- it 'should return true with production plan' do
18
- billing_detail.stub(:plan) { 'production' }
19
- expect(subject.can_manage_compliance?).to eq true
20
- end
21
-
22
- it 'should return false with development plan' do
23
- billing_detail.stub(:plan) { 'development' }
24
- expect(subject.can_manage_compliance?).to eq false
25
- end
26
-
27
- it 'should return false with platform plan' do
28
- billing_detail.stub(:plan) { 'platform' }
29
- expect(subject.can_manage_compliance?).to eq false
30
- end
31
- end
32
- end
33
-
34
4
  describe '#security_officer' do
35
5
  let(:user) { double 'Aptible::Auth::User' }
36
6
 
@@ -82,7 +82,7 @@ describe Aptible::Auth::Token do
82
82
  end
83
83
 
84
84
  describe '#authenticate_user' do
85
- let(:args) { %w(user@example.com foobar) }
85
+ let(:args) { %w[user@example.com foobar] }
86
86
 
87
87
  before { oauth.stub_chain(:password, :get_token) { response } }
88
88
 
@@ -116,7 +116,7 @@ describe Aptible::Auth::Token do
116
116
  end
117
117
 
118
118
  describe '#authenticate_client' do
119
- let(:args) { %w(id secret user@example.com) }
119
+ let(:args) { %w[id secret user@example.com] }
120
120
 
121
121
  before do
122
122
  subject.stub(:signing_params_from_secret) { { algorithm: 'foobar' } }
@@ -0,0 +1,58 @@
1
+ # rubocop:disable all
2
+ require 'oauth2'
3
+ require 'oauth2/strategy/token_exchange'
4
+ RSpec.describe OAuth2::Strategy::TokenExchange do
5
+ let(:client) do
6
+ cli = OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com')
7
+ cli.connection.build do |b|
8
+ b.adapter :test do |stub|
9
+ stub.post('/oauth/token') do |env|
10
+ case @mode
11
+ when 'formencoded'
12
+ [200, {'Content-Type' => 'application/x-www-form-urlencoded'}, 'expires_in=600&access_token=salmon&refresh_token=trout']
13
+ when 'json'
14
+ [200, {'Content-Type' => 'application/json'}, '{"expires_in":600,"access_token":"salmon","refresh_token":"trout"}']
15
+ end
16
+ end
17
+ end
18
+ end
19
+ cli
20
+ end
21
+ subject { client.token_exchange }
22
+
23
+ describe '#authorize_url' do
24
+ it 'raises NotImplementedError' do
25
+ expect { subject.authorize_url }.to raise_error(NotImplementedError)
26
+ end
27
+ end
28
+
29
+ %w(json formencoded).each do |mode|
30
+ describe "#get_token (#{mode})" do
31
+ before do
32
+ @mode = mode
33
+ @access = subject.get_token('actor token', 'actor token type', 'subject token', 'subject token type')
34
+ end
35
+
36
+ it 'returns AccessToken with same Client' do
37
+ expect(@access.client).to eq(client)
38
+ end
39
+
40
+ it 'returns AccessToken with #token' do
41
+ expect(@access.token).to eq('salmon')
42
+ end
43
+
44
+ it 'returns AccessToken with #refresh_token' do
45
+ expect(@access.refresh_token).to eq('trout')
46
+ end
47
+
48
+ it 'returns AccessToken with #expires_in' do
49
+ expect(@access.expires_in).to eq(600)
50
+ end
51
+
52
+ it 'returns AccessToken with #expires_at' do
53
+ expect(@access.expires_at).not_to be_nil
54
+ end
55
+ end
56
+ end
57
+
58
+ end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-27 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: aptible-billing
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: aptible-resource
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 1.0.0
19
+ version: '1.0'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 1.0.0
26
+ version: '1.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: gem_config
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,47 +39,47 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
- name: oauth2-aptible
42
+ name: oauth2
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 0.10.0
47
+ version: '1.4'
62
48
  type: :runtime
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 0.10.0
54
+ version: '1.4'
69
55
  - !ruby/object:Gem::Dependency
70
- name: bundler
56
+ name: aptible-tasks
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: '1.3'
61
+ version: 0.6.0
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '1.3'
68
+ version: 0.6.0
83
69
  - !ruby/object:Gem::Dependency
84
- name: aptible-tasks
70
+ name: pry
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - ">="
88
74
  - !ruby/object:Gem::Version
89
- version: 0.2.0
75
+ version: '0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
- version: 0.2.0
82
+ version: '0'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: rake
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +100,14 @@ dependencies:
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: '2.0'
103
+ version: '3.0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: '2.0'
110
+ version: '3.0'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: rspec-its
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -136,20 +122,6 @@ dependencies:
136
122
  - - ">="
137
123
  - !ruby/object:Gem::Version
138
124
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: pry
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
125
  - !ruby/object:Gem::Dependency
154
126
  name: timecop
155
127
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +143,7 @@ executables: []
171
143
  extensions: []
172
144
  extra_rdoc_files: []
173
145
  files:
146
+ - ".github/CODEOWNERS"
174
147
  - ".gitignore"
175
148
  - ".rspec"
176
149
  - ".travis.yml"
@@ -186,26 +159,32 @@ files:
186
159
  - lib/aptible/auth/invitation.rb
187
160
  - lib/aptible/auth/membership.rb
188
161
  - lib/aptible/auth/organization.rb
162
+ - lib/aptible/auth/reauthenticate_organization.rb
189
163
  - lib/aptible/auth/resource.rb
190
164
  - lib/aptible/auth/role.rb
165
+ - lib/aptible/auth/saml_configuration.rb
191
166
  - lib/aptible/auth/session.rb
192
167
  - lib/aptible/auth/ssh_key.rb
193
168
  - lib/aptible/auth/token.rb
194
169
  - lib/aptible/auth/user.rb
195
170
  - lib/aptible/auth/version.rb
171
+ - lib/aptible/auth/whitelist_membership.rb
172
+ - lib/oauth2/response_parser.rb
173
+ - lib/oauth2/strategy/token_exchange.rb
196
174
  - spec/aptible/auth/agent_spec.rb
197
175
  - spec/aptible/auth/organization_spec.rb
198
176
  - spec/aptible/auth/resource_spec.rb
199
177
  - spec/aptible/auth/token_spec.rb
200
178
  - spec/aptible/auth/user_spec.rb
201
179
  - spec/aptible/auth_spec.rb
180
+ - spec/oauth2/lib/token_exchange_spec.rb
202
181
  - spec/shared/set_env.rb
203
182
  - spec/spec_helper.rb
204
183
  homepage: https://github.com/aptible/aptible-auth-ruby
205
184
  licenses:
206
185
  - MIT
207
186
  metadata: {}
208
- post_install_message:
187
+ post_install_message:
209
188
  rdoc_options: []
210
189
  require_paths:
211
190
  - lib
@@ -220,9 +199,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
199
  - !ruby/object:Gem::Version
221
200
  version: '0'
222
201
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.6.13
225
- signing_key:
202
+ rubygems_version: 3.0.3
203
+ signing_key:
226
204
  specification_version: 4
227
205
  summary: Ruby client for auth.aptible.com
228
206
  test_files:
@@ -232,5 +210,6 @@ test_files:
232
210
  - spec/aptible/auth/token_spec.rb
233
211
  - spec/aptible/auth/user_spec.rb
234
212
  - spec/aptible/auth_spec.rb
213
+ - spec/oauth2/lib/token_exchange_spec.rb
235
214
  - spec/shared/set_env.rb
236
215
  - spec/spec_helper.rb