auth0 4.1.0 → 4.4.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.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +38 -0
  3. data/DEPLOYMENT.md +10 -1
  4. data/Dockerfile +5 -0
  5. data/README.md +14 -17
  6. data/RUBYGEM.md +9 -0
  7. data/auth0.gemspec +2 -2
  8. data/examples/ruby-api/.env.example +2 -0
  9. data/examples/ruby-on-rails-api/.env.example +2 -0
  10. data/examples/ruby-on-rails-api/Gemfile +7 -7
  11. data/examples/ruby-on-rails-api/app/controllers/secured_ping_controller.rb +2 -2
  12. data/examples/ruby-on-rails-api/app/models/User.rb +5 -0
  13. data/examples/ruby-on-rails-api/config/initializers/knock.rb +2 -20
  14. data/lib/auth0/api/authentication_endpoints.rb +10 -9
  15. data/lib/auth0/api/v2.rb +2 -0
  16. data/lib/auth0/api/v2/users.rb +1 -0
  17. data/lib/auth0/api/v2/users_by_email.rb +35 -0
  18. data/lib/auth0/exception.rb +2 -0
  19. data/lib/auth0/mixins/httpproxy.rb +6 -1
  20. data/lib/auth0/version.rb +1 -1
  21. data/publish_rubygem.sh +10 -0
  22. data/spec/integration/lib/auth0/api/api_authentication_spec.rb +3 -43
  23. data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +26 -17
  24. data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +45 -9
  25. data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +58 -13
  26. data/spec/integration/lib/auth0/api/v2/api_device_credentials_spec.rb +22 -4
  27. data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +66 -22
  28. data/spec/integration/lib/auth0/api/v2/api_logs_spec.rb +38 -24
  29. data/spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb +15 -2
  30. data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +52 -16
  31. data/spec/integration/lib/auth0/api/v2/api_stats_spec.rb +12 -3
  32. data/spec/integration/lib/auth0/api/v2/api_tenants_spec.rb +21 -5
  33. data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +15 -3
  34. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +58 -37
  35. data/spec/integration/lib/auth0/auth0_client_spec.rb +1 -1
  36. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +5 -3
  37. data/spec/lib/auth0/api/v2/users_by_email_spec.rb +21 -0
  38. data/spec/lib/auth0/client_spec.rb +0 -61
  39. data/spec/spec_helper.rb +23 -0
  40. data/spec/spec_helper_full.rb +8 -19
  41. data/spec/spec_helper_unit.rb +0 -9
  42. data/spec/support/credentials.rb +2 -0
  43. data/spec/support/dummy_class.rb +1 -1
  44. metadata +55 -107
  45. data/spec/integration/lib/auth0/api/v1/api_clients_spec.rb +0 -12
  46. data/spec/integration/lib/auth0/api/v1/api_users_spec.rb +0 -52
  47. data/spec/lib/auth0/api/v1/clients_spec.rb +0 -61
  48. data/spec/lib/auth0/api/v1/connections_spec.rb +0 -66
  49. data/spec/lib/auth0/api/v1/logs_spec.rb +0 -46
  50. data/spec/lib/auth0/api/v1/rules_spec.rb +0 -42
  51. data/spec/lib/auth0/api/v1/users_spec.rb +0 -248
@@ -1,43 +1,49 @@
1
1
  require 'spec_helper'
2
2
  describe Auth0::Api::V2::ClientGrants do
3
- attr_reader :client, :client_id, :audience, :existing_grant, :scope
3
+ attr_reader :client, :client_id, :audience, :existing_grant, :scope, :existing_client
4
4
 
5
5
  before(:all) do
6
6
  @client = Auth0Client.new(v2_creds)
7
- @client_id = Faker::Lorem.word
8
- @audience = Faker::Internet.url
7
+ @client_id = v2_creds[:client_id]
8
+ sleep 1
9
+ @existing_client = client.create_client("client#{entity_suffix}")
10
+ sleep 1
11
+ @audience = "https://#{client.clients[0]['tenant']}.auth0.com/api/v2/"
9
12
  @scope = [Faker::Lorem.word]
10
- @existing_grant = client.create_client_grant('client_id' => client_id, 'audience' => audience, 'scope' => scope)
13
+ sleep 1
14
+ @existing_grant = client.create_client_grant('client_id' => existing_client['client_id'],
15
+ 'audience' => audience,
16
+ 'scope' => scope)
11
17
  end
12
18
 
13
19
  after(:all) do
14
20
  grants = client.client_grants
15
21
  grants.each do |grant|
22
+ sleep 1
16
23
  client.delete_client_grant(grant['id'])
17
24
  end
18
25
  end
19
26
 
20
27
  describe '.client_grants' do
21
- let(:client_grants) { client.client_grants }
22
-
23
- it { expect(client_grants.size).to be > 0 }
24
- it { expect(client_grants).to include(existing_grant) }
25
- end
26
-
27
- describe '.create_client_grant' do
28
- let(:new_client) { Faker::Lorem.word }
28
+ let(:client_grants) do
29
+ sleep 1
30
+ client.client_grants
31
+ end
29
32
 
30
33
  it do
31
- expect(
32
- client.create_client_grant('client_id' => new_client, 'audience' => audience,
33
- 'scope' => scope)
34
- ).to(include('client_id' => new_client, 'audience' => audience, 'scope' => scope))
34
+ sleep 1
35
+ expect(client_grants.size).to be > 0
36
+ end
37
+ it do
38
+ sleep 1
39
+ expect(client_grants).to include(existing_grant)
35
40
  end
36
41
  end
37
42
 
38
43
  describe '.patch_client_grant' do
39
44
  let(:new_scope) { [Faker::Lorem.word] }
40
45
  it do
46
+ sleep 1
41
47
  expect(
42
48
  client.patch_client_grant(
43
49
  existing_grant['id'],
@@ -48,6 +54,9 @@ describe Auth0::Api::V2::ClientGrants do
48
54
  end
49
55
 
50
56
  describe '.delete_client_grant' do
51
- it { expect { client.delete_client_grant(existing_grant['id']) }.to_not raise_error }
57
+ it do
58
+ sleep 1
59
+ expect { client.delete_client_grant(existing_grant['id']) }.to_not raise_error
60
+ end
52
61
  end
53
62
  end
@@ -1,46 +1,71 @@
1
1
  require 'spec_helper'
2
2
  describe Auth0::Api::V2::Clients do
3
3
  let(:client) { Auth0Client.new(v2_creds) }
4
- let(:existing_client) { client.create_client("existing#{entity_suffix}") }
4
+ let(:existing_client) do
5
+ sleep 1
6
+ client.create_client("existing#{entity_suffix}")
7
+ end
5
8
  let(:client_name) { "ClientV2#{entity_suffix}" }
6
9
 
7
- it { expect(client.clients).to_not be_empty }
10
+ it do
11
+ sleep 1
12
+ expect(client.clients).to_not be_empty
13
+ end
8
14
 
9
15
  describe '.clients' do
10
- let(:clients) { client.clients }
16
+ let(:clients) do
17
+ sleep 1
18
+ client.clients
19
+ end
11
20
 
12
- it { expect(clients.size).to be > 0 }
21
+ it do
22
+ sleep 1
23
+ expect(clients.size).to be > 0
24
+ end
13
25
 
14
26
  context '#filters' do
15
27
  it do
28
+ sleep 1
16
29
  expect(client.clients(fields: [:name, :callbacks].join(',')).first).to(include('name', 'callbacks'))
17
30
  end
18
31
  it do
32
+ sleep 1
19
33
  expect(client.clients(fields: [:callbacks].join(',')).first).to_not(include('name'))
20
34
  end
21
35
  it do
36
+ sleep 1
22
37
  expect(client.clients(fields: [:callbacks].join(','), include_fields: false).first).to_not(include('callbacks'))
23
38
  end
24
39
  end
25
40
  end
26
41
 
27
42
  describe '.client' do
28
- it { expect(client.client(existing_client['client_id'])).to include('client_id' => existing_client['client_id']) }
29
- it { expect { client.client '' }.to raise_error(Auth0::MissingClientId) }
43
+ it do
44
+ sleep 1
45
+ expect(client.client(existing_client['client_id'])).to include('client_id' => existing_client['client_id'])
46
+ end
47
+ it do
48
+ sleep 1
49
+ expect { client.client '' }.to raise_error(Auth0::MissingClientId)
50
+ end
30
51
 
31
52
  context '#filters' do
32
53
  let(:client_include) do
54
+ sleep 1
33
55
  client.client(existing_client['client_id'], fields: [:name, :client_secret, :jwt_configuration].join(','))
34
56
  end
35
57
  let(:client_not_include) do
58
+ sleep 1
36
59
  client.client(existing_client['client_id'], fields: :jwt_configuration, include_fields: false)
37
60
  end
38
61
 
39
62
  it do
63
+ sleep 1
40
64
  expect(client_include).to(include('name', 'client_secret', 'jwt_configuration'))
41
65
  end
42
66
 
43
67
  it do
68
+ sleep 1
44
69
  expect(client_not_include).to(include('name', 'client_secret'))
45
70
  expect(client_not_include).to_not(include('jwt_configuration'))
46
71
  end
@@ -49,6 +74,7 @@ describe Auth0::Api::V2::Clients do
49
74
 
50
75
  describe '.create_client' do
51
76
  it do
77
+ sleep 1
52
78
  expect(client.create_client(client_name, custom_login_page_on: false)).to(
53
79
  include('name' => client_name, 'custom_login_page_on' => false)
54
80
  )
@@ -58,6 +84,7 @@ describe Auth0::Api::V2::Clients do
58
84
 
59
85
  describe '.patch_client' do
60
86
  it do
87
+ sleep 1
61
88
  expect(
62
89
  client.patch_client(
63
90
  existing_client['client_id'],
@@ -66,11 +93,20 @@ describe Auth0::Api::V2::Clients do
66
93
  )
67
94
  ).to(include('custom_login_page_on' => false, 'sso' => true))
68
95
  end
69
- it { expect { client.patch_client('', custom_login_page_on: false) }.to raise_error(Auth0::MissingClientId) }
96
+ it do
97
+ sleep 1
98
+ expect { client.patch_client('', custom_login_page_on: false) }.to raise_error(Auth0::MissingClientId)
99
+ end
70
100
  end
71
101
 
72
102
  describe '.delete_rule' do
73
- it { expect { client.delete_client(existing_client['client_id']) }.to_not raise_error }
74
- it { expect { client.delete_client '' }.to raise_error(Auth0::MissingClientId) }
103
+ it do
104
+ sleep 1
105
+ expect { client.delete_client(existing_client['client_id']) }.to_not raise_error
106
+ end
107
+ it do
108
+ sleep 1
109
+ expect { client.delete_client '' }.to raise_error(Auth0::MissingClientId)
110
+ end
75
111
  end
76
112
  end
@@ -15,15 +15,31 @@ describe Auth0::Api::V2::Connections do
15
15
  end
16
16
 
17
17
  describe '.connections' do
18
- let(:connections) { client.connections }
18
+ let(:connections) do
19
+ sleep 1
20
+ client.connections
21
+ end
19
22
 
20
- it { expect(connections.size).to be > 0 }
21
- it { expect(connections.find { |con| con['name'] == name }).to_not be_empty }
23
+ it do
24
+ sleep 1
25
+ expect(connections.size).to be > 0
26
+ end
27
+ it do
28
+ sleep 1
29
+ expect(connections.find { |con| con['name'] == name }).to_not be_empty
30
+ end
22
31
 
23
32
  context '#filters' do
24
- it { expect(client.connections(strategy: strategy).size).to be > 0 }
25
- it { expect(client.connections(strategy: strategy, fields: [:name].join(',')).first).to include('name') }
26
33
  it do
34
+ sleep 1
35
+ expect(client.connections(strategy: strategy).size).to be > 0
36
+ end
37
+ it do
38
+ sleep 1
39
+ expect(client.connections(strategy: strategy, fields: [:name].join(',')).first).to include('name')
40
+ end
41
+ it do
42
+ sleep 1
27
43
  expect(client.connections(strategy: strategy, fields: [:name].join(','), include_fields: false).first).to_not(
28
44
  include('name')
29
45
  )
@@ -32,13 +48,23 @@ describe Auth0::Api::V2::Connections do
32
48
  end
33
49
 
34
50
  describe '.connection' do
35
- let(:subject) { client.connection(connection['id']) }
51
+ let(:subject) do
52
+ sleep 1
53
+ client.connection(connection['id'])
54
+ end
36
55
 
37
- it { should include('name' => connection['name']) }
56
+ it do
57
+ sleep 1
58
+ should include('name' => connection['name'])
59
+ end
38
60
 
39
61
  context '#filters' do
40
- it { expect(client.connection(connection['id'], fields: [:name, :id].join(','))).to include('id', 'name') }
41
62
  it do
63
+ sleep 1
64
+ expect(client.connection(connection['id'], fields: [:name, :id].join(','))).to include('id', 'name')
65
+ end
66
+ it do
67
+ sleep 1
42
68
  expect(client.connection(connection['id'], fields: [:name, :id].join(','), include_fields: false)).to_not(
43
69
  include('id', 'name')
44
70
  )
@@ -49,16 +75,26 @@ describe Auth0::Api::V2::Connections do
49
75
  describe '.create_connection' do
50
76
  let(:subject) { connection }
51
77
 
52
- it { should include('id', 'name') }
53
- it { should include('name' => connection['name']) }
78
+ it do
79
+ sleep 1
80
+ should include('id', 'name')
81
+ end
82
+ it do
83
+ sleep 1
84
+ should include('name' => connection['name'])
85
+ end
54
86
  end
55
87
 
56
88
  describe '.delete_connection' do
57
- it { expect { client.delete_connection connection['id'] }.to_not raise_error }
89
+ it do
90
+ sleep 1
91
+ expect { client.delete_connection connection['id'] }.to_not raise_error
92
+ end
58
93
  end
59
94
 
60
95
  describe '.update_connection' do
61
96
  let!(:connection_to_update) do
97
+ sleep 1
62
98
  client.create_connection(name: "#{SecureRandom.uuid[0..25]}#{entity_suffix}",
63
99
  strategy: strategy,
64
100
  options: options,
@@ -67,6 +103,7 @@ describe Auth0::Api::V2::Connections do
67
103
  new_name = SecureRandom.uuid[0..25]
68
104
  let(:options) { { username: new_name } }
69
105
  it do
106
+ sleep 1
70
107
  expect(client.update_connection(connection_to_update['id'], 'options' => options)['options']).to include(
71
108
  'username' => new_name
72
109
  )
@@ -78,6 +115,7 @@ describe Auth0::Api::V2::Connections do
78
115
  let(:email) { "#{entity_suffix}#{Faker::Internet.safe_email(username)}" }
79
116
  let(:password) { Faker::Internet.password }
80
117
  let!(:user_to_delete) do
118
+ sleep 1
81
119
  client.create_user(username, email: email,
82
120
  password: password,
83
121
  email_verified: false,
@@ -85,16 +123,23 @@ describe Auth0::Api::V2::Connections do
85
123
  app_metadata: {})
86
124
  end
87
125
  let(:connection) do
126
+ sleep 1
88
127
  client.connections.find { |connection| connection['name'] == Auth0::Api::AuthenticationEndpoints::UP_AUTH }
89
128
  end
90
129
 
91
- it { expect(client.delete_connection_user(connection['id'], email)).to be_empty }
130
+ it do
131
+ sleep 1
132
+ expect(client.delete_connection_user(connection['id'], email)).to be_empty
133
+ end
92
134
  end
93
135
 
94
136
  after(:all) do
95
137
  client
96
138
  .connections
97
139
  .select { |connection| connection['name'].include?(entity_suffix) }
98
- .each { |connection| client.delete_connection(connection['id']) }
140
+ .each { |connection|
141
+ sleep 1
142
+ client.delete_connection(connection['id'])
143
+ }
99
144
  end
100
145
  end
@@ -8,6 +8,7 @@ describe Auth0::Api::V2::DeviceCredentials do
8
8
  username = Faker::Internet.user_name
9
9
  email = "#{entity_suffix}#{Faker::Internet.safe_email(username)}"
10
10
  password = Faker::Internet.password
11
+ sleep 1
11
12
  @user = client.create_user(username, 'email' => email,
12
13
  'password' => password,
13
14
  'email_verified' => true,
@@ -20,6 +21,7 @@ describe Auth0::Api::V2::DeviceCredentials do
20
21
  authorization: 'Basic' }
21
22
 
22
23
  @basic_client = Auth0Client.new(v2_creds.merge(basic_creds))
24
+ sleep 1
23
25
  @existing_device_credentials = basic_client.create_device_credential(
24
26
  "#{user['name']}_phone_1",
25
27
  'dmFsdWU=',
@@ -29,16 +31,27 @@ describe Auth0::Api::V2::DeviceCredentials do
29
31
  end
30
32
 
31
33
  after(:all) do
34
+ sleep 1
32
35
  client.delete_user(user['user_id'])
33
36
  end
34
37
 
35
38
  describe '.device_credentials' do
36
- let(:device_credentials) { basic_client.device_credentials(ENV['CLIENT_ID']) }
37
- it { expect(device_credentials.size).to be > 0 }
38
- it { expect(device_credentials.find { |cred| cred['id'] == existing_device_credentials['id'] }).to_not be_empty }
39
+ let(:device_credentials) do
40
+ sleep 1
41
+ basic_client.device_credentials(ENV['CLIENT_ID'])
42
+ end
43
+ it do
44
+ sleep 1
45
+ expect(device_credentials.size).to be > 0
46
+ end
47
+ it do
48
+ sleep 1
49
+ expect(device_credentials.find { |cred| cred['id'] == existing_device_credentials['id'] }).to_not be_empty
50
+ end
39
51
  context '#filter_by_type' do
40
52
  let(:filtered_device_credentials) { basic_client.device_credentials(ENV['CLIENT_ID'], type: 'refresh_token') }
41
53
  it do
54
+ sleep 1
42
55
  expect(filtered_device_credentials.find do |cred|
43
56
  cred['id'] == existing_device_credentials['id']
44
57
  end).to eq nil
@@ -48,6 +61,7 @@ describe Auth0::Api::V2::DeviceCredentials do
48
61
 
49
62
  describe '.create_device_credential' do
50
63
  let!(:new_credentials) do
64
+ sleep 1
51
65
  basic_client.create_device_credential(
52
66
  "#{user['name']}_phone_2",
53
67
  'dmFsdWU=',
@@ -56,12 +70,16 @@ describe Auth0::Api::V2::DeviceCredentials do
56
70
  )
57
71
  end
58
72
  it do
73
+ sleep 1
59
74
  expect(basic_client.device_credentials(ENV['CLIENT_ID'])
60
75
  .find { |cred| cred['id'] == new_credentials['id'] }).to_not be_empty
61
76
  end
62
77
  end
63
78
 
64
79
  describe '.delete_device_credential' do
65
- it { expect { basic_client.delete_device_credential(existing_device_credentials['id']) }.to_not raise_error }
80
+ it do
81
+ sleep 1
82
+ expect { basic_client.delete_device_credential(existing_device_credentials['id']) }.to_not raise_error
83
+ end
66
84
  end
67
85
  end
@@ -3,6 +3,7 @@ describe Auth0::Api::V2::Emails do
3
3
  before(:all) do
4
4
  client = Auth0Client.new(v2_creds)
5
5
  begin
6
+ sleep 1
6
7
  client.delete_provider
7
8
  rescue
8
9
  puts 'no email provider to delete'
@@ -22,31 +23,63 @@ describe Auth0::Api::V2::Emails do
22
23
  end
23
24
 
24
25
  describe '.configure_provider' do
25
- let!(:email_provider) { client.configure_provider(body) }
26
+ let!(:email_provider) do
27
+ sleep 1
28
+ begin
29
+ client.configure_provider(body)
30
+ rescue
31
+ puts 'email provider is already configured'
32
+ end
33
+ end
26
34
  it do
27
- expect(email_provider).to include(
28
- 'name' => name, 'enabled' => enabled, 'credentials' => credentials, 'settings' => settings
29
- )
35
+ if email_provider
36
+ sleep 1
37
+ expect(email_provider).to include(
38
+ 'name' => name, 'enabled' => enabled, 'credentials' => credentials, 'settings' => settings
39
+ )
40
+ end
30
41
  end
31
42
  end
32
43
 
33
44
  describe '.get_provider' do
34
- let(:provider) { client.get_provider }
45
+ let(:provider) do
46
+ sleep 1
47
+ begin
48
+ client.get_provider
49
+ rescue
50
+ 'no email provider'
51
+ end
52
+ end
35
53
 
36
- it { expect(provider.size).to be > 0 }
54
+ it do
55
+ if provider
56
+ sleep 1
57
+ expect(provider.size).to be > 0
58
+ end
59
+ end
37
60
 
38
61
  context '#filters' do
39
62
  it do
40
- expect(
41
- client.get_provider(fields: [:name, :enabled, :credentials].join(','), include_fields: true)
42
- ).to(
43
- include('name', 'enabled', 'credentials')
44
- )
63
+ begin
64
+ sleep 1
65
+ expect(
66
+ client.get_provider(fields: [:name, :enabled, :credentials].join(','), include_fields: true)
67
+ ).to(
68
+ include('name', 'enabled', 'credentials')
69
+ )
70
+ rescue
71
+ 'no email provider'
72
+ end
45
73
  end
46
74
  it do
47
- expect(
48
- client.get_provider(fields: [:enabled].join(','), include_fields: false).first
49
- ).to_not(include('enabled'))
75
+ begin
76
+ sleep 1
77
+ expect(
78
+ client.get_provider(fields: [:enabled].join(','), include_fields: false).first
79
+ ).to_not(include('enabled'))
80
+ rescue
81
+ 'no email provider'
82
+ end
50
83
  end
51
84
  end
52
85
  end
@@ -61,18 +94,29 @@ describe Auth0::Api::V2::Emails do
61
94
  'settings' => update_settings }
62
95
  end
63
96
  it do
64
- expect(
65
- client.update_provider(update_body)
66
- ).to(
67
- include(
68
- 'name' => update_name, 'enabled' => enabled, 'credentials' => credentials, 'settings' => update_settings
97
+ begin
98
+ sleep 1
99
+ expect(
100
+ client.update_provider(update_body)
101
+ ).to(
102
+ include(
103
+ 'name' => update_name, 'enabled' => enabled, 'credentials' => credentials, 'settings' => update_settings
104
+ )
69
105
  )
70
- )
106
+ rescue
107
+ puts 'email provider is not configured'
108
+ end
71
109
  end
72
110
  end
73
111
 
74
112
  describe '.delete_provider' do
75
- it { expect { client.delete_provider }.to_not raise_error }
76
- it { expect { client.get_provider }.to raise_error(Auth0::NotFound) }
113
+ it do
114
+ sleep 1
115
+ expect { client.delete_provider }.to_not raise_error
116
+ end
117
+ it do
118
+ sleep 1
119
+ expect { client.get_provider }.to raise_error(Auth0::NotFound)
120
+ end
77
121
  end
78
122
  end