auth0 4.17.0 → 5.1.1

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +29 -8
  3. data/.github/CODEOWNERS +1 -1
  4. data/.github/ISSUE_TEMPLATE/config.yml +8 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +39 -0
  6. data/.github/ISSUE_TEMPLATE/report_a_bug.md +55 -0
  7. data/.gitignore +1 -1
  8. data/.yardoc/checksums +22 -0
  9. data/.yardoc/complete +0 -0
  10. data/.yardoc/object_types +0 -0
  11. data/.yardoc/objects/root.dat +0 -0
  12. data/.yardoc/proxy_types +0 -0
  13. data/CHANGELOG.md +79 -0
  14. data/Gemfile +0 -1
  15. data/README.md +81 -8
  16. data/Rakefile +0 -22
  17. data/auth0.gemspec +4 -3
  18. data/examples/ruby-api/.gitignore +0 -6
  19. data/lib/auth0/api/authentication_endpoints.rb +22 -226
  20. data/lib/auth0/api/v2.rb +8 -4
  21. data/lib/auth0/api/v2/branding.rb +66 -0
  22. data/lib/auth0/api/v2/connections.rb +3 -0
  23. data/lib/auth0/api/v2/jobs.rb +3 -1
  24. data/lib/auth0/api/v2/organizations.rb +335 -0
  25. data/lib/auth0/api/v2/tickets.rb +14 -2
  26. data/lib/auth0/api/v2/users.rb +20 -6
  27. data/lib/auth0/exception.rb +4 -7
  28. data/lib/auth0/mixins.rb +0 -1
  29. data/lib/auth0/mixins/access_token_struct.rb +2 -2
  30. data/lib/auth0/mixins/api_token_struct.rb +2 -2
  31. data/lib/auth0/mixins/initializer.rb +4 -8
  32. data/lib/auth0/mixins/permission_struct.rb +2 -2
  33. data/lib/auth0/mixins/validation.rb +15 -1
  34. data/lib/auth0/version.rb +1 -1
  35. data/spec/integration/lib/auth0/api/api_authentication_spec.rb +1 -1
  36. data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +1 -1
  37. data/spec/integration/lib/auth0/api/v2/api_roles_spec.rb +1 -1
  38. data/spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb +1 -1
  39. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +1 -1
  40. data/spec/lib/auth0/api/v2/branding_spec.rb +70 -0
  41. data/spec/lib/auth0/api/v2/connections_spec.rb +4 -0
  42. data/spec/lib/auth0/api/v2/jobs_spec.rb +11 -0
  43. data/spec/lib/auth0/api/v2/organizations_spec.rb +593 -0
  44. data/spec/lib/auth0/api/v2/roles_spec.rb +4 -4
  45. data/spec/lib/auth0/api/v2/tickets_spec.rb +55 -0
  46. data/spec/lib/auth0/api/v2/users_spec.rb +39 -10
  47. data/spec/lib/auth0/client_spec.rb +79 -9
  48. data/spec/lib/auth0/mixins/validation_spec.rb +32 -0
  49. data/spec/spec_helper.rb +6 -1
  50. data/spec/support/credentials.rb +0 -19
  51. metadata +49 -44
  52. data/.github/ISSUE_TEMPLATE.md +0 -39
  53. data/Gemfile.lock +0 -227
  54. data/deploy_documentation.sh +0 -29
  55. data/doc_config/templates/default/fulldoc/html/css/full_list.css +0 -79
  56. data/doc_config/templates/default/fulldoc/html/css/style.css +0 -546
  57. data/doc_config/templates/default/layout/html/breadcrumb.erb +0 -11
  58. data/doc_config/templates/default/layout/html/footer.erb +0 -115
  59. data/doc_config/templates/default/layout/html/headers.erb +0 -17
  60. data/doc_config/templates/default/layout/html/layout.erb +0 -27
  61. data/lib/auth0/api/v1.rb +0 -19
  62. data/lib/auth0/api/v1/clients.rb +0 -58
  63. data/lib/auth0/api/v1/connections.rb +0 -68
  64. data/lib/auth0/api/v1/logs.rb +0 -43
  65. data/lib/auth0/api/v1/rules.rb +0 -57
  66. data/lib/auth0/api/v1/users.rb +0 -227
  67. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +0 -703
@@ -38,23 +38,20 @@ module Auth0
38
38
  class MissingUserId < Auth0::Exception; end
39
39
  # exception for unset client_id
40
40
  class MissingClientId < Auth0::Exception; end
41
+ # exception for unset organization_id
42
+ class MissingOrganizationId < Auth0::Exception; end
41
43
  # exception for an unset parameter
42
44
  class MissingParameter < Auth0::Exception; end
43
45
  # Api v2 access denied
44
46
  class AccessDenied < Auth0::HTTPError; end
45
47
  # Invalid parameter passed, e.g. empty where ID is required
46
48
  class InvalidParameter < Auth0::Exception; end
47
- # Invalid Auth0 credentials either client_id/secret for API v1
48
- # or JWT for API v2/
49
+ # Invalid JWT
49
50
  class InvalidCredentials < Auth0::Exception; end
50
51
  # Invalid Auth0 API namespace
51
52
  class InvalidApiNamespace < Auth0::Exception; end
52
53
  # Auth0 API rate-limiting encountered
53
- # TODO: When making API-breaking changes, make this a subclass
54
- # of Auth0::HTTPError directly rather than Auth0::Unsupported.
55
- # It's currently under Unsupported to avoid breaking compatibility
56
- # with prior gem versions that treated 429 errors as unknown errors.
57
- class RateLimitEncountered < Auth0::Unsupported
54
+ class RateLimitEncountered < Auth0::HTTPError
58
55
  def reset
59
56
  Time.at(headers['X-RateLimit-Reset']).utc
60
57
  end
data/lib/auth0/mixins.rb CHANGED
@@ -11,7 +11,6 @@ require 'auth0/mixins/permission_struct'
11
11
  require 'auth0/mixins/validation'
12
12
 
13
13
  require 'auth0/api/authentication_endpoints'
14
- require 'auth0/api/v1'
15
14
  require 'auth0/api/v2'
16
15
 
17
16
  module Auth0
@@ -1,4 +1,4 @@
1
- AccessToken = Struct.new(
1
+ Auth0::AccessToken = Struct.new(
2
2
  :access_token,
3
3
  :expires_in,
4
4
  :refresh_token,
@@ -17,4 +17,4 @@ AccessToken = Struct.new(
17
17
  def token
18
18
  access_token
19
19
  end
20
- end
20
+ end
@@ -1,4 +1,4 @@
1
- ApiToken = Struct.new :access_token, :scope, :expires_in do
1
+ Auth0::ApiToken = Struct.new :access_token, :scope, :expires_in do
2
2
 
3
3
  def token
4
4
  access_token
@@ -7,4 +7,4 @@ ApiToken = Struct.new :access_token, :scope, :expires_in do
7
7
  def scopes
8
8
  scope.split
9
9
  end
10
- end
10
+ end
@@ -18,6 +18,7 @@ module Auth0
18
18
  extend Auth0::Api::AuthenticationEndpoints
19
19
  @client_id = options[:client_id]
20
20
  @client_secret = options[:client_secret]
21
+ @organization = options[:organization]
21
22
  initialize_api(options)
22
23
  end
23
24
 
@@ -40,7 +41,7 @@ module Auth0
40
41
  private
41
42
 
42
43
  def initialize_api(options)
43
- api_v2?(options) ? initialize_v2(options) : initialize_v1
44
+ initialize_v2(options)
44
45
  raise InvalidCredentials, 'Must supply a valid API token' if @token.nil?
45
46
  if options.fetch(:authorization, nil) == 'Basic'
46
47
  authorization_header_basic(options)
@@ -58,13 +59,8 @@ module Auth0
58
59
  def initialize_v2(options)
59
60
  extend Auth0::Api::V2
60
61
  @token = options[:access_token] || options[:token]
61
- @token = api_token.token if @token.nil? && @client_id && @client_secret
62
- end
63
-
64
- def initialize_v1
65
- extend Auth0::Api::V1
66
- raise InvalidCredentials, 'Invalid API v1 client_id and client_secret' if @client_id.nil? || @client_secret.nil?
67
- @token = obtain_access_token
62
+ api_identifier = options[:api_identifier] || "https://#{@domain}/api/v2/"
63
+ @token = api_token(audience: api_identifier).token if @token.nil? && @client_id && @client_secret
68
64
  end
69
65
 
70
66
  def api_v2?(options)
@@ -1,3 +1,3 @@
1
- Permission = Struct.new :permission_name, :resource_server_identifier do
1
+ Auth0::Permission = Struct.new :permission_name, :resource_server_identifier do
2
2
 
3
- end
3
+ end
@@ -23,7 +23,7 @@ module Auth0
23
23
  raise Auth0::InvalidParameter, 'Must supply an array of Permissions' unless permissions.kind_of?(Array)
24
24
  raise Auth0::MissingParameter, 'Must supply an array of Permissions' if permissions.empty?
25
25
  raise Auth0::InvalidParameter, 'All array elements must be Permissions' unless permissions.all? do |permission|
26
- permission.kind_of? Permission
26
+ permission.kind_of? ::Auth0::Permission
27
27
  end
28
28
  permissions.map { |permission| permission.to_h }
29
29
  end
@@ -100,11 +100,13 @@ module Auth0
100
100
  issuer = @context[:issuer]
101
101
  audience = @context[:audience]
102
102
  max_age = @context[:max_age]
103
+ org = @context[:organization]
103
104
 
104
105
  raise Auth0::InvalidParameter, 'Must supply a valid leeway' unless leeway.is_a?(Integer) && leeway >= 0
105
106
  raise Auth0::InvalidParameter, 'Must supply a valid nonce' unless nonce.nil? || !nonce.to_s.empty?
106
107
  raise Auth0::InvalidParameter, 'Must supply a valid issuer' unless issuer.nil? || !issuer.to_s.empty?
107
108
  raise Auth0::InvalidParameter, 'Must supply a valid audience' unless audience.nil? || !audience.to_s.empty?
109
+ raise Auth0::InvalidParameter, 'Must supply a valid organization' unless org.nil? || !org.to_s.empty?
108
110
 
109
111
  unless max_age.nil? || (max_age.is_a?(Integer) && max_age >= 0)
110
112
  raise Auth0::InvalidParameter, 'Must supply a valid max_age'
@@ -118,6 +120,7 @@ module Auth0
118
120
  validate_nonce(claims, nonce) if nonce
119
121
  validate_azp(claims, audience) if claims['aud'].is_a?(Array) && claims['aud'].count > 1
120
122
  validate_auth_time(claims, max_age, leeway) if max_age
123
+ validate_org(claims, org) if org
121
124
  end
122
125
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
123
126
 
@@ -184,6 +187,17 @@ module Auth0
184
187
  end
185
188
  end
186
189
 
190
+ def validate_org(claims, expected)
191
+ unless claims.key?('org_id') && claims['org_id'].is_a?(String)
192
+ raise Auth0::InvalidIdToken, 'Organization Id (org_id) claim must be a string present in the ID token'
193
+ end
194
+
195
+ unless expected == claims['org_id']
196
+ raise Auth0::InvalidIdToken, "Organization Id (org_id) claim value mismatch in the ID token; expected \"#{expected}\","\
197
+ " found \"#{claims['org_id']}\""
198
+ end
199
+ end
200
+
187
201
  def validate_azp(claims, expected)
188
202
  unless claims.key?('azp') && claims['azp'].is_a?(String)
189
203
  raise Auth0::InvalidIdToken, 'Authorized Party (azp) claim must be a string present in the ID token'
data/lib/auth0/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # current version of gem
2
2
  module Auth0
3
- VERSION = '4.17.0'.freeze
3
+ VERSION = '5.1.1'.freeze
4
4
  end
@@ -60,7 +60,7 @@ describe Auth0::Api::AuthenticationEndpoints do
60
60
  end
61
61
 
62
62
  it 'should return the userinfo' do
63
- tokens = @client.login(test_user_email, test_user_pwd, nil, nil)
63
+ tokens = @client.login_with_resource_owner(test_user_email, test_user_pwd)
64
64
  expect(@client.userinfo(tokens['access_token'])).to(
65
65
  include( 'email' => test_user_email )
66
66
  )
@@ -4,7 +4,7 @@ describe Auth0::Api::V2::Jobs do
4
4
 
5
5
  let(:client) { Auth0Client.new(v2_creds) }
6
6
  let(:username) { Faker::Internet.user_name }
7
- let(:email) { "#{entity_suffix}#{Faker::Internet.safe_email(username)}" }
7
+ let(:email) { "#{entity_suffix}#{Faker::Internet.safe_email(name: username)}" }
8
8
  let(:connection_id) do
9
9
  VCR.use_cassette('Auth0_Api_V2_Jobs/search_for_connection_id') do
10
10
  client.connections.find do |connection|
@@ -14,7 +14,7 @@ describe Auth0::Api::V2::Roles do
14
14
  @test_role_name = "#{entity_suffix}-test-role"
15
15
 
16
16
  @test_permission_name = "#{entity_suffix}-test-permission"
17
- @test_permission = Permission.new(@test_permission_name, @test_api_name)
17
+ @test_permission = ::Auth0::Permission.new(@test_permission_name , @test_api_name)
18
18
 
19
19
  VCR.use_cassette('Auth0_Api_V2_Roles/create_test_user') do
20
20
  @test_user ||= client.create_user(
@@ -6,7 +6,7 @@ describe Auth0::Api::V2::UserBlocks do
6
6
  before(:all) do
7
7
  @client = Auth0Client.new(v2_creds)
8
8
  username = Faker::Internet.user_name
9
- @email = "#{entity_suffix}#{Faker::Internet.safe_email(username)}"
9
+ @email = "#{entity_suffix}#{Faker::Internet.safe_email(name: username)}"
10
10
  password = Faker::Internet.password
11
11
  @user = client.create_user(username, 'email' => email,
12
12
  'password' => password,
@@ -14,7 +14,7 @@ describe Auth0::Api::V2::Users do
14
14
  @test_api_scope = 'test:scope'
15
15
 
16
16
  @test_permission_name = "#{entity_suffix}-test-permission-for-users"
17
- @test_permission = Permission.new("#{entity_suffix}-test-permission-for-users", @test_api_name)
17
+ @test_permission = ::Auth0::Permission.new("#{entity_suffix}-test-permission-for-users", @test_api_name)
18
18
 
19
19
  VCR.use_cassette('Auth0_Api_V2_Users/create_test_user') do
20
20
  @test_user ||= client.create_user(
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::Branding do
3
+ before :all do
4
+ dummy_instance = DummyClass.new
5
+ dummy_instance.extend(Auth0::Api::V2::Branding)
6
+ dummy_instance.extend(Auth0::Mixins::Initializer)
7
+ @instance = dummy_instance
8
+ end
9
+
10
+ context '.branding' do
11
+ it { expect(@instance).to respond_to(:branding) }
12
+
13
+ it 'is expected to call get /api/v2/branding' do
14
+ expect(@instance).to receive(:get).with('/api/v2/branding')
15
+ expect { @instance.branding }.not_to raise_error
16
+ end
17
+
18
+ it 'is expected to respond to a get_branding method' do
19
+ expect(@instance).to respond_to(:get_branding)
20
+ end
21
+ end
22
+
23
+ context '.patch_branding' do
24
+ it { expect(@instance).to respond_to(:patch_branding) }
25
+ it 'is expected to call post /api/v2/branding' do
26
+ expect(@instance).to receive(:patch).with(
27
+ '/api/v2/branding',
28
+ template: 'Test'
29
+ )
30
+ expect { @instance.patch_branding({ template: 'Test' }) }.not_to raise_error
31
+ end
32
+
33
+ it 'is expected to respond to a get_branding method' do
34
+ expect(@instance).to respond_to(:update_branding)
35
+ end
36
+ end
37
+
38
+ context '.branding_templates_for_universal_login' do
39
+ it { expect(@instance).to respond_to(:branding) }
40
+
41
+ it 'is expected to call get /api/v2/branding/templates/universal-login' do
42
+ expect(@instance).to receive(:get).with('/api/v2/branding/templates/universal-login')
43
+ expect { @instance.branding_templates_for_universal_login }.not_to raise_error
44
+ end
45
+
46
+ it 'is expected to respond to a get_branding_templates_for_universal_login method' do
47
+ expect(@instance).to respond_to(:get_branding_templates_for_universal_login)
48
+ end
49
+ end
50
+
51
+ context '.put_branding_templates_for_universal_login' do
52
+ it { expect(@instance).to respond_to(:put_branding_templates_for_universal_login) }
53
+ it 'is expected to call put /api/v2/branding/templates/universal-login' do
54
+ expect(@instance).to receive(:put).with(
55
+ '/api/v2/branding/templates/universal-login', template: 'Template'
56
+ )
57
+ expect do
58
+ @instance.put_branding_templates_for_universal_login(template: 'Template')
59
+ end.not_to raise_error
60
+ end
61
+ end
62
+
63
+ context '.delete_branding_templates_for_universal_login' do
64
+ it { expect(@instance).to respond_to(:delete_branding_templates_for_universal_login) }
65
+ it 'is expected to call delete /api/v2/branding/templates/universal-login' do
66
+ expect(@instance).to receive(:delete).with('/api/v2/branding/templates/universal-login')
67
+ expect { @instance.delete_branding_templates_for_universal_login() }.not_to raise_error
68
+ end
69
+ end
70
+ end
@@ -14,6 +14,7 @@ describe Auth0::Api::V2::Connections do
14
14
  expect(@instance).to receive(:get).with(
15
15
  '/api/v2/connections',
16
16
  strategy: nil,
17
+ name: nil,
17
18
  fields: nil,
18
19
  include_fields: nil,
19
20
  page: nil,
@@ -28,6 +29,7 @@ describe Auth0::Api::V2::Connections do
28
29
  include_fields: true,
29
30
  fields: 'name',
30
31
  strategy: nil,
32
+ name: nil,
31
33
  page: nil,
32
34
  per_page: nil
33
35
  )
@@ -42,6 +44,7 @@ describe Auth0::Api::V2::Connections do
42
44
  include_fields: true,
43
45
  fields: 'name,strategy',
44
46
  strategy: nil,
47
+ name: nil,
45
48
  page: nil,
46
49
  per_page: nil
47
50
  )
@@ -56,6 +59,7 @@ describe Auth0::Api::V2::Connections do
56
59
  page: 1,
57
60
  per_page: 10,
58
61
  strategy: nil,
62
+ name: nil,
59
63
  fields: nil,
60
64
  include_fields: nil
61
65
  )
@@ -119,6 +119,17 @@ describe Auth0::Api::V2::Jobs do
119
119
  )
120
120
  end
121
121
 
122
+ it 'expect client to accept organization_id' do
123
+ expect(@instance).to receive(:post).with('/api/v2/jobs/verification-email',
124
+ user_id: 'user_id',
125
+ organization_id: 'org_id'
126
+ )
127
+
128
+ expect {
129
+ @instance.send_verification_email('user_id', organization_id: 'org_id')
130
+ }.not_to raise_error
131
+ end
132
+
122
133
  it 'should raise an error if the user_id is empty' do
123
134
  expect do
124
135
  @instance.send_verification_email('')
@@ -0,0 +1,593 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::Organizations do
3
+ before :all do
4
+ dummy_instance = DummyClass.new
5
+ dummy_instance.extend(Auth0::Api::V2::Organizations)
6
+ @instance = dummy_instance
7
+ end
8
+
9
+ context '.organizations' do
10
+ it 'is expected to respond to a organizations method' do
11
+ expect(@instance).to respond_to(:organizations)
12
+ end
13
+
14
+ it 'is expected to respond to a get_organizations method' do
15
+ expect(@instance).to respond_to(:get_organizations)
16
+ end
17
+
18
+ it 'is expected to get /api/v2/organizations' do
19
+ expect(@instance).to receive(:get).with(
20
+ '/api/v2/organizations',
21
+ per_page: nil,
22
+ page: nil,
23
+ include_totals: nil
24
+ )
25
+ expect { @instance.organizations }.not_to raise_error
26
+ end
27
+
28
+ it 'is expected to get /api/v2/organizations with custom parameters' do
29
+ expect(@instance).to receive(:get).with(
30
+ '/api/v2/organizations',
31
+ per_page: 10,
32
+ page: 1,
33
+ include_totals: true
34
+ )
35
+ expect do
36
+ @instance.organizations(
37
+ per_page: 10,
38
+ page: 1,
39
+ include_totals: true
40
+ )
41
+ end.not_to raise_error
42
+ end
43
+ end
44
+
45
+ context '.organization' do
46
+ it 'is expected to respond to a user method' do
47
+ expect(@instance).to respond_to(:organization)
48
+ end
49
+
50
+ it 'is expected to call get request to /api/v2/users/org_id' do
51
+ expect(@instance).to receive(:get).with(
52
+ '/api/v2/organizations/org_id'
53
+ )
54
+ expect { @instance.organization('org_id') }.not_to raise_error
55
+ end
56
+
57
+ it 'is expected to raise an exception when the organization ID is empty' do
58
+ expect { @instance.organization(nil) }.to raise_exception(Auth0::MissingOrganizationId)
59
+ end
60
+ end
61
+
62
+ context '.create_organization' do
63
+ it 'is expected to respond to a create_organization method' do
64
+ expect(@instance).to respond_to(:create_organization)
65
+ end
66
+
67
+ it 'is expected to post to /api/v2/organizations' do
68
+ expect(@instance).to receive(:post).with(
69
+ '/api/v2/organizations',
70
+ name: 'test_org'
71
+ )
72
+ expect do
73
+ @instance.create_organization(
74
+ name: 'test_org'
75
+ )
76
+ end.not_to raise_error
77
+ end
78
+ end
79
+
80
+ context '.delete_organization' do
81
+ it 'is expected to respond to a delete_organization method' do
82
+ expect(@instance).to respond_to :delete_organization
83
+ end
84
+
85
+ it 'is expected to call delete to /api/v2/organizations/org_id' do
86
+ expect(@instance).to receive(:delete).with('/api/v2/organizations/org_id')
87
+ expect { @instance.delete_organization('org_id') }.not_to raise_error
88
+ end
89
+
90
+ it 'is expected not to delete /api/v2/organizations if organization_id is blank' do
91
+ expect(@instance).not_to receive(:delete)
92
+ expect { @instance.delete_organization(nil) }.to raise_exception(
93
+ Auth0::MissingOrganizationId
94
+ )
95
+ end
96
+ end
97
+
98
+ context '.organization_by_name' do
99
+ it 'is expected to respond to a user method' do
100
+ expect(@instance).to respond_to(:organization_by_name)
101
+ end
102
+
103
+ it 'is expected to call get request to /api/v2/users/org_id' do
104
+ expect(@instance).to receive(:get).with(
105
+ '/api/v2/organizations/name/org_id'
106
+ )
107
+ expect { @instance.organization_by_name('org_id') }.not_to raise_error
108
+ end
109
+
110
+ it 'is expected to raise an exception when the organization ID is empty' do
111
+ expect { @instance.organization_by_name(nil) }.to raise_exception(Auth0::InvalidParameter)
112
+ end
113
+ end
114
+
115
+
116
+ context '.patch_organization' do
117
+ it 'is expected to respond to a patch_organization method' do
118
+ expect(@instance).to respond_to(:patch_organization)
119
+ end
120
+
121
+ it 'is expected to respond to a update_organization method' do
122
+ expect(@instance).to respond_to(:update_organization)
123
+ end
124
+
125
+ it 'is expected to patch /api/v2/organizations/org_id' do
126
+ expect(@instance).to receive(:patch).with(
127
+ '/api/v2/organizations/org_id',
128
+ name: 'name'
129
+ )
130
+ @instance.patch_organization(
131
+ 'org_id',
132
+ name: 'name'
133
+ )
134
+ end
135
+
136
+ it 'is expected to raise an exception when the organization id is empty' do
137
+ expect { @instance.patch_organization(nil, 'BODY') }.to raise_exception(Auth0::MissingOrganizationId)
138
+ end
139
+
140
+ it 'is expected to raise an error when the body is empty' do
141
+ expect { @instance.patch_organization('org_id', nil) }.to raise_error 'Must supply a valid body'
142
+ end
143
+ end
144
+
145
+ context '.get_organizations_enabled_connections' do
146
+ it 'is expected to respond to a get_organizations_enabled_connections method' do
147
+ expect(@instance).to respond_to(:get_organizations_enabled_connections)
148
+ end
149
+
150
+ it 'is expected to raise an exception when the org ID is empty' do
151
+ expect { @instance.get_organizations_enabled_connections(nil) }.to raise_exception(Auth0::MissingOrganizationId)
152
+ end
153
+
154
+ it 'is expected to get enabled_connections for an org' do
155
+ expect(@instance).to receive(:get).with(
156
+ '/api/v2/organizations/org_id/enabled_connections'
157
+ )
158
+ expect { @instance.get_organizations_enabled_connections('org_id') }.not_to raise_error
159
+ end
160
+
161
+ it 'is expected to get enabled_connections for an org' do
162
+ expect(@instance).to receive(:get).with(
163
+ '/api/v2/organizations/org_id/enabled_connections'
164
+ )
165
+ expect do
166
+ @instance.get_organizations_enabled_connections('org_id')
167
+ end.not_to raise_error
168
+ end
169
+ end
170
+
171
+ context '.get_organizations_enabled_connection' do
172
+ it 'is expected to respond to a get_organizations_enabled_connection method' do
173
+ expect(@instance).to respond_to(:get_organizations_enabled_connection)
174
+ end
175
+
176
+ it 'is expected to raise an exception when the org ID is empty' do
177
+ expect { @instance.get_organizations_enabled_connection(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
178
+ end
179
+
180
+ it 'is expected to raise an exception when the org ID is empty' do
181
+ expect { @instance.get_organizations_enabled_connection('org_id', nil) }.to raise_exception(Auth0::InvalidParameter)
182
+ end
183
+
184
+ it 'is expected to get enabled connection for an org' do
185
+ expect(@instance).to receive(:get).with(
186
+ '/api/v2/organizations/org_id/enabled_connections/connection_id'
187
+ )
188
+ expect { @instance.get_organizations_enabled_connection('org_id', 'connection_id') }.not_to raise_error
189
+ end
190
+
191
+ it 'is expected to get enabled connection for an org' do
192
+ expect(@instance).to receive(:get).with(
193
+ '/api/v2/organizations/org_id/enabled_connections/connection_id'
194
+ )
195
+ expect do
196
+ @instance.get_organizations_enabled_connection('org_id', 'connection_id')
197
+ end.not_to raise_error
198
+ end
199
+ end
200
+
201
+ context '.patch_organizations_enabled_connection' do
202
+ it 'is expected to respond to a patch_organizations_enabled_connection method' do
203
+ expect(@instance).to respond_to(:patch_organizations_enabled_connection)
204
+ end
205
+
206
+ it 'is expected to respond to a update_organizations_enabled_connection method' do
207
+ expect(@instance).to respond_to(:update_organizations_enabled_connection)
208
+ end
209
+
210
+ it 'is expected to patch /api/v2/organizations/org_id/enabled_connections/connection_id' do
211
+ expect(@instance).to receive(:patch).with(
212
+ '/api/v2/organizations/org_id/enabled_connections/connection_id',
213
+ {
214
+ assign_membership_on_login: false
215
+ }
216
+ )
217
+ @instance.patch_organizations_enabled_connection(
218
+ 'org_id',
219
+ 'connection_id',
220
+ assign_membership_on_login: false
221
+ )
222
+ end
223
+
224
+ it 'is expected to raise an exception when the organization id is empty' do
225
+ expect { @instance.patch_organizations_enabled_connection(nil, 'BODY') }.to raise_exception(Auth0::MissingOrganizationId)
226
+ end
227
+
228
+ it 'is expected to raise an error when the connection_id is empty' do
229
+ expect { @instance.patch_organizations_enabled_connection('org_id', nil) }.to raise_error 'Must supply a valid connection id'
230
+ end
231
+
232
+ it 'is expected to raise an error when assign_membership_on_login is nil' do
233
+ expect { @instance.patch_organizations_enabled_connection('org_id', 'connection_id') }.to raise_error 'Must supply a valid assign_membership_on_login value'
234
+ end
235
+ end
236
+
237
+ context '.create_organizations_enabled_connection' do
238
+ it 'is expected to respond to a create_organizations_enabled_connection method' do
239
+ expect(@instance).to respond_to(:create_organizations_enabled_connection)
240
+ end
241
+
242
+ it 'is expected to respond to a add_organizations_enabled_connection method' do
243
+ expect(@instance).to respond_to(:add_organizations_enabled_connection)
244
+ end
245
+
246
+ it 'is expected to post /api/v2/organizations/org_id/enabled_connections' do
247
+ expect(@instance).to receive(:post).with(
248
+ '/api/v2/organizations/org_id/enabled_connections',
249
+ {
250
+ connection_id: 'connection_id',
251
+ assign_membership_on_login: true
252
+ }
253
+ )
254
+ @instance.create_organizations_enabled_connection('org_id', 'connection_id', assign_membership_on_login: true)
255
+ end
256
+
257
+ it 'is expected to raise an exception when the organization id is empty' do
258
+ expect { @instance.create_organizations_enabled_connection(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
259
+ end
260
+
261
+ it 'is expected to raise an exception when the connection id is empty' do
262
+ expect { @instance.create_organizations_enabled_connection('123', nil) }.to raise_error 'Must supply a valid connection id'
263
+ end
264
+ end
265
+
266
+ context '.delete_organizations_enabled_connection' do
267
+ it 'is expected to respond to a delete_organizations_enabled_connection method' do
268
+ expect(@instance).to respond_to(:delete_organizations_enabled_connection)
269
+ end
270
+
271
+ it 'is expected to respond to a remove_organizations_enabled_connection method' do
272
+ expect(@instance).to respond_to(:remove_organizations_enabled_connection)
273
+ end
274
+
275
+ it 'is expected to delete /api/v2/organizations/org_id/enabled_connections/connection_id' do
276
+ expect(@instance).to receive(:delete).with(
277
+ '/api/v2/organizations/org_id/enabled_connections/connection_id'
278
+ )
279
+ @instance.delete_organizations_enabled_connection('org_id', 'connection_id')
280
+ end
281
+
282
+ it 'is expected to raise an exception when the organization id is empty' do
283
+ expect { @instance.delete_organizations_enabled_connection(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
284
+ end
285
+
286
+ it 'is expected to raise an exception when the connection id is empty' do
287
+ expect { @instance.delete_organizations_enabled_connection('org_id', nil) }.to raise_error 'Must supply a valid connection id'
288
+ end
289
+ end
290
+
291
+ context '.get_organizations_invites' do
292
+ it 'is expected to respond to a get_organizations_invites method' do
293
+ expect(@instance).to respond_to(:get_organizations_invites)
294
+ end
295
+
296
+ it 'is expected to raise an exception when the org ID is empty' do
297
+ expect { @instance.get_organizations_invites(nil) }.to raise_exception(Auth0::MissingOrganizationId)
298
+ end
299
+
300
+ it 'is expected to get invitations for an org' do
301
+ expect(@instance).to receive(:get).with(
302
+ '/api/v2/organizations/org_id/invitations'
303
+ )
304
+ expect { @instance.get_organizations_invites('org_id') }.not_to raise_error
305
+ end
306
+
307
+ it 'is expected to get invitations for an org' do
308
+ expect(@instance).to receive(:get).with(
309
+ '/api/v2/organizations/org_id/invitations'
310
+ )
311
+ expect do
312
+ @instance.get_organizations_invites('org_id')
313
+ end.not_to raise_error
314
+ end
315
+ end
316
+
317
+ context '.get_organizations_invite' do
318
+ it 'is expected to respond to a get_organizations_invite method' do
319
+ expect(@instance).to respond_to(:get_organizations_invite)
320
+ end
321
+
322
+ it 'is expected to raise an exception when the org ID is empty' do
323
+ expect { @instance.get_organizations_invite(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
324
+ end
325
+
326
+ it 'is expected to raise an exception when the org ID is empty' do
327
+ expect { @instance.get_organizations_invite('org_id', nil) }.to raise_exception(Auth0::InvalidParameter)
328
+ end
329
+
330
+ it 'is expected to get enabled connection for an org' do
331
+ expect(@instance).to receive(:get).with(
332
+ '/api/v2/organizations/org_id/invitations/invite_id'
333
+ )
334
+ expect { @instance.get_organizations_invite('org_id', 'invite_id') }.not_to raise_error
335
+ end
336
+
337
+ it 'is expected to get enabled connection for an org' do
338
+ expect(@instance).to receive(:get).with(
339
+ '/api/v2/organizations/org_id/invitations/invite_id'
340
+ )
341
+ expect do
342
+ @instance.get_organizations_invite('org_id', 'invite_id')
343
+ end.not_to raise_error
344
+ end
345
+ end
346
+
347
+ context '.patch_organizations_enabled_connection' do
348
+ it 'is expected to respond to a patch_organizations_enabled_connection method' do
349
+ expect(@instance).to respond_to(:patch_organizations_enabled_connection)
350
+ end
351
+
352
+ it 'is expected to respond to a update_organizations_enabled_connection method' do
353
+ expect(@instance).to respond_to(:update_organizations_enabled_connection)
354
+ end
355
+
356
+ it 'is expected to patch /api/v2/organizations/org_id/enabled_connections/connection_id' do
357
+ expect(@instance).to receive(:patch).with(
358
+ '/api/v2/organizations/org_id/enabled_connections/connection_id',
359
+ {
360
+ assign_membership_on_login: false
361
+ }
362
+ )
363
+ @instance.patch_organizations_enabled_connection(
364
+ 'org_id',
365
+ 'connection_id',
366
+ assign_membership_on_login: false
367
+ )
368
+ end
369
+
370
+ it 'is expected to raise an exception when the organization id is empty' do
371
+ expect { @instance.patch_organizations_enabled_connection(nil, 'BODY') }.to raise_exception(Auth0::MissingOrganizationId)
372
+ end
373
+
374
+ it 'is expected to raise an error when the connection_id is empty' do
375
+ expect { @instance.patch_organizations_enabled_connection('org_id', nil) }.to raise_error 'Must supply a valid connection id'
376
+ end
377
+
378
+ it 'is expected to raise an error when assign_membership_on_login is nil' do
379
+ expect { @instance.patch_organizations_enabled_connection('org_id', 'connection_id') }.to raise_error 'Must supply a valid assign_membership_on_login value'
380
+ end
381
+ end
382
+
383
+ context '.create_organizations_invite' do
384
+ it 'is expected to respond to a create_organizations_invite method' do
385
+ expect(@instance).to respond_to(:create_organizations_invite)
386
+ end
387
+
388
+ it 'is expected to respond to a add_organizations_invite method' do
389
+ expect(@instance).to respond_to(:add_organizations_invite)
390
+ end
391
+
392
+ it 'is expected to post /api/v2/organizations/org_id/invitations' do
393
+ expect(@instance).to receive(:post).with(
394
+ '/api/v2/organizations/org_id/invitations',
395
+ {
396
+ ttl_sec: 60000
397
+ }
398
+ )
399
+ @instance.create_organizations_invite('org_id', ttl_sec: 60000)
400
+ end
401
+
402
+ it 'is expected to raise an exception when the organization id is empty' do
403
+ expect { @instance.create_organizations_invite(nil) }.to raise_exception(Auth0::MissingOrganizationId)
404
+ end
405
+ end
406
+
407
+ context '.delete_organizations_invite' do
408
+ it 'is expected to respond to a delete_organizations_invite method' do
409
+ expect(@instance).to respond_to(:delete_organizations_invite)
410
+ end
411
+
412
+ it 'is expected to respond to a remove_organizations_invite method' do
413
+ expect(@instance).to respond_to(:remove_organizations_invite)
414
+ end
415
+
416
+ it 'is expected to delete /api/v2/organizations/org_id/invitations/invite_id' do
417
+ expect(@instance).to receive(:delete).with(
418
+ '/api/v2/organizations/org_id/invitations/invite_id'
419
+ )
420
+ @instance.delete_organizations_invite('org_id', 'invite_id')
421
+ end
422
+
423
+ it 'is expected to raise an exception when the organization id is empty' do
424
+ expect { @instance.delete_organizations_invite(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
425
+ end
426
+
427
+ it 'is expected to raise an exception when the invitation id is empty' do
428
+ expect { @instance.delete_organizations_invite('org_id', nil) }.to raise_error 'Must supply a valid invitation id'
429
+ end
430
+ end
431
+
432
+ context '.get_organizations_members' do
433
+ it 'is expected to respond to a get_organizations_members method' do
434
+ expect(@instance).to respond_to(:get_organizations_members)
435
+ end
436
+
437
+ it 'is expected to raise an exception when the org ID is empty' do
438
+ expect { @instance.get_organizations_members(nil) }.to raise_exception(Auth0::MissingOrganizationId)
439
+ end
440
+
441
+ it 'is expected to get invitations for an org' do
442
+ expect(@instance).to receive(:get).with(
443
+ '/api/v2/organizations/org_id/members'
444
+ )
445
+ expect { @instance.get_organizations_members('org_id') }.not_to raise_error
446
+ end
447
+
448
+ it 'is expected to get members for an org' do
449
+ expect(@instance).to receive(:get).with(
450
+ '/api/v2/organizations/org_id/members'
451
+ )
452
+ expect do
453
+ @instance.get_organizations_members('org_id')
454
+ end.not_to raise_error
455
+ end
456
+ end
457
+
458
+ context '.create_organizations_members' do
459
+ it 'is expected to respond to a create_organizations_members method' do
460
+ expect(@instance).to respond_to(:create_organizations_members)
461
+ end
462
+
463
+ it 'is expected to respond to a add_organizations_members method' do
464
+ expect(@instance).to respond_to(:add_organizations_members)
465
+ end
466
+
467
+ it 'is expected to post /api/v2/organizations/org_id/members' do
468
+ expect(@instance).to receive(:post).with(
469
+ '/api/v2/organizations/org_id/members',
470
+ {
471
+ members: ['123', '456']
472
+ }
473
+ )
474
+ @instance.create_organizations_members('org_id', ['123', '456'])
475
+ end
476
+
477
+ it 'is expected to raise an exception when the organization id is empty' do
478
+ expect { @instance.create_organizations_members(nil) }.to raise_exception(Auth0::MissingOrganizationId)
479
+ end
480
+ end
481
+
482
+ context '.delete_organizations_members' do
483
+ it 'is expected to respond to a delete_organizations_members method' do
484
+ expect(@instance).to respond_to(:delete_organizations_members)
485
+ end
486
+
487
+ it 'is expected to respond to a remove_organizations_members method' do
488
+ expect(@instance).to respond_to(:remove_organizations_members)
489
+ end
490
+
491
+ it 'is expected to delete /api/v2/organizations/org_id/members' do
492
+ expect(@instance).to receive(:delete).with(
493
+ '/api/v2/organizations/org_id/members', {
494
+ members: ['123', '456']
495
+ }
496
+ )
497
+ @instance.delete_organizations_members('org_id', ['123', '456'])
498
+ end
499
+
500
+ it 'is expected to raise an exception when the organization id is empty' do
501
+ expect { @instance.delete_organizations_members(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
502
+ end
503
+
504
+ it 'is expected to raise an exception when the invitation id is empty' do
505
+ expect { @instance.delete_organizations_members('org_id', []) }.to raise_error 'Must supply an array of member ids'
506
+ end
507
+ end
508
+
509
+ context '.get_organizations_member_roles' do
510
+ it 'is expected to respond to a get_organizations_member_roles method' do
511
+ expect(@instance).to respond_to(:get_organizations_member_roles)
512
+ end
513
+
514
+ it 'is expected to raise an exception when the org ID is empty' do
515
+ expect { @instance.get_organizations_member_roles(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
516
+ end
517
+
518
+ it 'is expected to raise an exception when the org ID is empty' do
519
+ expect { @instance.get_organizations_member_roles('org_id', nil) }.to raise_exception(Auth0::InvalidParameter)
520
+ end
521
+
522
+ it 'is expected to get roles for a member in an org' do
523
+ expect(@instance).to receive(:get).with(
524
+ '/api/v2/organizations/org_id/members/user_id/roles'
525
+ )
526
+ expect { @instance.get_organizations_member_roles('org_id', 'user_id') }.not_to raise_error
527
+ end
528
+
529
+ it 'is expected to get members for an org' do
530
+ expect(@instance).to receive(:get).with(
531
+ '/api/v2/organizations/org_id/members/user_id/roles'
532
+ )
533
+ expect do
534
+ @instance.get_organizations_member_roles('org_id', 'user_id')
535
+ end.not_to raise_error
536
+ end
537
+ end
538
+
539
+ context '.create_organizations_member_roles' do
540
+ it 'is expected to respond to a create_organizations_member_roles method' do
541
+ expect(@instance).to respond_to(:create_organizations_member_roles)
542
+ end
543
+
544
+ it 'is expected to respond to a add_organizations_member_roles method' do
545
+ expect(@instance).to respond_to(:add_organizations_member_roles)
546
+ end
547
+
548
+ it 'is expected to post /api/v2/organizations/org_id/members/user_id/roles' do
549
+ expect(@instance).to receive(:post).with(
550
+ '/api/v2/organizations/org_id/members/user_id/roles',
551
+ {
552
+ roles: ['123', '456']
553
+ }
554
+ )
555
+ @instance.create_organizations_member_roles('org_id', 'user_id', ['123', '456'])
556
+ end
557
+
558
+ it 'is expected to raise an exception when the organization id is empty' do
559
+ expect { @instance.create_organizations_member_roles(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
560
+ end
561
+ end
562
+
563
+ context '.delete_organizations_member_roles' do
564
+ it 'is expected to respond to a delete_organizations_member_roles method' do
565
+ expect(@instance).to respond_to(:delete_organizations_member_roles)
566
+ end
567
+
568
+ it 'is expected to respond to a remove_organizations_member_roles method' do
569
+ expect(@instance).to respond_to(:remove_organizations_member_roles)
570
+ end
571
+
572
+ it 'is expected to delete /api/v2/organizations/org_id/members/user_id/roles' do
573
+ expect(@instance).to receive(:delete).with(
574
+ '/api/v2/organizations/org_id/members/user_id/roles', {
575
+ roles: ['123', '456']
576
+ }
577
+ )
578
+ @instance.delete_organizations_member_roles('org_id', 'user_id', ['123', '456'])
579
+ end
580
+
581
+ it 'is expected to raise an exception when the organization id is empty' do
582
+ expect { @instance.delete_organizations_member_roles(nil, nil) }.to raise_exception(Auth0::MissingOrganizationId)
583
+ end
584
+
585
+ it 'is expected to raise an exception when the invitation id is empty' do
586
+ expect { @instance.delete_organizations_member_roles('org_id', nil, nil) }.to raise_error 'Must supply a valid user id'
587
+ end
588
+
589
+ it 'is expected to raise an exception when the invitation id is empty' do
590
+ expect { @instance.delete_organizations_member_roles('org_id', 'user_id') }.to raise_error 'Must supply an array of role ids'
591
+ end
592
+ end
593
+ end