auth0 4.0.0 → 4.1.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 (145) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +2 -1
  4. data/.rubocop_todo.yml +0 -2
  5. data/.travis.yml +4 -2
  6. data/CHANGELOG.md +40 -38
  7. data/DEPLOYMENT.md +5 -0
  8. data/Gemfile +1 -1
  9. data/README.md +20 -2
  10. data/Rakefile +1 -1
  11. data/auth0.gemspec +4 -3
  12. data/doc_config/templates/default/layout/html/footer.erb +1 -1
  13. data/examples/ruby-api/.gitignore +86 -0
  14. data/examples/ruby-api/Gemfile +8 -0
  15. data/examples/ruby-api/README.md +24 -0
  16. data/examples/ruby-api/config.ru +2 -0
  17. data/examples/ruby-api/main.rb +33 -0
  18. data/examples/ruby-on-rails-api/.gitignore +18 -0
  19. data/examples/ruby-on-rails-api/Gemfile +48 -0
  20. data/examples/ruby-on-rails-api/README.md +27 -0
  21. data/examples/ruby-on-rails-api/Rakefile +6 -0
  22. data/examples/ruby-on-rails-api/app/assets/images/.keep +0 -0
  23. data/examples/ruby-on-rails-api/app/assets/javascripts/application.js +16 -0
  24. data/examples/ruby-on-rails-api/app/assets/stylesheets/application.css +15 -0
  25. data/examples/ruby-on-rails-api/app/controllers/application_controller.rb +8 -0
  26. data/examples/ruby-on-rails-api/app/controllers/concerns/.keep +0 -0
  27. data/examples/ruby-on-rails-api/app/controllers/ping_controller.rb +6 -0
  28. data/examples/ruby-on-rails-api/app/controllers/secured_ping_controller.rb +11 -0
  29. data/examples/ruby-on-rails-api/app/helpers/application_helper.rb +3 -0
  30. data/examples/ruby-on-rails-api/app/mailers/.keep +0 -0
  31. data/examples/ruby-on-rails-api/app/models/.keep +0 -0
  32. data/examples/ruby-on-rails-api/app/models/concerns/.keep +0 -0
  33. data/examples/ruby-on-rails-api/app/views/layouts/application.html.erb +14 -0
  34. data/examples/ruby-on-rails-api/bin/bundle +3 -0
  35. data/examples/ruby-on-rails-api/bin/rails +4 -0
  36. data/examples/ruby-on-rails-api/bin/rake +4 -0
  37. data/examples/ruby-on-rails-api/bin/setup +29 -0
  38. data/examples/ruby-on-rails-api/config.ru +4 -0
  39. data/examples/ruby-on-rails-api/config/application.rb +23 -0
  40. data/examples/ruby-on-rails-api/config/boot.rb +4 -0
  41. data/examples/ruby-on-rails-api/config/database.yml +27 -0
  42. data/examples/ruby-on-rails-api/config/environment.rb +5 -0
  43. data/examples/ruby-on-rails-api/config/environments/development.rb +37 -0
  44. data/examples/ruby-on-rails-api/config/environments/production.rb +83 -0
  45. data/examples/ruby-on-rails-api/config/environments/test.rb +41 -0
  46. data/examples/ruby-on-rails-api/config/initializers/backtrace_silencers.rb +7 -0
  47. data/examples/ruby-on-rails-api/config/initializers/cookies_serializer.rb +3 -0
  48. data/examples/ruby-on-rails-api/config/initializers/dotenv.rb +4 -0
  49. data/examples/ruby-on-rails-api/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/examples/ruby-on-rails-api/config/initializers/inflections.rb +16 -0
  51. data/examples/ruby-on-rails-api/config/initializers/knock.rb +53 -0
  52. data/examples/ruby-on-rails-api/config/initializers/mime_types.rb +4 -0
  53. data/examples/ruby-on-rails-api/config/initializers/session_store.rb +3 -0
  54. data/examples/ruby-on-rails-api/config/initializers/wrap_parameters.rb +14 -0
  55. data/examples/ruby-on-rails-api/config/locales/en.yml +23 -0
  56. data/examples/ruby-on-rails-api/config/routes.rb +58 -0
  57. data/examples/ruby-on-rails-api/config/secrets.yml +28 -0
  58. data/examples/ruby-on-rails-api/db/schema.rb +15 -0
  59. data/examples/ruby-on-rails-api/db/seeds.rb +7 -0
  60. data/examples/ruby-on-rails-api/lib/assets/.keep +0 -0
  61. data/examples/ruby-on-rails-api/lib/tasks/.keep +0 -0
  62. data/examples/ruby-on-rails-api/log/.keep +0 -0
  63. data/examples/ruby-on-rails-api/public/404.html +67 -0
  64. data/examples/ruby-on-rails-api/public/422.html +67 -0
  65. data/examples/ruby-on-rails-api/public/500.html +66 -0
  66. data/examples/ruby-on-rails-api/public/favicon.ico +0 -0
  67. data/examples/ruby-on-rails-api/public/robots.txt +5 -0
  68. data/examples/ruby-on-rails-api/test/controllers/.keep +0 -0
  69. data/examples/ruby-on-rails-api/test/fixtures/.keep +0 -0
  70. data/examples/ruby-on-rails-api/test/helpers/.keep +0 -0
  71. data/examples/ruby-on-rails-api/test/integration/.keep +0 -0
  72. data/examples/ruby-on-rails-api/test/mailers/.keep +0 -0
  73. data/examples/ruby-on-rails-api/test/models/.keep +0 -0
  74. data/examples/ruby-on-rails-api/test/ping_controller_test.rb +8 -0
  75. data/examples/ruby-on-rails-api/test/secured_ping_controller_test.rb +26 -0
  76. data/examples/ruby-on-rails-api/test/test_helper.rb +16 -0
  77. data/lib/auth0/api/authentication_endpoints.rb +59 -30
  78. data/lib/auth0/api/v1/clients.rb +1 -1
  79. data/lib/auth0/api/v1/connections.rb +4 -3
  80. data/lib/auth0/api/v1/logs.rb +1 -1
  81. data/lib/auth0/api/v1/rules.rb +1 -1
  82. data/lib/auth0/api/v1/users.rb +5 -5
  83. data/lib/auth0/api/v2.rb +10 -0
  84. data/lib/auth0/api/v2/blacklists.rb +1 -1
  85. data/lib/auth0/api/v2/client_grants.rb +57 -0
  86. data/lib/auth0/api/v2/clients.rb +14 -14
  87. data/lib/auth0/api/v2/connections.rb +19 -20
  88. data/lib/auth0/api/v2/device_credentials.rb +76 -0
  89. data/lib/auth0/api/v2/emails.rb +5 -7
  90. data/lib/auth0/api/v2/jobs.rb +15 -12
  91. data/lib/auth0/api/v2/logs.rb +65 -0
  92. data/lib/auth0/api/v2/resource_servers.rb +61 -0
  93. data/lib/auth0/api/v2/rules.rb +21 -20
  94. data/lib/auth0/api/v2/stats.rb +2 -2
  95. data/lib/auth0/api/v2/tenants.rb +6 -4
  96. data/lib/auth0/api/v2/tickets.rb +13 -14
  97. data/lib/auth0/api/v2/user_blocks.rb +62 -0
  98. data/lib/auth0/api/v2/users.rb +63 -32
  99. data/lib/auth0/client.rb +0 -2
  100. data/lib/auth0/mixins.rb +4 -3
  101. data/lib/auth0/mixins/httpproxy.rb +55 -0
  102. data/lib/auth0/mixins/initializer.rb +27 -10
  103. data/lib/auth0/version.rb +1 -1
  104. data/spec/integration/lib/auth0/api/api_authentication_spec.rb +118 -0
  105. data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +1 -1
  106. data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +53 -0
  107. data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +5 -2
  108. data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +8 -5
  109. data/spec/integration/lib/auth0/api/v2/api_device_credentials_spec.rb +67 -0
  110. data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +15 -8
  111. data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +11 -9
  112. data/spec/integration/lib/auth0/api/v2/api_logs_spec.rb +69 -0
  113. data/spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb +47 -0
  114. data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +2 -1
  115. data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +2 -2
  116. data/spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb +73 -0
  117. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +32 -5
  118. data/spec/integration/lib/auth0/auth0_client_spec.rb +14 -11
  119. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +116 -56
  120. data/spec/lib/auth0/api/v1/connections_spec.rb +2 -4
  121. data/spec/lib/auth0/api/v1/rules_spec.rb +2 -1
  122. data/spec/lib/auth0/api/v1/users_spec.rb +17 -9
  123. data/spec/lib/auth0/api/v2/client_grants_spec.rb +44 -0
  124. data/spec/lib/auth0/api/v2/connections_spec.rb +2 -1
  125. data/spec/lib/auth0/api/v2/device_credentials_spec.rb +73 -0
  126. data/spec/lib/auth0/api/v2/jobs_spec.rb +3 -2
  127. data/spec/lib/auth0/api/v2/logs_spec.rb +48 -0
  128. data/spec/lib/auth0/api/v2/resource_servers_spec.rb +63 -0
  129. data/spec/lib/auth0/api/v2/rules_spec.rb +8 -4
  130. data/spec/lib/auth0/api/v2/tenants_spec.rb +2 -1
  131. data/spec/lib/auth0/api/v2/tickets_spec.rb +4 -7
  132. data/spec/lib/auth0/api/v2/user_blocks_spec.rb +52 -0
  133. data/spec/lib/auth0/api/v2/users_spec.rb +39 -6
  134. data/spec/lib/auth0/client_spec.rb +8 -5
  135. data/spec/lib/auth0/mixins/httpproxy_spec.rb +225 -0
  136. data/spec/lib/auth0/mixins/initializer_spec.rb +1 -1
  137. data/spec/spec_helper_full.rb +12 -3
  138. data/spec/spec_helper_unit.rb +2 -2
  139. data/spec/support/credentials.rb +6 -4
  140. data/spec/support/dummy_class.rb +2 -1
  141. data/spec/support/dummy_class_for_proxy.rb +2 -2
  142. data/spec/support/dummy_class_for_restclient.rb +2 -0
  143. metadata +117 -9
  144. data/lib/auth0/mixins/httparty_proxy.rb +0 -38
  145. data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +0 -148
@@ -17,29 +17,30 @@ describe Auth0::Api::V2::Jobs do
17
17
  'user_metadata' => {
18
18
  'theme' => 'light'
19
19
  }
20
- }
21
- ]
20
+ }]
22
21
  end
23
22
  let(:users_file) do
24
23
  File.new('temp.json', 'w+') { |f| f.write(file_content) }
25
24
  end
26
25
  let(:connection_id) do
27
26
  client.connections
28
- .find do |connection|
29
- connection['name'].include?(Auth0::Api::AuthenticationEndpoints::UP_AUTH)
30
- end['id']
27
+ .find do |connection|
28
+ connection['name'].include?(Auth0::Api::AuthenticationEndpoints::UP_AUTH)
29
+ end['id']
31
30
  end
32
31
  let(:imported_users) { client.import_users(users_file, connection_id) }
33
32
  it do
34
33
  expect(imported_users).to include(
35
34
  'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
36
35
  'status' => 'pending',
37
- 'type' => 'users_import')
36
+ 'type' => 'users_import'
37
+ )
38
38
  end
39
39
  let(:import_job_id) { imported_users['id'] }
40
40
  it do
41
41
  expect(client.get_job(import_job_id)).to include(
42
- 'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH, 'type' => 'users_import', 'id' => import_job_id)
42
+ 'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH, 'type' => 'users_import', 'id' => import_job_id
43
+ )
43
44
  end
44
45
  end
45
46
 
@@ -51,12 +52,13 @@ describe Auth0::Api::V2::Jobs do
51
52
  'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
52
53
  'app_metadata' => {})
53
54
  end
54
- let(:email_verification_job) { client.send_verification_email(user_id: user['user_id']) }
55
+ let(:email_verification_job) { client.send_verification_email(user['user_id']) }
55
56
  it { expect(email_verification_job).to include('status' => 'pending', 'type' => 'verification_email') }
56
57
  let(:email_job_id) { email_verification_job['id'] }
57
58
  it do
58
59
  expect(client.get_job(email_job_id)).to include(
59
- 'status' => 'completed', 'type' => 'verification_email', 'id' => email_job_id)
60
+ 'status' => 'completed', 'type' => 'verification_email', 'id' => email_job_id
61
+ )
60
62
  end
61
63
  end
62
64
 
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Auth0::Api::V2::Logs do
4
+ attr_reader :client, :user
5
+
6
+ before(:all) do
7
+ @client = Auth0Client.new(v2_creds)
8
+ username = Faker::Internet.user_name
9
+ email = "#{entity_suffix}#{Faker::Internet.safe_email(username)}"
10
+ password = Faker::Internet.password
11
+ @user = client.create_user(username, 'email' => email,
12
+ 'password' => password,
13
+ 'email_verified' => false,
14
+ 'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
15
+ 'app_metadata' => {})
16
+ end
17
+
18
+ after(:all) do
19
+ client.delete_user(user['user_id'])
20
+ end
21
+
22
+ describe '.logs' do
23
+ let(:logs) { client.logs }
24
+ it 'is expected to get a log about user creation' do
25
+ wait 30 do
26
+ expect(find_create_user_log_by_email(user['email'])).to_not be_empty
27
+ end
28
+ end
29
+
30
+ context '#filters' do
31
+ it { expect(client.logs(per_page: 1).size).to be 1 }
32
+ it do
33
+ expect(
34
+ client.logs(per_page: 1, fields: [:date, :description, :type].join(','), include_fields: true).first
35
+ ).to(include('date', 'description', 'type'))
36
+ end
37
+ it { expect(client.logs(per_page: 1, fields: [:date].join(',')).first).to_not include('type', 'description') }
38
+ it do
39
+ expect(
40
+ client.logs(per_page: 1, fields: [:date].join(','), include_fields: false).first
41
+ ).to include('type', 'description')
42
+ end
43
+ end
44
+
45
+ context '#from' do
46
+ it { expect(client.logs(from: logs.last['_id'], take: 1).size).to be 1 }
47
+ it { expect(client.logs(from: logs.first['_id'], take: 1).size).to be 0 }
48
+ end
49
+ end
50
+
51
+ describe '.log' do
52
+ let(:first_log) { client.logs.first }
53
+ let(:log) { client.log(first_log['_id']) }
54
+ it { expect(log).to_not be_empty }
55
+ it { expect(log['_id']).to eq(first_log['_id']) }
56
+ it { expect(log['date']).to eq(first_log['date']) }
57
+ end
58
+
59
+ private
60
+
61
+ def find_create_user_log_by_email(email)
62
+ logs = client.logs
63
+ logs.find do |log|
64
+ log['description'] == 'Create a user' &&
65
+ log['type'] == 'sapi' &&
66
+ log['details']['request']['body']['email'] == email
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::ResourceServers do
3
+ attr_reader :client, :resource_server
4
+
5
+ before(:all) do
6
+ @client = Auth0Client.new(v2_creds)
7
+ identifier = SecureRandom.uuid
8
+ @resource_server = client.create_resource_server(identifier)
9
+ end
10
+
11
+ after(:all) do
12
+ client.delete_resource_server(resource_server['id'])
13
+ end
14
+
15
+ describe '.resource_server' do
16
+ it do
17
+ expect(client.resource_server(resource_server['id'])).to(
18
+ include('identifier' => resource_server['identifier'], 'id' => resource_server['id'],
19
+ 'signing_alg' => resource_server['signing_alg'],
20
+ 'token_lifetime' => resource_server['token_lifetime'])
21
+ )
22
+ end
23
+ end
24
+
25
+ describe '.create_resource_server' do
26
+ let(:name) { Faker::Lorem.word }
27
+ let(:identifier) { SecureRandom.uuid }
28
+ let(:signing_alg) { 'HS256' }
29
+ let(:signing_secret) { Faker::Lorem.characters(16) }
30
+ let(:token_lifetime) { rand(1000..3000) }
31
+ let!(:resource_server) do
32
+ client.create_resource_server(identifier, 'name' => name, 'signing_alg' => signing_alg,
33
+ 'signing_secret' => signing_secret,
34
+ 'token_lifetime' => token_lifetime)
35
+ end
36
+ it do
37
+ expect(resource_server).to include('name' => name, 'identifier' => identifier, 'signing_alg' => signing_alg,
38
+ 'signing_secret' => signing_secret,
39
+ 'token_lifetime' => token_lifetime)
40
+ end
41
+ it { expect { client.delete_resource_server(resource_server['id']) }.to_not raise_error }
42
+ end
43
+
44
+ describe '.delete_resource_server' do
45
+ it { expect { client.delete_resource_server(resource_server['id']) }.to_not raise_error }
46
+ end
47
+ end
@@ -44,7 +44,8 @@ describe Auth0::Api::V2::Rules do
44
44
  describe '.rule' do
45
45
  it do
46
46
  expect(client.rule(enabled_rule['id'])).to(
47
- include('stage' => enabled_rule['stage'], 'order' => enabled_rule['order'], 'script' => enabled_rule['script']))
47
+ include('stage' => enabled_rule['stage'], 'order' => enabled_rule['order'], 'script' => enabled_rule['script'])
48
+ )
48
49
  end
49
50
 
50
51
  context '#filters' do
@@ -25,8 +25,8 @@ describe Auth0::Api::V2::Tickets do
25
25
 
26
26
  describe '.post_password_change' do
27
27
  let(:password_change) do
28
- client.post_password_change('secret', user_id: user['user_id'],
29
- result_url: 'http://myapp.com/callback')
28
+ client.post_password_change(new_password: 'secret', user_id: user['user_id'],
29
+ result_url: 'http://myapp.com/callback')
30
30
  end
31
31
  it { expect(password_change).to include('ticket') }
32
32
  end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+ describe Auth0::Api::V2::UserBlocks do
3
+ attr_reader :client, :user, :email
4
+
5
+ skip 'User blocks examples are skipped since is #logins exceeds free tenant limits' do
6
+ before(:all) do
7
+ @client = Auth0Client.new(v2_creds)
8
+ username = Faker::Internet.user_name
9
+ @email = "#{entity_suffix}#{Faker::Internet.safe_email(username)}"
10
+ password = Faker::Internet.password
11
+ @user = client.create_user(username, 'email' => email,
12
+ 'password' => password,
13
+ 'email_verified' => true,
14
+ 'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
15
+ 'app_metadata' => {})
16
+ end
17
+
18
+ after(:all) do
19
+ client.delete_user(user['user_id'])
20
+ end
21
+
22
+ describe '.user_blocks' do
23
+ let(:user_blocks) do
24
+ block_user(email)
25
+ client.user_blocks(email)
26
+ end
27
+ it { expect(user_blocks['blocked_for'].size).to be > 0 }
28
+ it { expect(user_blocks['blocked_for'].first['identifier']).to eq email }
29
+ end
30
+
31
+ describe '.user_blocks_by_id' do
32
+ let(:user_blocks) do
33
+ block_user(email)
34
+ client.user_blocks_by_id(user['user_id'])
35
+ end
36
+ it { expect(user_blocks['blocked_for'].size).to be > 0 }
37
+ it { expect(user_blocks['blocked_for'].first['identifier']).to eq email }
38
+ end
39
+
40
+ describe '.delete_user_blocks' do
41
+ let(:user_blocks) do
42
+ block_user(email)
43
+ client.delete_user_blocks(email)
44
+ client.user_blocks(email)
45
+ end
46
+ it { expect(user_blocks['blocked_for']).to eq [] }
47
+ end
48
+
49
+ describe '.delete_user_blocks_by_id' do
50
+ let(:user_blocks) do
51
+ block_user(email)
52
+ client.delete_user_blocks_by_id(user['user_id'])
53
+ client.user_blocks(email)
54
+ end
55
+ it { expect(user_blocks['blocked_for']).to eq [] }
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def block_user(email)
62
+ 100.times do
63
+ begin
64
+ client.login(email, 'invalid password')
65
+ rescue Auth0::Unauthorized
66
+ next
67
+ rescue Auth0::Unsupported => e
68
+ puts e.message
69
+ break
70
+ end
71
+ end
72
+ end
73
+ end
@@ -51,7 +51,8 @@ describe Auth0::Api::V2::Users do
51
51
  context '#filters' do
52
52
  it do
53
53
  expect(client.user(user['user_id'], fields: [:picture, :email, :user_id].join(','))).to(
54
- include('email', 'user_id', 'picture'))
54
+ include('email', 'user_id', 'picture')
55
+ )
55
56
  end
56
57
  it { expect(client.user(user['user_id'], fields: [:email].join(','))).to_not include('user_id', 'picture') }
57
58
  end
@@ -110,11 +111,37 @@ describe Auth0::Api::V2::Users do
110
111
  client.link_user_account(primary_user['user_id'], body_link).first
111
112
  ).to include('provider' => 'auth0', 'user_id' => primary_user['identities'].first['user_id'])
112
113
  end
114
+
115
+ it do
116
+ expect(
117
+ client.unlink_users_account(primary_user['user_id'], 'auth0', link_user['user_id']).first
118
+ ).to include('provider' => 'auth0', 'user_id' => primary_user['identities'].first['user_id'])
119
+ end
113
120
  end
114
- it do
115
- expect(
116
- client.unlink_users_account(primary_user['user_id'], 'auth0', link_user['user_id']).first
117
- ).to include('provider' => 'auth0', 'user_id' => primary_user['identities'].first['user_id'])
121
+ end
122
+
123
+ describe '.user_logs' do
124
+ it 'is expected that the user logs contain a success signup log entry' do
125
+ wait 30 do
126
+ user_logs = client.user_logs(user['user_id'])
127
+ expect(user_logs.size).to be > 0
128
+ expect(find_success_signup_log_by_email(user['email'], user_logs)).to_not be_empty
129
+ end
130
+ end
131
+
132
+ context '#filters' do
133
+ it do
134
+ wait 30 do
135
+ expect(client.user_logs(user['user_id'], per_page: 1).size).to be 1
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ def find_success_signup_log_by_email(email, logs)
142
+ logs.find do |log|
143
+ log['type'] == 'ss' &&
144
+ log['details']['body']['email'] == email
118
145
  end
119
146
  end
120
147
  end
@@ -12,26 +12,32 @@ describe Auth0::Client do
12
12
 
13
13
  it_should_behave_like 'invalid credentials', { namespace: 'samples.auth0.com' }, Auth0::InvalidCredentials
14
14
  it_should_behave_like 'invalid credentials', {
15
- namespace: 'samples.auth0.com', client_id: 'client_id' }, Auth0::InvalidCredentials
15
+ namespace: 'samples.auth0.com', client_id: 'client_id'
16
+ }, Auth0::InvalidCredentials
16
17
  it_should_behave_like 'invalid credentials', {
17
- namespace: 'samples.auth0.com', client_secret: 'secret' }, Auth0::InvalidCredentials
18
+ namespace: 'samples.auth0.com', client_secret: 'secret'
19
+ }, Auth0::InvalidCredentials
18
20
  it_should_behave_like 'invalid credentials', {
19
- namespace: 'samples.auth0.com', api_version: 2 }, Auth0::InvalidCredentials
21
+ namespace: 'samples.auth0.com', api_version: 2
22
+ }, Auth0::InvalidCredentials
20
23
  it_should_behave_like 'invalid credentials', {}
21
24
  it_should_behave_like 'invalid credentials', api_version: 2
22
25
  it_should_behave_like 'invalid credentials', api_version: 1
23
26
  it_should_behave_like 'invalid credentials', {
24
- client_id: 'client_id', client_secret: 'secret' }, Auth0::InvalidApiNamespace
27
+ client_id: 'client_id', client_secret: 'secret'
28
+ }, Auth0::InvalidApiNamespace
25
29
  it_should_behave_like 'invalid credentials', {
26
- api_version: 2, token: 'token' }, Auth0::InvalidApiNamespace
30
+ api_version: 2, token: 'token'
31
+ }, Auth0::InvalidApiNamespace
27
32
 
28
33
  let(:valid_v1_credentials) do
29
34
  { client_id: ENV['CLIENT_ID'],
30
35
  client_secret: ENV['CLIENT_SECRET'],
31
- domain: ENV['DOMAIN'] }
36
+ domain: ENV['DOMAIN'],
37
+ api_version: 1 }
32
38
  end
33
39
  let(:token) { ENV['MASTER_JWT'] }
34
- let(:v2_credentials) { { domain: ENV['DOMAIN'], api_version: 2 } }
40
+ let(:v2_credentials) { { domain: ENV['DOMAIN'] } }
35
41
 
36
42
  shared_examples 'valid credentials' do
37
43
  it { expect { Auth0Client.new(credentials) }.to_not raise_error }
@@ -40,9 +46,6 @@ describe Auth0::Client do
40
46
  it_should_behave_like 'valid credentials' do
41
47
  let(:credentials) { valid_v1_credentials }
42
48
  end
43
- it_should_behave_like 'valid credentials' do
44
- let(:credentials) { valid_v1_credentials.merge(api_version: 1) }
45
- end
46
49
  it_should_behave_like 'valid credentials' do
47
50
  let(:credentials) { v2_credentials.merge(token: token) }
48
51
  end
@@ -52,7 +55,7 @@ describe Auth0::Client do
52
55
 
53
56
  context 'client headers' do
54
57
  let(:client) { Auth0::Client.new(v2_credentials.merge(access_token: 'abc123', domain: 'myhost.auth0.com')) }
55
- let(:headers) { client.class.headers }
58
+ let(:headers) { client.headers }
56
59
 
57
60
  let(:base64_token) do
58
61
  Base64.urlsafe_encode64('{"name":"ruby-auth0","version":"' + Auth0::VERSION + '"}')
@@ -11,10 +11,12 @@ describe Auth0::Api::AuthenticationEndpoints do
11
11
  it { expect(@instance).to respond_to(:obtain_access_token) }
12
12
  it "is expected to make post request to '/oauth/token'" do
13
13
  allow(@instance).to receive(:post).with(
14
- '/oauth/token', client_id: nil, client_secret: nil, grant_type: 'client_credentials')
14
+ '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'client_credentials'
15
+ )
15
16
  .and_return('access_token' => 'AccessToken')
16
17
  expect(@instance).to receive(:post).with(
17
- '/oauth/token', client_id: nil, client_secret: nil, grant_type: 'client_credentials')
18
+ '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'client_credentials'
19
+ )
18
20
  expect(@instance.obtain_access_token).to eql 'AccessToken'
19
21
  end
20
22
  end
@@ -23,22 +25,45 @@ describe Auth0::Api::AuthenticationEndpoints do
23
25
  it { expect(@instance).to respond_to(:obtain_access_token) }
24
26
  it "is expected to make post request to '/oauth/access_token'" do
25
27
  allow(@instance).to receive(:post).with(
26
- '/oauth/access_token', client_id: nil, access_token: 'access_token', connection: 'facebook', scope: 'openid')
28
+ '/oauth/access_token', client_id: @instance.client_id, access_token: 'access_token', connection: 'facebook',
29
+ scope: 'openid'
30
+ )
27
31
  .and_return('access_token' => 'AccessToken')
28
32
  expect(@instance).to receive(:post).with(
29
- '/oauth/access_token', client_id: nil, access_token: 'access_token', connection: 'facebook', scope: 'openid')
33
+ '/oauth/access_token', client_id: @instance.client_id, access_token: 'access_token', connection: 'facebook',
34
+ scope: 'openid'
35
+ )
30
36
  expect(@instance.obtain_access_token('access_token', 'facebook', 'openid')).to eql 'AccessToken'
31
37
  end
32
38
  end
33
39
 
40
+ context '.obtain_user_tokens' do
41
+ it { expect(@instance).to respond_to(:obtain_user_tokens) }
42
+ it "is expected to make post request to '/oauth/token'" do
43
+ allow(@instance).to receive(:post).with(
44
+ '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'authorization_code',
45
+ connection: 'facebook', code: 'code', scope: 'openid', redirect_uri: 'uri'
46
+ )
47
+ .and_return('user_tokens' => 'UserToken')
48
+ expect(@instance).to receive(:post).with(
49
+ '/oauth/token', client_id: @instance.client_id, client_secret: nil, grant_type: 'authorization_code',
50
+ connection: 'facebook', code: 'code', scope: 'openid', redirect_uri: 'uri'
51
+ )
52
+ expect(@instance.obtain_user_tokens('code', 'uri')['user_tokens']).to eq 'UserToken'
53
+ end
54
+ it { expect { @instance.obtain_user_tokens('', '') }.to raise_error 'Must supply a valid code' }
55
+ it { expect { @instance.obtain_user_tokens('code', '') }.to raise_error 'Must supply a valid redirect_uri' }
56
+ end
57
+
34
58
  context '.login' do
35
59
  it { expect(@instance).to respond_to(:login) }
36
60
  it 'is expected to make post to /oauth/ro' do
37
61
  expect(@instance).to receive(:post).with(
38
62
  '/oauth/ro',
39
- client_id: nil, username: 'test@test.com',
63
+ client_id: @instance.client_id, username: 'test@test.com',
40
64
  password: 'password', scope: 'openid', connection: 'Username-Password-Authentication',
41
- grant_type: 'password', id_token: nil, device: nil)
65
+ grant_type: 'password', id_token: nil, device: nil
66
+ )
42
67
  @instance.login('test@test.com', 'password')
43
68
  end
44
69
  it { expect { @instance.login('', '') }.to raise_error 'Must supply a valid username' }
@@ -50,8 +75,9 @@ describe Auth0::Api::AuthenticationEndpoints do
50
75
  it 'is expected to make post to /dbconnections/signup' do
51
76
  expect(@instance).to receive(:post).with(
52
77
  '/dbconnections/signup',
53
- client_id: nil, email: 'test@test.com',
54
- password: 'password', connection: 'User')
78
+ client_id: @instance.client_id, email: 'test@test.com',
79
+ password: 'password', connection: 'User'
80
+ )
55
81
  @instance.signup('test@test.com', 'password', 'User')
56
82
  end
57
83
  it { expect { @instance.signup('', '') }.to raise_error 'Must supply a valid email' }
@@ -63,8 +89,9 @@ describe Auth0::Api::AuthenticationEndpoints do
63
89
  it 'is expected to make post to /dbconnections/change_password' do
64
90
  expect(@instance).to receive(:post).with(
65
91
  '/dbconnections/change_password',
66
- client_id: nil, email: 'test@test.com',
67
- password: 'password', connection: 'User')
92
+ client_id: @instance.client_id, email: 'test@test.com',
93
+ password: 'password', connection: 'User'
94
+ )
68
95
  @instance.change_password('test@test.com', 'password', 'User')
69
96
  end
70
97
  it { expect { @instance.change_password('', '', '') }.to raise_error 'Must supply a valid email' }
@@ -75,13 +102,15 @@ describe Auth0::Api::AuthenticationEndpoints do
75
102
  it 'is expected to make post to /passwordless/start' do
76
103
  expect(@instance).to receive(:post).with(
77
104
  '/passwordless/start',
78
- client_id: nil,
105
+ client_id: @instance.client_id,
106
+ connection: 'email',
79
107
  email: 'test@test.com',
80
108
  send: 'link',
81
- auth_params: {
109
+ authParams: {
82
110
  scope: 'scope',
83
111
  protocol: 'protocol'
84
- })
112
+ }
113
+ )
85
114
  @instance.start_passwordless_email_flow('test@test.com', 'link', scope: 'scope', protocol: 'protocol')
86
115
  end
87
116
  it { expect { @instance.start_passwordless_email_flow('', '', '') }.to raise_error 'Must supply a valid email' }
@@ -93,9 +122,10 @@ describe Auth0::Api::AuthenticationEndpoints do
93
122
  it 'is expected to make post to /passwordless/start' do
94
123
  expect(@instance).to receive(:post).with(
95
124
  '/passwordless/start',
96
- client_id: nil,
125
+ client_id: @instance.client_id,
97
126
  connection: 'sms',
98
- phone_number: phone_number)
127
+ phone_number: phone_number
128
+ )
99
129
  @instance.start_passwordless_sms_flow(phone_number)
100
130
  end
101
131
  it { expect { @instance.start_passwordless_sms_flow('') }.to raise_error 'Must supply a valid phone number' }
@@ -108,9 +138,10 @@ describe Auth0::Api::AuthenticationEndpoints do
108
138
  it 'is expected to make post to /oauth/ro' do
109
139
  expect(@instance).to receive(:post).with(
110
140
  '/oauth/ro',
111
- client_id: nil, username: phone_number,
141
+ client_id: @instance.client_id, username: phone_number,
112
142
  password: code, connection: 'sms',
113
- scope: 'openid', grant_type: 'password')
143
+ scope: 'openid', grant_type: 'password'
144
+ )
114
145
  @instance.phone_login(phone_number, code)
115
146
  end
116
147
  it { expect { @instance.phone_login('', '') }.to raise_error 'Must supply a valid phone number' }
@@ -118,13 +149,11 @@ describe Auth0::Api::AuthenticationEndpoints do
118
149
  end
119
150
 
120
151
  context '.saml_metadata' do
121
- let(:client_id) { 'client-id' }
122
152
  it { expect(@instance).to respond_to(:saml_metadata) }
123
153
  it 'is expected to make post to /samlp/metadata/client-id' do
124
- expect(@instance).to receive(:get).with("/samlp/metadata/#{client_id}")
125
- @instance.saml_metadata(client_id)
154
+ expect(@instance).to receive(:get).with("/samlp/metadata/#{@instance.client_id}")
155
+ @instance.saml_metadata
126
156
  end
127
- it { expect { @instance.saml_metadata('') }.to raise_error 'Must supply a valid client_id' }
128
157
  end
129
158
 
130
159
  context '.wsfed_metadata' do
@@ -136,21 +165,34 @@ describe Auth0::Api::AuthenticationEndpoints do
136
165
  end
137
166
 
138
167
  context '.authorization_url' do
139
- let(:redirect_url) { 'http://redirect.com' }
168
+ let(:redirect_uri) { 'http://redirect.com' }
140
169
  it { expect(@instance).to respond_to(:authorization_url) }
141
170
  it 'is expected to return an authorization url' do
142
- expect(@instance.authorization_url(redirect_url).to_s).to eq(
143
- "https://#{@instance.domain}/authorize?response_type=code&redirect_url=#{redirect_url}")
171
+ expect(@instance.authorization_url(redirect_uri).to_s).to eq(
172
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
173
+ "redirect_uri=#{redirect_uri}"
174
+ )
144
175
  end
145
176
  let(:additional_parameters) { { additional_parameters: { aparam1: 'test1' } } }
146
177
  it 'is expected to return an authorization url with additionalParameters' do
147
- expect(@instance.authorization_url(redirect_url, additional_parameters).to_s).to eq(
148
- "https://#{@instance.domain}/authorize?response_type=code&redirect_url=#{redirect_url}&aparam1=test1")
178
+ expect(@instance.authorization_url(redirect_uri, additional_parameters).to_s).to eq(
179
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
180
+ "redirect_uri=#{redirect_uri}&aparam1=test1"
181
+ )
149
182
  end
150
183
  let(:state) { { state: 'state1' } }
151
184
  it 'is expected to return an authorization url with additionalParameters' do
152
- expect(@instance.authorization_url(redirect_url, state).to_s).to eq(
153
- "https://#{@instance.domain}/authorize?response_type=code&redirect_url=#{redirect_url}&state=state1")
185
+ expect(@instance.authorization_url(redirect_uri, state).to_s).to eq(
186
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
187
+ "redirect_uri=#{redirect_uri}&state=state1"
188
+ )
189
+ end
190
+ let(:connection) { { connection: 'connection-1' } }
191
+ it 'is expected to return an authorization url with additionalParameters' do
192
+ expect(@instance.authorization_url(redirect_uri, connection).to_s).to eq(
193
+ "https://#{@instance.domain}/authorize?client_id=#{@instance.client_id}&response_type=code&"\
194
+ "connection=connection-1&redirect_uri=#{redirect_uri}"
195
+ )
154
196
  end
155
197
  it { expect { @instance.authorization_url('', '') }.to raise_error 'Must supply a valid redirect_uri' }
156
198
  end
@@ -168,10 +210,11 @@ describe Auth0::Api::AuthenticationEndpoints do
168
210
  it "is expected to make post request to '/delegation'" do
169
211
  expect(@instance).to receive(:post).with(
170
212
  '/delegation',
171
- client_id: nil,
213
+ client_id: @instance.client_id,
172
214
  grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
173
215
  refresh_token: 'id_token', target: '', api_type: '', scope: '',
174
- additional_parameter: 'parameter')
216
+ additional_parameter: 'parameter'
217
+ )
175
218
  @instance.refresh_delegation('id_token', '', '', '', additional_parameter: 'parameter')
176
219
  end
177
220
  it { expect { @instance.refresh_delegation('', '', '', '') }.to raise_error 'Must supply a valid token to refresh' }
@@ -182,55 +225,67 @@ describe Auth0::Api::AuthenticationEndpoints do
182
225
  it "is expected to make post request to '/delegation'" do
183
226
  expect(@instance).to receive(:post).with(
184
227
  '/delegation',
185
- client_id: nil,
228
+ client_id: @instance.client_id,
186
229
  grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
187
230
  id_token: 'token',
188
231
  target: 'target',
189
232
  scope: '',
190
- api_type: 'app')
233
+ api_type: 'app'
234
+ )
191
235
  @instance.delegation('token', 'target', '')
192
236
  end
193
237
  it "is expected to make post request to '/delegation'
194
238
  with specified api_type" do
195
239
  expect(@instance).to receive(:post).with(
196
240
  '/delegation',
197
- client_id: nil,
241
+ client_id: @instance.client_id,
198
242
  grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
199
243
  id_token: 'id_token', target: '', scope: '',
200
- api_type: 'salesforce_api')
244
+ api_type: 'salesforce_api'
245
+ )
201
246
  @instance.delegation('id_token', '', '', 'salesforce_api')
202
247
  end
203
248
  it 'allows to pass extra parameters' do
204
249
  expect(@instance).to receive(:post).with(
205
250
  '/delegation',
206
- client_id: nil,
251
+ client_id: @instance.client_id,
207
252
  grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
208
253
  id_token: 'id_token', target: '', scope: '', api_type: '',
209
- community_name: 'test-community', community_url: 'test-url')
254
+ community_name: 'test-community', community_url: 'test-url'
255
+ )
210
256
  @instance.delegation(
211
257
  'id_token', '', '', '',
212
- community_name: 'test-community', community_url: 'test-url')
258
+ community_name: 'test-community', community_url: 'test-url'
259
+ )
213
260
  end
214
261
  it { expect { @instance.delegation('', nil, nil, nil) }.to raise_error 'Must supply a valid id_token' }
215
262
  end
216
263
 
217
264
  context '.impersonate' do
218
- let(:user_id) { 'some_user_id' }
219
- let(:app_client_id) { 'some_app_client_id' }
220
- let(:impersonator_id) { 'some_impersonator_id' }
221
-
265
+ let(:user_id) { 'some_user_id' }
266
+ let(:impersonator_id) { 'some_other_user_id' }
267
+ let(:app_client_id) { 'app_client_id' }
222
268
  it { expect(@instance).to respond_to(:impersonate) }
223
- it "is expected to make post request to '/users/{user_id}/impersonate'" do
224
- expect(@instance).to receive(:post).with(
225
- "/users/#{user_id}/impersonate",
226
- protocol: 'oauth2',
227
- impersonator_id: impersonator_id, client_id: app_client_id,
228
- additionalParameters: {
229
- response_type: 'code', state: '',
230
- scope: 'openid', callback_url: '' })
231
- @instance.impersonate(user_id, app_client_id, impersonator_id, {})
269
+ it do
270
+ expect { @instance.impersonate(user_id, app_client_id, impersonator_id, {}) }.to raise_error(
271
+ 'Must supply client_secret'
272
+ )
273
+ end
274
+ it do
275
+ expect { @instance.impersonate('', app_client_id, impersonator_id, {}) }.to raise_error(
276
+ 'Must supply a valid user_id'
277
+ )
278
+ end
279
+ it do
280
+ expect { @instance.impersonate(user_id, app_client_id, '', {}) }.to raise_error(
281
+ 'Must supply a valid impersonator_id'
282
+ )
283
+ end
284
+ it do
285
+ expect { @instance.impersonate(user_id, '', impersonator_id, {}) }.to raise_error(
286
+ 'Must supply a valid app_client_id'
287
+ )
232
288
  end
233
- it { expect { @instance.impersonate('', '', '', '') }.to raise_error 'Must supply a valid user_id' }
234
289
  end
235
290
 
236
291
  context '.unlink_user' do
@@ -256,7 +311,8 @@ describe Auth0::Api::AuthenticationEndpoints do
256
311
  it { expect(@instance).to respond_to(:logout_url) }
257
312
  it 'is expected to return a logout url' do
258
313
  expect(@instance.logout_url(return_to).to_s).to eq(
259
- "https://#{@instance.domain}/logout?returnTo=#{return_to}")
314
+ "https://#{@instance.domain}/logout?returnTo=#{return_to}"
315
+ )
260
316
  end
261
317
  end
262
318
 
@@ -264,11 +320,13 @@ describe Auth0::Api::AuthenticationEndpoints do
264
320
  it { expect(@instance).to respond_to(:samlp_url) }
265
321
  it 'is expected to get the samlp url' do
266
322
  expect(@instance.samlp_url.to_s).to eq(
267
- "https://#{@instance.domain}/samlp/?connection=Username-Password-Authentication")
323
+ "https://#{@instance.domain}/samlp/#{@instance.client_id}?connection=Username-Password-Authentication"
324
+ )
268
325
  end
269
326
  it 'is expected to get the samlp url with fb connection' do
270
327
  expect(@instance.samlp_url('facebook').to_s).to eq(
271
- "https://#{@instance.domain}/samlp/?connection=facebook")
328
+ "https://#{@instance.domain}/samlp/#{@instance.client_id}?connection=facebook"
329
+ )
272
330
  end
273
331
  end
274
332
 
@@ -276,11 +334,13 @@ describe Auth0::Api::AuthenticationEndpoints do
276
334
  it { expect(@instance).to respond_to(:wsfed_url) }
277
335
  it 'is expected to get the wsfed url' do
278
336
  expect(@instance.wsfed_url.to_s).to eq(
279
- "https://#{@instance.domain}/wsfed/?whr=Username-Password-Authentication")
337
+ "https://#{@instance.domain}/wsfed/#{@instance.client_id}?whr=Username-Password-Authentication"
338
+ )
280
339
  end
281
340
  it 'is expected to get the wsfed url with fb connection' do
282
341
  expect(@instance.wsfed_url('facebook').to_s).to eq(
283
- "https://#{@instance.domain}/wsfed/?whr=facebook")
342
+ "https://#{@instance.domain}/wsfed/#{@instance.client_id}?whr=facebook"
343
+ )
284
344
  end
285
345
  end
286
346
  end