auth0 3.6.1 → 4.0.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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +7 -0
  4. data/.rubocop_todo.yml +7 -0
  5. data/.travis.yml +12 -7
  6. data/CHANGELOG.md +10 -0
  7. data/Gemfile +4 -2
  8. data/Guardfile +13 -10
  9. data/LICENSE +2 -2
  10. data/README.md +9 -11
  11. data/Rakefile +33 -7
  12. data/auth0.gemspec +12 -12
  13. data/deploy_documentation.sh +29 -0
  14. data/doc_config/templates/default/fulldoc/html/css/full_list.css +79 -0
  15. data/doc_config/templates/default/fulldoc/html/css/style.css +546 -0
  16. data/doc_config/templates/default/layout/html/breadcrumb.erb +11 -0
  17. data/doc_config/templates/default/layout/html/footer.erb +115 -0
  18. data/doc_config/templates/default/layout/html/headers.erb +17 -0
  19. data/doc_config/templates/default/layout/html/layout.erb +27 -0
  20. data/lib/auth0.rb +5 -5
  21. data/lib/auth0/api/authentication_endpoints.rb +264 -46
  22. data/lib/auth0/api/v1.rb +5 -5
  23. data/lib/auth0/api/v1/clients.rb +7 -7
  24. data/lib/auth0/api/v1/connections.rb +9 -10
  25. data/lib/auth0/api/v1/logs.rb +9 -16
  26. data/lib/auth0/api/v1/rules.rb +5 -5
  27. data/lib/auth0/api/v1/users.rb +28 -27
  28. data/lib/auth0/api/v2.rb +17 -9
  29. data/lib/auth0/api/v2/blacklists.rb +30 -9
  30. data/lib/auth0/api/v2/clients.rb +60 -19
  31. data/lib/auth0/api/v2/connections.rb +63 -10
  32. data/lib/auth0/api/v2/emails.rb +58 -0
  33. data/lib/auth0/api/v2/jobs.rb +44 -7
  34. data/lib/auth0/api/v2/rules.rb +104 -0
  35. data/lib/auth0/api/v2/stats.rb +22 -5
  36. data/lib/auth0/api/v2/tenants.rb +39 -0
  37. data/lib/auth0/api/v2/tickets.rb +58 -0
  38. data/lib/auth0/api/v2/users.rb +128 -39
  39. data/lib/auth0/client.rb +8 -6
  40. data/lib/auth0/exception.rb +29 -23
  41. data/lib/auth0/mixins.rb +12 -10
  42. data/lib/auth0/mixins/httparty_proxy.rb +13 -10
  43. data/lib/auth0/mixins/initializer.rb +25 -27
  44. data/lib/auth0/version.rb +2 -2
  45. data/spec/integration/lib/auth0/api/v1/api_clients_spec.rb +2 -4
  46. data/spec/integration/lib/auth0/api/v1/api_users_spec.rb +25 -32
  47. data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +14 -0
  48. data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +61 -6
  49. data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +68 -42
  50. data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +71 -0
  51. data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +69 -0
  52. data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +83 -0
  53. data/spec/integration/lib/auth0/api/v2/api_stats_spec.rb +16 -0
  54. data/spec/integration/lib/auth0/api/v2/api_tenants_spec.rb +37 -0
  55. data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +33 -0
  56. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +88 -36
  57. data/spec/integration/lib/auth0/auth0_client_spec.rb +43 -35
  58. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +253 -47
  59. data/spec/lib/auth0/api/v1/clients_spec.rb +37 -38
  60. data/spec/lib/auth0/api/v1/connections_spec.rb +44 -38
  61. data/spec/lib/auth0/api/v1/logs_spec.rb +24 -24
  62. data/spec/lib/auth0/api/v1/rules_spec.rb +23 -22
  63. data/spec/lib/auth0/api/v1/users_spec.rb +153 -130
  64. data/spec/lib/auth0/api/v2/blacklists_spec.rb +12 -11
  65. data/spec/lib/auth0/api/v2/clients_spec.rb +38 -33
  66. data/spec/lib/auth0/api/v2/connections_spec.rb +59 -34
  67. data/spec/lib/auth0/api/v2/emails_spec.rb +47 -0
  68. data/spec/lib/auth0/api/v2/jobs_spec.rb +24 -10
  69. data/spec/lib/auth0/api/v2/rules_spec.rb +69 -0
  70. data/spec/lib/auth0/api/v2/stats_spec.rb +11 -11
  71. data/spec/lib/auth0/api/v2/tenants_spec.rb +25 -0
  72. data/spec/lib/auth0/api/v2/tickets_spec.rb +31 -0
  73. data/spec/lib/auth0/api/v2/users_spec.rb +101 -39
  74. data/spec/lib/auth0/client_spec.rb +46 -58
  75. data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +98 -69
  76. data/spec/lib/auth0/mixins/initializer_spec.rb +2 -2
  77. data/spec/spec_helper.rb +2 -2
  78. data/spec/spec_helper_full.rb +16 -15
  79. data/spec/spec_helper_unit.rb +5 -5
  80. data/spec/support/credentials.rb +9 -3
  81. data/spec/support/dummy_class.rb +7 -1
  82. data/spec/support/dummy_class_for_proxy.rb +2 -2
  83. data/spec/support/import_users.json +13 -0
  84. data/spec/support/stub_response.rb +1 -2
  85. metadata +78 -41
@@ -1,59 +1,52 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
  describe Auth0::Api::V1::Users do
3
-
4
3
  let(:client) { Auth0Client.new(v1_creds) }
5
4
  let(:username) { Faker::Internet.user_name }
6
5
  let(:email) { "#{entity_suffix}#{Faker::Internet.safe_email(username)}" }
7
6
  let(:password) { Faker::Internet.password }
8
- let(:connection) { "Username-Password-Authentication" }
9
- let!(:user) { client.create_user(email, password, connection, {
10
- "username" => username,
11
- "email_verified" => false,
12
- })}
13
-
14
- describe '.users' do
7
+ let!(:user) do
8
+ client.create_user(email, password, Auth0::Api::AuthenticationEndpoints::UP_AUTH,
9
+ 'username' => username, 'email_verified' => false)
10
+ end
15
11
 
16
- let(:users) { client.users() }
12
+ skip 'Users examples are skipped' do
13
+ describe '.users' do
14
+ let(:users) { client.users }
17
15
 
18
- it { expect(users.size).to be > 0 }
16
+ it { expect(users.size).to be > 0 }
19
17
 
20
- context "#filters" do
21
- it { expect(client.users("email: #{email}").size).to be 1 }
18
+ context '#filters' do
19
+ it { expect(client.users("email: #{email}").size).to be 1 }
20
+ end
22
21
  end
23
-
24
22
  end
25
23
 
26
24
  describe '.user' do
25
+ let(:subject) { client.user(user['user_id']) }
27
26
 
28
- let(:subject) { client.user(user["user_id"]) }
29
-
30
- it { should include("email" => email, "username" => username) }
31
-
27
+ it { should include('email' => email, 'username' => username) }
32
28
  end
33
29
 
34
30
  describe '.create_user' do
35
-
36
31
  let(:subject) { user }
37
32
 
38
- it { should include("user_id", "identities") }
39
- it { should include(
40
- "username" => username,
41
- "email" => email,
42
- "email_verified" => false,
43
- )}
44
-
33
+ it { should include('user_id', 'identities') }
34
+ it do
35
+ should include(
36
+ 'username' => username,
37
+ 'email' => email,
38
+ 'email_verified' => false
39
+ )
40
+ end
45
41
  end
46
42
 
47
43
  describe '.delete_user' do
44
+ it { expect { client.delete_user user['user_id'] }.to_not raise_error }
48
45
 
49
- it { expect { client.delete_user user["user_id"] }.to_not raise_error }
50
-
51
- it { expect { client.delete_user "" }.to raise_error(Auth0::MissingUserId) }
52
-
46
+ it { expect { client.delete_user '' }.to raise_error(Auth0::MissingUserId) }
53
47
  end
54
48
 
55
49
  describe '.patch_user_metadata' do
56
- it { expect(client.patch_user_metadata(user["user_id"], {"custom_field" => "custom_value"})).to eq "OK" }
50
+ it { expect(client.patch_user_metadata(user['user_id'], 'custom_field' => 'custom_value')).to eq 'OK' }
57
51
  end
58
-
59
52
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::Blacklists do
3
+ let(:client) { Auth0Client.new(v2_creds) }
4
+ let(:token) { 'faketoken' }
5
+
6
+ describe '.add_token_to_blacklist' do
7
+ it { expect(client.add_token_to_blacklist(token)).to be_nil }
8
+ end
9
+
10
+ describe '.blacklisted_tokens' do
11
+ let(:response) { { 'aud' => ENV['GLOBAL_CLIENT_ID'], 'jti' => token } }
12
+ it { expect(client.blacklisted_tokens).to include response }
13
+ end
14
+ end
@@ -1,18 +1,73 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
  describe Auth0::Api::V2::Clients do
3
-
4
3
  let(:client) { Auth0Client.new(v2_creds) }
5
4
  let(:existing_client) { client.create_client("existing#{entity_suffix}") }
6
5
  let(:client_name) { "ClientV2#{entity_suffix}" }
7
6
 
8
7
  it { expect(client.clients).to_not be_empty }
9
8
 
10
- it { expect(client.create_client(client_name, {custom_login_page_on: false})).to include("name" => client_name, "custom_login_page_on" => false) }
9
+ describe '.clients' do
10
+ let(:clients) { client.clients }
11
+
12
+ it { expect(clients.size).to be > 0 }
13
+
14
+ context '#filters' do
15
+ it do
16
+ expect(client.clients(fields: [:name, :callbacks].join(',')).first).to(include('name', 'callbacks'))
17
+ end
18
+ it do
19
+ expect(client.clients(fields: [:callbacks].join(',')).first).to_not(include('name'))
20
+ end
21
+ it do
22
+ expect(client.clients(fields: [:callbacks].join(','), include_fields: false).first).to_not(include('callbacks'))
23
+ end
24
+ end
25
+ end
26
+
27
+ 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) }
30
+
31
+ context '#filters' do
32
+ let(:client_include) do
33
+ client.client(existing_client['client_id'], fields: [:name, :client_secret, :jwt_configuration].join(','))
34
+ end
35
+ let(:client_not_include) do
36
+ client.client(existing_client['client_id'], fields: :jwt_configuration, include_fields: false)
37
+ end
38
+
39
+ it do
40
+ expect(client_include).to(include('name', 'client_secret', 'jwt_configuration'))
41
+ end
11
42
 
12
- it { expect(client.patch_client(existing_client["client_id"], {custom_login_page_on: false, sso: true})).to include("custom_login_page_on" => false, "sso" => true) }
43
+ it do
44
+ expect(client_not_include).to(include('name', 'client_secret'))
45
+ expect(client_not_include).to_not(include('jwt_configuration'))
46
+ end
47
+ end
48
+ end
13
49
 
14
- it { expect { client.delete_client(existing_client["client_id"]) }.to_not raise_error }
50
+ describe '.create_client' do
51
+ it do
52
+ expect(client.create_client(client_name, custom_login_page_on: false)).to(
53
+ include('name' => client_name, 'custom_login_page_on' => false))
54
+ end
55
+ it { expect { client.create_client('', custom_login_page_on: false) }.to raise_error(Auth0::MissingParameter) }
56
+ end
15
57
 
16
- it { expect(client.client(existing_client["client_id"])).to include("client_id" => existing_client["client_id"]) }
58
+ describe '.patch_client' do
59
+ it do
60
+ expect(
61
+ client.patch_client(
62
+ existing_client['client_id'],
63
+ custom_login_page_on: false,
64
+ sso: true)).to(include('custom_login_page_on' => false, 'sso' => true))
65
+ end
66
+ it { expect { client.patch_client('', custom_login_page_on: false) }.to raise_error(Auth0::MissingClientId) }
67
+ end
17
68
 
69
+ describe '.delete_rule' do
70
+ it { expect { client.delete_client(existing_client['client_id']) }.to_not raise_error }
71
+ it { expect { client.delete_client '' }.to raise_error(Auth0::MissingClientId) }
72
+ end
18
73
  end
@@ -1,71 +1,97 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
  describe Auth0::Api::V2::Connections do
3
-
4
- let(:client) { Auth0Client.new(v2_creds) }
5
-
6
- let(:name) { SecureRandom.uuid[0..25] }
7
- let(:strategy) { 'google-oauth2' }
8
- let(:options) { {} }
9
- let(:enabled_clients) { [] }
10
-
11
- let!(:connection) { client.create_connection({
12
- name: name,
13
- strategy: strategy,
14
- options: options,
15
- enabled_clients: enabled_clients,
16
- })}
3
+ attr_reader :client, :connection, :strategy, :name, :enabled_clients, :options
4
+
5
+ before(:all) do
6
+ @client = Auth0Client.new(v2_creds)
7
+ @name = "#{SecureRandom.uuid[0..25]}#{entity_suffix}"
8
+ @strategy = 'google-oauth2'
9
+ @options = {}
10
+ @enabled_clients = []
11
+ @connection = client.create_connection(name: name,
12
+ strategy: strategy,
13
+ options: options,
14
+ enabled_clients: enabled_clients)
15
+ end
17
16
 
18
17
  describe '.connections' do
19
-
20
- let(:connections) { client.connections() }
18
+ let(:connections) { client.connections }
21
19
 
22
20
  it { expect(connections.size).to be > 0 }
23
- it { expect(connections.find {|con| con["name"] == name}).to_not be_nil }
21
+ it { expect(connections.find { |con| con['name'] == name }).to_not be_nil }
24
22
 
25
- context "#filters" do
23
+ context '#filters' do
26
24
  it { expect(client.connections(strategy: strategy).size).to be > 0 }
27
- it { expect(client.connections(strategy: strategy, fields: [:name].join(',')).first).to include("name") }
28
- it { expect(client.connections(strategy: strategy, fields: [:name].join(','), include_fields: false).first).to_not include("name") }
25
+ it { expect(client.connections(strategy: strategy, fields: [:name].join(',')).first).to include('name') }
26
+ it do
27
+ expect(client.connections(strategy: strategy, fields: [:name].join(','), include_fields: false).first).to_not(
28
+ include('name'))
29
+ end
29
30
  end
30
-
31
31
  end
32
32
 
33
33
  describe '.connection' do
34
+ let(:subject) { client.connection(connection['id']) }
34
35
 
35
- let(:subject) { client.connection(connection["id"]) }
36
+ it { should include('name' => connection['name']) }
36
37
 
37
- it { should include("name" => connection['name']) }
38
-
39
- context "#filters" do
40
- it { expect(client.connection(connection["id"], fields: [:name, :id].join(','))).to include("id", "name") }
41
- it { expect(client.connection(connection["id"], fields: [:name, :id].join(','), include_fields: false)).to_not include("id", "name") }
38
+ context '#filters' do
39
+ it { expect(client.connection(connection['id'], fields: [:name, :id].join(','))).to include('id', 'name') }
40
+ it do
41
+ expect(client.connection(connection['id'], fields: [:name, :id].join(','), include_fields: false)).to_not(
42
+ include('id', 'name'))
43
+ end
42
44
  end
43
-
44
45
  end
45
46
 
46
47
  describe '.create_connection' do
47
-
48
48
  let(:subject) { connection }
49
49
 
50
- it { should include("id", "name") }
51
- it { should include(
52
- "name" => connection['name'],
53
- )}
54
-
50
+ it { should include('id', 'name') }
51
+ it { should include('name' => connection['name']) }
55
52
  end
56
53
 
57
54
  describe '.delete_connection' do
58
-
59
- it { expect { client.delete_connection connection["id"] }.to_not raise_error }
60
-
61
- it { expect { client.delete_connection "" }.to raise_error(Auth0::MissingConnectionId) }
62
-
55
+ it { expect { client.delete_connection connection['id'] }.to_not raise_error }
63
56
  end
64
57
 
65
-
66
58
  describe '.update_connection' do
59
+ let!(:connection_to_update) do
60
+ client.create_connection(name: "#{SecureRandom.uuid[0..25]}#{entity_suffix}",
61
+ strategy: strategy,
62
+ options: options,
63
+ enabled_clients: enabled_clients)
64
+ end
67
65
  new_name = SecureRandom.uuid[0..25]
68
- it { expect(client.update_connection(connection["id"], {"name" => new_name})).to include("name" => new_name) }
66
+ let(:options) { { username: new_name } }
67
+ it do
68
+ expect(client.update_connection(connection_to_update['id'], 'options' => options)['options']).to include(
69
+ 'username' => new_name)
70
+ end
69
71
  end
70
72
 
73
+ describe '.delete_connection_user' do
74
+ let(:username) { Faker::Internet.user_name }
75
+ let(:email) { "#{entity_suffix}#{Faker::Internet.safe_email(username)}" }
76
+ let(:password) { Faker::Internet.password }
77
+ let!(:user_to_delete) do
78
+ client.create_user(username, email: email,
79
+ password: password,
80
+ email_verified: false,
81
+ connection: Auth0::Api::AuthenticationEndpoints::UP_AUTH,
82
+ app_metadata: {})
83
+ end
84
+ let(:connection) do
85
+ client.connections.find { |connection| connection['name'] == Auth0::Api::AuthenticationEndpoints::UP_AUTH }
86
+ end
87
+
88
+ it { expect(client.delete_connection_user(connection['id'], email)).to be_nil }
89
+ end
90
+
91
+ after(:all) do
92
+ client
93
+ .connections
94
+ .select { |connection| connection['name'].include?(entity_suffix) }
95
+ .each { |connection| client.delete_connection(connection['id']) }
96
+ end
71
97
  end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::Emails do
3
+ before(:all) do
4
+ client = Auth0Client.new(v2_creds)
5
+ begin
6
+ client.delete_provider
7
+ rescue
8
+ puts 'no email provider to delete'
9
+ end
10
+ end
11
+
12
+ let(:client) { Auth0Client.new(v2_creds) }
13
+ let(:name) { 'mandrill' }
14
+ let(:enabled) { true }
15
+ let(:credentials) { { 'api_key' => 'api_key' } }
16
+ let(:settings) { { 'first_setting' => 'first_setting_set', 'second_setting' => 'second_setting_set' } }
17
+ let(:body) do
18
+ { 'name' => name,
19
+ 'enabled' => enabled,
20
+ 'credentials' => credentials,
21
+ 'settings' => settings }
22
+ end
23
+
24
+ describe '.configure_provider' do
25
+ let!(:email_provider) { client.configure_provider(body) }
26
+ it do
27
+ expect(email_provider).to include(
28
+ 'name' => name, 'enabled' => enabled, 'credentials' => credentials, 'settings' => settings)
29
+ end
30
+ end
31
+
32
+ describe '.get_provider' do
33
+ let(:provider) { client.get_provider }
34
+
35
+ it { expect(provider.size).to be > 0 }
36
+
37
+ context '#filters' do
38
+ it do
39
+ expect(
40
+ client.get_provider(fields: [:name, :enabled, :credentials].join(','), include_fields: true)).to(
41
+ include('name', 'enabled', 'credentials'))
42
+ end
43
+ it do
44
+ expect(
45
+ client.get_provider(fields: [:enabled].join(','), include_fields: false).first).to_not(include('enabled'))
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '.update_provider' do
51
+ let(:update_name) { 'sendgrid' }
52
+ let(:update_settings) do
53
+ { 'first_up_setting' => 'first_up_setting_set', 'second_up_setting' => 'second_up_setting_set' }
54
+ end
55
+ let(:update_body) do
56
+ { 'name' => update_name,
57
+ 'settings' => update_settings }
58
+ end
59
+ it do
60
+ expect(
61
+ client.update_provider(update_body)).to(
62
+ include(
63
+ 'name' => update_name, 'enabled' => enabled, 'credentials' => credentials, 'settings' => update_settings))
64
+ end
65
+ end
66
+
67
+ describe '.delete_provider' do
68
+ it { expect { client.delete_provider }.to_not raise_error }
69
+ it { expect { client.get_provider }.to raise_error(Auth0::NotFound) }
70
+ end
71
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::Jobs do
3
+ skip "Jobs examples are skipped to avoid Job's creation" do
4
+ let(:client) { Auth0Client.new(v2_creds) }
5
+ let(:username) { Faker::Internet.user_name }
6
+ let(:email) { "#{entity_suffix}#{Faker::Internet.safe_email(username)}" }
7
+
8
+ describe '.import_users and .get_job' do
9
+ let(:file_content) do
10
+ [{
11
+ 'email' => email,
12
+ 'email_verified' => false,
13
+ 'app_metadata' => {
14
+ 'roles' => ['admin'],
15
+ 'plan' => 'premium'
16
+ },
17
+ 'user_metadata' => {
18
+ 'theme' => 'light'
19
+ }
20
+ }
21
+ ]
22
+ end
23
+ let(:users_file) do
24
+ File.new('temp.json', 'w+') { |f| f.write(file_content) }
25
+ end
26
+ let(:connection_id) do
27
+ client.connections
28
+ .find do |connection|
29
+ connection['name'].include?(Auth0::Api::AuthenticationEndpoints::UP_AUTH)
30
+ end['id']
31
+ end
32
+ let(:imported_users) { client.import_users(users_file, connection_id) }
33
+ it do
34
+ expect(imported_users).to include(
35
+ 'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
36
+ 'status' => 'pending',
37
+ 'type' => 'users_import')
38
+ end
39
+ let(:import_job_id) { imported_users['id'] }
40
+ it do
41
+ expect(client.get_job(import_job_id)).to include(
42
+ 'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH, 'type' => 'users_import', 'id' => import_job_id)
43
+ end
44
+ end
45
+
46
+ describe '.send_verification_email and .get_job' do
47
+ let(:user) do
48
+ client.create_user(username, 'email' => email,
49
+ 'password' => Faker::Internet.password,
50
+ 'email_verified' => false,
51
+ 'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
52
+ 'app_metadata' => {})
53
+ end
54
+ let(:email_verification_job) { client.send_verification_email(user_id: user['user_id']) }
55
+ it { expect(email_verification_job).to include('status' => 'pending', 'type' => 'verification_email') }
56
+ let(:email_job_id) { email_verification_job['id'] }
57
+ it do
58
+ expect(client.get_job(email_job_id)).to include(
59
+ 'status' => 'completed', 'type' => 'verification_email', 'id' => email_job_id)
60
+ end
61
+ end
62
+
63
+ after(:all) do
64
+ new_client = Auth0Client.new(v2_creds)
65
+ delete_user_id = new_client.get_users(q: 'email:@example.com').first['user_id']
66
+ new_client.delete_user(delete_user_id)
67
+ end
68
+ end
69
+ end