auth0 3.6.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +12 -7
- data/CHANGELOG.md +10 -0
- data/Gemfile +4 -2
- data/Guardfile +13 -10
- data/LICENSE +2 -2
- data/README.md +9 -11
- data/Rakefile +33 -7
- data/auth0.gemspec +12 -12
- data/deploy_documentation.sh +29 -0
- data/doc_config/templates/default/fulldoc/html/css/full_list.css +79 -0
- data/doc_config/templates/default/fulldoc/html/css/style.css +546 -0
- data/doc_config/templates/default/layout/html/breadcrumb.erb +11 -0
- data/doc_config/templates/default/layout/html/footer.erb +115 -0
- data/doc_config/templates/default/layout/html/headers.erb +17 -0
- data/doc_config/templates/default/layout/html/layout.erb +27 -0
- data/lib/auth0.rb +5 -5
- data/lib/auth0/api/authentication_endpoints.rb +264 -46
- data/lib/auth0/api/v1.rb +5 -5
- data/lib/auth0/api/v1/clients.rb +7 -7
- data/lib/auth0/api/v1/connections.rb +9 -10
- data/lib/auth0/api/v1/logs.rb +9 -16
- data/lib/auth0/api/v1/rules.rb +5 -5
- data/lib/auth0/api/v1/users.rb +28 -27
- data/lib/auth0/api/v2.rb +17 -9
- data/lib/auth0/api/v2/blacklists.rb +30 -9
- data/lib/auth0/api/v2/clients.rb +60 -19
- data/lib/auth0/api/v2/connections.rb +63 -10
- data/lib/auth0/api/v2/emails.rb +58 -0
- data/lib/auth0/api/v2/jobs.rb +44 -7
- data/lib/auth0/api/v2/rules.rb +104 -0
- data/lib/auth0/api/v2/stats.rb +22 -5
- data/lib/auth0/api/v2/tenants.rb +39 -0
- data/lib/auth0/api/v2/tickets.rb +58 -0
- data/lib/auth0/api/v2/users.rb +128 -39
- data/lib/auth0/client.rb +8 -6
- data/lib/auth0/exception.rb +29 -23
- data/lib/auth0/mixins.rb +12 -10
- data/lib/auth0/mixins/httparty_proxy.rb +13 -10
- data/lib/auth0/mixins/initializer.rb +25 -27
- data/lib/auth0/version.rb +2 -2
- data/spec/integration/lib/auth0/api/v1/api_clients_spec.rb +2 -4
- data/spec/integration/lib/auth0/api/v1/api_users_spec.rb +25 -32
- data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +14 -0
- data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +61 -6
- data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +68 -42
- data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +71 -0
- data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +69 -0
- data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +83 -0
- data/spec/integration/lib/auth0/api/v2/api_stats_spec.rb +16 -0
- data/spec/integration/lib/auth0/api/v2/api_tenants_spec.rb +37 -0
- data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +33 -0
- data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +88 -36
- data/spec/integration/lib/auth0/auth0_client_spec.rb +43 -35
- data/spec/lib/auth0/api/authentication_endpoints_spec.rb +253 -47
- data/spec/lib/auth0/api/v1/clients_spec.rb +37 -38
- data/spec/lib/auth0/api/v1/connections_spec.rb +44 -38
- data/spec/lib/auth0/api/v1/logs_spec.rb +24 -24
- data/spec/lib/auth0/api/v1/rules_spec.rb +23 -22
- data/spec/lib/auth0/api/v1/users_spec.rb +153 -130
- data/spec/lib/auth0/api/v2/blacklists_spec.rb +12 -11
- data/spec/lib/auth0/api/v2/clients_spec.rb +38 -33
- data/spec/lib/auth0/api/v2/connections_spec.rb +59 -34
- data/spec/lib/auth0/api/v2/emails_spec.rb +47 -0
- data/spec/lib/auth0/api/v2/jobs_spec.rb +24 -10
- data/spec/lib/auth0/api/v2/rules_spec.rb +69 -0
- data/spec/lib/auth0/api/v2/stats_spec.rb +11 -11
- data/spec/lib/auth0/api/v2/tenants_spec.rb +25 -0
- data/spec/lib/auth0/api/v2/tickets_spec.rb +31 -0
- data/spec/lib/auth0/api/v2/users_spec.rb +101 -39
- data/spec/lib/auth0/client_spec.rb +46 -58
- data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +98 -69
- data/spec/lib/auth0/mixins/initializer_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/spec_helper_full.rb +16 -15
- data/spec/spec_helper_unit.rb +5 -5
- data/spec/support/credentials.rb +9 -3
- data/spec/support/dummy_class.rb +7 -1
- data/spec/support/dummy_class_for_proxy.rb +2 -2
- data/spec/support/import_users.json +13 -0
- data/spec/support/stub_response.rb +1 -2
- metadata +78 -41
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Auth0::Api::V2::Rules do
|
3
|
+
attr_reader :client, :enabled_rule, :disabled_rule
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@client = Auth0Client.new(v2_creds)
|
7
|
+
suffix = Faker::Lorem.word
|
8
|
+
script = 'function (user, context, callback) { callback(null, user, context);}'
|
9
|
+
stage = 'login_success'
|
10
|
+
@enabled_rule = client.create_rule("Enabled Rule #{suffix}", script, rand(1..10), true, stage)
|
11
|
+
@disabled_rule = client.create_rule("Disabled Rule #{suffix}", script, rand(11..20), false, stage)
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
rules = client.rules
|
16
|
+
rules.each do |rule|
|
17
|
+
client.delete_rule(rule['id'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.rules' do
|
22
|
+
let(:rules) { client.rules }
|
23
|
+
|
24
|
+
it { expect(rules.size).to be > 0 }
|
25
|
+
|
26
|
+
context '#filters' do
|
27
|
+
it do
|
28
|
+
expect(client.rules(enabled: true).size).to be 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it do
|
32
|
+
expect(client.rules(enabled: false).size).to be 1
|
33
|
+
end
|
34
|
+
|
35
|
+
it do
|
36
|
+
expect(client.rules(enabled: true, fields: [:script, :order].join(',')).first).to(include('script', 'order'))
|
37
|
+
end
|
38
|
+
it do
|
39
|
+
expect(client.rules(enabled: true, fields: [:script].join(',')).first).to_not(include('order', 'name'))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '.rule' do
|
45
|
+
it do
|
46
|
+
expect(client.rule(enabled_rule['id'])).to(
|
47
|
+
include('stage' => enabled_rule['stage'], 'order' => enabled_rule['order'], 'script' => enabled_rule['script']))
|
48
|
+
end
|
49
|
+
|
50
|
+
context '#filters' do
|
51
|
+
let(:rule_include) { client.rule(enabled_rule['id'], fields: [:stage, :order, :script].join(',')) }
|
52
|
+
let(:rule_not_include) { client.rule(enabled_rule['id'], fields: :stage, include_fields: false) }
|
53
|
+
|
54
|
+
it do
|
55
|
+
expect(rule_include).to(include('stage', 'order', 'script'))
|
56
|
+
end
|
57
|
+
|
58
|
+
it do
|
59
|
+
expect(rule_not_include).to(include('order', 'script'))
|
60
|
+
expect(rule_not_include).to_not(include('stage'))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '.create_rule' do
|
66
|
+
let(:name) { Faker::Lorem.word }
|
67
|
+
let(:order) { rand(21..30) }
|
68
|
+
let(:stage) { 'login_success' }
|
69
|
+
let(:script) { 'function(test)' }
|
70
|
+
let(:enabled) { false }
|
71
|
+
let!(:rule) { client.create_rule(name, script, order, enabled, stage) }
|
72
|
+
it { expect(rule).to include('name' => name, 'stage' => stage, 'order' => order, 'script' => script) }
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '.delete_rule' do
|
76
|
+
it { expect { client.delete_rule(enabled_rule['id']) }.to_not raise_error }
|
77
|
+
it { expect { client.delete_rule '' }.to raise_error(Auth0::InvalidParameter) }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '.update_rule' do
|
81
|
+
it { expect(client.update_rule(disabled_rule['id'], enabled: true)).to(include('enabled' => true)) }
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Auth0::Api::V2::Stats do
|
3
|
+
let(:client) { Auth0Client.new(v2_creds) }
|
4
|
+
|
5
|
+
describe '.active_users' do
|
6
|
+
it { expect(Integer(client.active_users)).to be >= 0 }
|
7
|
+
end
|
8
|
+
|
9
|
+
# rubocop:disable Date
|
10
|
+
describe '.daily_stats' do
|
11
|
+
let(:from) { Date.today.prev_day.strftime('%Y%m%d') }
|
12
|
+
let(:to) { Date.today.strftime('%Y%m%d') }
|
13
|
+
let(:daily_stats) { client.daily_stats(from, to) }
|
14
|
+
it { expect(daily_stats.size).to be > 0 }
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Auth0::Api::V2::Tenants do
|
3
|
+
attr_reader :client, :body
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@client = Auth0Client.new(v2_creds)
|
7
|
+
@body = {
|
8
|
+
'error_page' => {
|
9
|
+
'html' => '',
|
10
|
+
'show_log_link' => false,
|
11
|
+
'url' => 'https://mycompany.org/error'
|
12
|
+
},
|
13
|
+
'friendly_name' => 'My Company',
|
14
|
+
'picture_url' => 'https://mycompany.org/logo.png',
|
15
|
+
'support_email' => 'support@mycompany.org',
|
16
|
+
'support_url' => 'https://mycompany.org/support'
|
17
|
+
}
|
18
|
+
|
19
|
+
client.update_tenant_settings(body)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.get_tenant_settings' do
|
23
|
+
it { expect(client.get_tenant_settings).to include(body) }
|
24
|
+
|
25
|
+
let(:tenant_setting_fields) { client.get_tenant_settings(fields: 'picture_url') }
|
26
|
+
it { expect(tenant_setting_fields).to_not include('friendly_name' => 'My Company') }
|
27
|
+
it { expect(tenant_setting_fields).to include('picture_url' => 'https://mycompany.org/logo.png') }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.update_tenant_settings' do
|
31
|
+
let(:tenant_name) { Faker::Company.name }
|
32
|
+
let(:body_tenant) do
|
33
|
+
{ 'friendly_name' => tenant_name }
|
34
|
+
end
|
35
|
+
it { expect(client.update_tenant_settings(body_tenant)['friendly_name']).to include(tenant_name) }
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe Auth0::Api::V2::Tickets do
|
3
|
+
attr_reader :client, :user
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@client = Auth0Client.new(v2_creds)
|
7
|
+
username = Faker::Internet.user_name
|
8
|
+
email = "#{entity_suffix}#{Faker::Internet.safe_email(username)}"
|
9
|
+
password = Faker::Internet.password
|
10
|
+
@user = client.create_user(username, 'email' => email,
|
11
|
+
'password' => password,
|
12
|
+
'email_verified' => false,
|
13
|
+
'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
|
14
|
+
'app_metadata' => {})
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:all) do
|
18
|
+
client.delete_user(user['user_id'])
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.post_email_verification' do
|
22
|
+
let(:email_verification) { client.post_email_verification(user['user_id'], result_url: 'http://myapp.com/callback') }
|
23
|
+
it { expect(email_verification).to include('ticket') }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.post_password_change' do
|
27
|
+
let(:password_change) do
|
28
|
+
client.post_password_change('secret', user_id: user['user_id'],
|
29
|
+
result_url: 'http://myapp.com/callback')
|
30
|
+
end
|
31
|
+
it { expect(password_change).to include('ticket') }
|
32
|
+
end
|
33
|
+
end
|
@@ -1,68 +1,120 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
describe Auth0::Api::V2::Users do
|
3
|
-
|
4
3
|
let(:client) { Auth0Client.new(v2_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(:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
})}
|
7
|
+
let!(:user) do
|
8
|
+
client.create_user(username, 'email' => email,
|
9
|
+
'password' => password,
|
10
|
+
'email_verified' => false,
|
11
|
+
'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
|
12
|
+
'app_metadata' => {})
|
13
|
+
end
|
16
14
|
|
17
15
|
describe '.users' do
|
18
|
-
|
19
|
-
let(:users) { client.users() }
|
16
|
+
let(:users) { client.users }
|
20
17
|
|
21
18
|
it { expect(users.size).to be > 0 }
|
22
19
|
|
23
|
-
context
|
20
|
+
context '#filters' do
|
24
21
|
it { expect(client.users(per_page: 1).size).to be 1 }
|
25
|
-
it
|
26
|
-
|
22
|
+
it do
|
23
|
+
expect(
|
24
|
+
client.users(per_page: 1, fields: [:picture, :email, :user_id].join(','), include_fields: true).first
|
25
|
+
).to(include('email', 'user_id', 'picture'))
|
26
|
+
end
|
27
|
+
it { expect(client.users(per_page: 1, fields: [:email].join(',')).first).to_not include('user_id', 'picture') }
|
28
|
+
it do
|
29
|
+
expect(
|
30
|
+
client.users(per_page: 1, fields: [:email].join(','), include_fields: false).first
|
31
|
+
).to include('user_id', 'picture')
|
32
|
+
end
|
27
33
|
end
|
28
|
-
|
29
34
|
end
|
30
35
|
|
31
36
|
describe '.user' do
|
37
|
+
let(:subject) { client.user(user['user_id']) }
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
it { should include('email' => email, 'name' => username) }
|
40
|
+
it do
|
41
|
+
expect(
|
42
|
+
client.user(user['user_id'], fields: [:picture, :email, :user_id].join(','), include_fields: true)
|
43
|
+
).to(include('email', 'user_id', 'picture'))
|
44
|
+
end
|
45
|
+
it do
|
46
|
+
expect(
|
47
|
+
client.user(user['user_id'], fields: [:picture, :email, :user_id].join(','), include_fields: false)
|
48
|
+
).not_to(include('email', 'user_id', 'picture'))
|
40
49
|
end
|
41
50
|
|
51
|
+
context '#filters' do
|
52
|
+
it do
|
53
|
+
expect(client.user(user['user_id'], fields: [:picture, :email, :user_id].join(','))).to(
|
54
|
+
include('email', 'user_id', 'picture'))
|
55
|
+
end
|
56
|
+
it { expect(client.user(user['user_id'], fields: [:email].join(','))).to_not include('user_id', 'picture') }
|
57
|
+
end
|
42
58
|
end
|
43
59
|
|
44
60
|
describe '.create_user' do
|
45
|
-
|
46
61
|
let(:subject) { user }
|
47
62
|
|
48
|
-
it { should include(
|
49
|
-
it {
|
50
|
-
"email" => email,
|
51
|
-
"email_verified" => false,
|
52
|
-
)}
|
53
|
-
|
63
|
+
it { should include('user_id', 'identities') }
|
64
|
+
it { expect(client.patch_user(user['user_id'], 'email_verified' => true)).to include('email_verified' => true) }
|
54
65
|
end
|
55
66
|
|
56
67
|
describe '.delete_user' do
|
57
|
-
|
58
|
-
it { expect { client.delete_user
|
59
|
-
|
60
|
-
it { expect { client.delete_user "" }.to raise_error(Auth0::MissingUserId) }
|
61
|
-
|
68
|
+
it { expect { client.delete_user user['user_id'] }.to_not raise_error }
|
69
|
+
it { expect { client.delete_user '' }.to raise_error(Auth0::MissingUserId) }
|
62
70
|
end
|
63
71
|
|
64
72
|
describe '.patch_user' do
|
65
|
-
it { expect(client.patch_user(user[
|
73
|
+
it { expect(client.patch_user(user['user_id'], 'email_verified' => true)).to(include('email_verified' => true)) }
|
74
|
+
let(:body_path) do
|
75
|
+
{
|
76
|
+
'user_metadata' => {
|
77
|
+
'addresses' => { 'home_address' => '742 Evergreen Terrace' }
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
it do
|
82
|
+
expect(
|
83
|
+
client.patch_user(user['user_id'], body_path)
|
84
|
+
).to(include('user_metadata' => { 'addresses' => { 'home_address' => '742 Evergreen Terrace' } }))
|
85
|
+
end
|
66
86
|
end
|
67
87
|
|
88
|
+
describe '.link_user_account and .unlink_users_account' do
|
89
|
+
let(:email_link) { "#{entity_suffix}#{Faker::Internet.safe_email(Faker::Internet.user_name)}" }
|
90
|
+
let!(:link_user) do
|
91
|
+
client.create_user(username, 'email' => email_link,
|
92
|
+
'password' => Faker::Internet.password,
|
93
|
+
'email_verified' => false,
|
94
|
+
'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
|
95
|
+
'app_metadata' => {})
|
96
|
+
end
|
97
|
+
let(:email_primary) { "#{entity_suffix}#{Faker::Internet.safe_email(Faker::Internet.user_name)}" }
|
98
|
+
let!(:primary_user) do
|
99
|
+
client.create_user(username, 'email' => email_primary,
|
100
|
+
'password' => Faker::Internet.password,
|
101
|
+
'email_verified' => false,
|
102
|
+
'connection' => Auth0::Api::AuthenticationEndpoints::UP_AUTH,
|
103
|
+
'app_metadata' => {})
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:body_link) { { 'provider' => 'auth0', 'user_id' => link_user['user_id'] } }
|
107
|
+
skip 'Link user account examples are skipped to avoid errors on users deletion' do
|
108
|
+
it do
|
109
|
+
expect(
|
110
|
+
client.link_user_account(primary_user['user_id'], body_link).first
|
111
|
+
).to include('provider' => 'auth0', 'user_id' => primary_user['identities'].first['user_id'])
|
112
|
+
end
|
113
|
+
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'])
|
118
|
+
end
|
119
|
+
end
|
68
120
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
describe Auth0::Client do
|
3
|
-
|
4
|
-
shared_examples "invalid credentials" do |credentials, error|
|
3
|
+
shared_examples 'invalid credentials' do |credentials, error|
|
5
4
|
it "raise an error with credentials #{credentials}" do
|
6
5
|
if error.nil?
|
7
6
|
expect { Auth0Client.new(credentials) }.to raise_error
|
@@ -11,62 +10,71 @@ describe Auth0::Client do
|
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
|
-
it_should_behave_like
|
15
|
-
it_should_behave_like
|
16
|
-
|
17
|
-
it_should_behave_like
|
18
|
-
|
19
|
-
it_should_behave_like
|
20
|
-
|
21
|
-
it_should_behave_like
|
22
|
-
it_should_behave_like
|
13
|
+
it_should_behave_like 'invalid credentials', { namespace: 'samples.auth0.com' }, Auth0::InvalidCredentials
|
14
|
+
it_should_behave_like 'invalid credentials', {
|
15
|
+
namespace: 'samples.auth0.com', client_id: 'client_id' }, Auth0::InvalidCredentials
|
16
|
+
it_should_behave_like 'invalid credentials', {
|
17
|
+
namespace: 'samples.auth0.com', client_secret: 'secret' }, Auth0::InvalidCredentials
|
18
|
+
it_should_behave_like 'invalid credentials', {
|
19
|
+
namespace: 'samples.auth0.com', api_version: 2 }, Auth0::InvalidCredentials
|
20
|
+
it_should_behave_like 'invalid credentials', {}
|
21
|
+
it_should_behave_like 'invalid credentials', api_version: 2
|
22
|
+
it_should_behave_like 'invalid credentials', api_version: 1
|
23
|
+
it_should_behave_like 'invalid credentials', {
|
24
|
+
client_id: 'client_id', client_secret: 'secret' }, Auth0::InvalidApiNamespace
|
25
|
+
it_should_behave_like 'invalid credentials', {
|
26
|
+
api_version: 2, token: 'token' }, Auth0::InvalidApiNamespace
|
23
27
|
|
24
|
-
let(:valid_v1_credentials)
|
25
|
-
|
26
|
-
|
28
|
+
let(:valid_v1_credentials) do
|
29
|
+
{ client_id: ENV['CLIENT_ID'],
|
30
|
+
client_secret: ENV['CLIENT_SECRET'],
|
31
|
+
domain: ENV['DOMAIN'] }
|
32
|
+
end
|
33
|
+
let(:token) { ENV['MASTER_JWT'] }
|
34
|
+
let(:v2_credentials) { { domain: ENV['DOMAIN'], api_version: 2 } }
|
27
35
|
|
28
|
-
shared_examples
|
36
|
+
shared_examples 'valid credentials' do
|
29
37
|
it { expect { Auth0Client.new(credentials) }.to_not raise_error }
|
30
38
|
end
|
31
39
|
|
32
|
-
it_should_behave_like
|
40
|
+
it_should_behave_like 'valid credentials' do
|
33
41
|
let(:credentials) { valid_v1_credentials }
|
34
42
|
end
|
35
|
-
it_should_behave_like
|
36
|
-
let(:credentials) { valid_v1_credentials.merge(
|
43
|
+
it_should_behave_like 'valid credentials' do
|
44
|
+
let(:credentials) { valid_v1_credentials.merge(api_version: 1) }
|
37
45
|
end
|
38
|
-
it_should_behave_like
|
39
|
-
let(:credentials) { v2_credentials.merge(
|
46
|
+
it_should_behave_like 'valid credentials' do
|
47
|
+
let(:credentials) { v2_credentials.merge(token: token) }
|
40
48
|
end
|
41
|
-
it_should_behave_like
|
42
|
-
let(:credentials) { v2_credentials.merge(
|
49
|
+
it_should_behave_like 'valid credentials' do
|
50
|
+
let(:credentials) { v2_credentials.merge(access_token: ENV['MASTER_JWT']) }
|
43
51
|
end
|
44
52
|
|
45
|
-
context
|
46
|
-
let(:client) { Auth0::Client.new(v2_credentials.merge(
|
53
|
+
context 'client headers' do
|
54
|
+
let(:client) { Auth0::Client.new(v2_credentials.merge(access_token: 'abc123', domain: 'myhost.auth0.com')) }
|
47
55
|
let(:headers) { client.class.headers }
|
48
56
|
|
49
|
-
let(:base64_token)
|
50
|
-
Base64.urlsafe_encode64('{"name":"ruby-auth0","version":"'+Auth0::VERSION+'"}')
|
51
|
-
|
57
|
+
let(:base64_token) do
|
58
|
+
Base64.urlsafe_encode64('{"name":"ruby-auth0","version":"' + Auth0::VERSION + '"}')
|
59
|
+
end
|
52
60
|
|
53
|
-
it
|
54
|
-
expect(headers.keys.sort).to eql
|
61
|
+
it 'has the correct headers present' do
|
62
|
+
expect(headers.keys.sort).to eql(['Auth0-Client', 'Authorization', 'Content-Type', 'User-Agent'])
|
55
63
|
end
|
56
64
|
|
57
|
-
it
|
58
|
-
expect(headers['Authorization']).to eql
|
65
|
+
it 'uses the correct access token' do
|
66
|
+
expect(headers['Authorization']).to eql 'Bearer abc123'
|
59
67
|
end
|
60
68
|
|
61
|
-
it
|
69
|
+
it 'is always json' do
|
62
70
|
expect(headers['Content-Type']).to eql 'application/json'
|
63
71
|
end
|
64
72
|
|
65
|
-
it
|
73
|
+
it 'sets the ruby version' do
|
66
74
|
expect(headers['User-Agent']).to eql "Ruby/#{RUBY_VERSION}"
|
67
75
|
end
|
68
76
|
|
69
|
-
it
|
77
|
+
it 'sets the client version' do
|
70
78
|
expect(headers['Auth0-Client']).to eql base64_token
|
71
79
|
end
|
72
80
|
end
|
@@ -1,80 +1,286 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
describe Auth0::Api::AuthenticationEndpoints do
|
3
3
|
before :all do
|
4
4
|
dummy_instance = DummyClass.new
|
5
5
|
dummy_instance.extend(Auth0::Api::AuthenticationEndpoints)
|
6
|
+
|
6
7
|
@instance = dummy_instance
|
7
8
|
end
|
8
9
|
|
9
|
-
context
|
10
|
-
it {expect(@instance).to respond_to(:obtain_access_token)}
|
10
|
+
context '.obtain_access_token' do
|
11
|
+
it { expect(@instance).to respond_to(:obtain_access_token) }
|
11
12
|
it "is expected to make post request to '/oauth/token'" do
|
12
|
-
allow(@instance).to receive(:post).with(
|
13
|
-
|
14
|
-
|
15
|
-
expect(@instance
|
13
|
+
allow(@instance).to receive(:post).with(
|
14
|
+
'/oauth/token', client_id: nil, client_secret: nil, grant_type: 'client_credentials')
|
15
|
+
.and_return('access_token' => 'AccessToken')
|
16
|
+
expect(@instance).to receive(:post).with(
|
17
|
+
'/oauth/token', client_id: nil, client_secret: nil, grant_type: 'client_credentials')
|
18
|
+
expect(@instance.obtain_access_token).to eql 'AccessToken'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context '.obtain_access_token social' do
|
23
|
+
it { expect(@instance).to respond_to(:obtain_access_token) }
|
24
|
+
it "is expected to make post request to '/oauth/access_token'" do
|
25
|
+
allow(@instance).to receive(:post).with(
|
26
|
+
'/oauth/access_token', client_id: nil, access_token: 'access_token', connection: 'facebook', scope: 'openid')
|
27
|
+
.and_return('access_token' => 'AccessToken')
|
28
|
+
expect(@instance).to receive(:post).with(
|
29
|
+
'/oauth/access_token', client_id: nil, access_token: 'access_token', connection: 'facebook', scope: 'openid')
|
30
|
+
expect(@instance.obtain_access_token('access_token', 'facebook', 'openid')).to eql 'AccessToken'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '.login' do
|
35
|
+
it { expect(@instance).to respond_to(:login) }
|
36
|
+
it 'is expected to make post to /oauth/ro' do
|
37
|
+
expect(@instance).to receive(:post).with(
|
38
|
+
'/oauth/ro',
|
39
|
+
client_id: nil, username: 'test@test.com',
|
40
|
+
password: 'password', scope: 'openid', connection: 'Username-Password-Authentication',
|
41
|
+
grant_type: 'password', id_token: nil, device: nil)
|
42
|
+
@instance.login('test@test.com', 'password')
|
43
|
+
end
|
44
|
+
it { expect { @instance.login('', '') }.to raise_error 'Must supply a valid username' }
|
45
|
+
it { expect { @instance.login('username', '') }.to raise_error 'Must supply a valid password' }
|
46
|
+
end
|
47
|
+
|
48
|
+
context '.signup' do
|
49
|
+
it { expect(@instance).to respond_to(:signup) }
|
50
|
+
it 'is expected to make post to /dbconnections/signup' do
|
51
|
+
expect(@instance).to receive(:post).with(
|
52
|
+
'/dbconnections/signup',
|
53
|
+
client_id: nil, email: 'test@test.com',
|
54
|
+
password: 'password', connection: 'User')
|
55
|
+
@instance.signup('test@test.com', 'password', 'User')
|
56
|
+
end
|
57
|
+
it { expect { @instance.signup('', '') }.to raise_error 'Must supply a valid email' }
|
58
|
+
it { expect { @instance.signup('email', '') }.to raise_error 'Must supply a valid password' }
|
59
|
+
end
|
60
|
+
|
61
|
+
context '.change_password' do
|
62
|
+
it { expect(@instance).to respond_to(:change_password) }
|
63
|
+
it 'is expected to make post to /dbconnections/change_password' do
|
64
|
+
expect(@instance).to receive(:post).with(
|
65
|
+
'/dbconnections/change_password',
|
66
|
+
client_id: nil, email: 'test@test.com',
|
67
|
+
password: 'password', connection: 'User')
|
68
|
+
@instance.change_password('test@test.com', 'password', 'User')
|
69
|
+
end
|
70
|
+
it { expect { @instance.change_password('', '', '') }.to raise_error 'Must supply a valid email' }
|
71
|
+
end
|
72
|
+
|
73
|
+
context '.start_passwordless_email_flow' do
|
74
|
+
it { expect(@instance).to respond_to(:start_passwordless_email_flow) }
|
75
|
+
it 'is expected to make post to /passwordless/start' do
|
76
|
+
expect(@instance).to receive(:post).with(
|
77
|
+
'/passwordless/start',
|
78
|
+
client_id: nil,
|
79
|
+
email: 'test@test.com',
|
80
|
+
send: 'link',
|
81
|
+
auth_params: {
|
82
|
+
scope: 'scope',
|
83
|
+
protocol: 'protocol'
|
84
|
+
})
|
85
|
+
@instance.start_passwordless_email_flow('test@test.com', 'link', scope: 'scope', protocol: 'protocol')
|
86
|
+
end
|
87
|
+
it { expect { @instance.start_passwordless_email_flow('', '', '') }.to raise_error 'Must supply a valid email' }
|
88
|
+
end
|
89
|
+
|
90
|
+
context '.start_passwordless_sms_flow' do
|
91
|
+
let(:phone_number) { Faker::PhoneNumber.cell_phone }
|
92
|
+
it { expect(@instance).to respond_to(:start_passwordless_sms_flow) }
|
93
|
+
it 'is expected to make post to /passwordless/start' do
|
94
|
+
expect(@instance).to receive(:post).with(
|
95
|
+
'/passwordless/start',
|
96
|
+
client_id: nil,
|
97
|
+
connection: 'sms',
|
98
|
+
phone_number: phone_number)
|
99
|
+
@instance.start_passwordless_sms_flow(phone_number)
|
100
|
+
end
|
101
|
+
it { expect { @instance.start_passwordless_sms_flow('') }.to raise_error 'Must supply a valid phone number' }
|
102
|
+
end
|
103
|
+
|
104
|
+
context '.phone_login' do
|
105
|
+
let(:phone_number) { Faker::PhoneNumber.cell_phone }
|
106
|
+
let(:code) { Faker::Number.number(10) }
|
107
|
+
it { expect(@instance).to respond_to(:phone_login) }
|
108
|
+
it 'is expected to make post to /oauth/ro' do
|
109
|
+
expect(@instance).to receive(:post).with(
|
110
|
+
'/oauth/ro',
|
111
|
+
client_id: nil, username: phone_number,
|
112
|
+
password: code, connection: 'sms',
|
113
|
+
scope: 'openid', grant_type: 'password')
|
114
|
+
@instance.phone_login(phone_number, code)
|
115
|
+
end
|
116
|
+
it { expect { @instance.phone_login('', '') }.to raise_error 'Must supply a valid phone number' }
|
117
|
+
it { expect { @instance.phone_login('phone', '') }.to raise_error 'Must supply a valid code' }
|
118
|
+
end
|
119
|
+
|
120
|
+
context '.saml_metadata' do
|
121
|
+
let(:client_id) { 'client-id' }
|
122
|
+
it { expect(@instance).to respond_to(:saml_metadata) }
|
123
|
+
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)
|
126
|
+
end
|
127
|
+
it { expect { @instance.saml_metadata('') }.to raise_error 'Must supply a valid client_id' }
|
128
|
+
end
|
129
|
+
|
130
|
+
context '.wsfed_metadata' do
|
131
|
+
it { expect(@instance).to respond_to(:wsfed_metadata) }
|
132
|
+
it 'is expected to make post to /wsfed/FederationMetadata/2007-06/FederationMetadata.xml' do
|
133
|
+
expect(@instance).to receive(:get).with('/wsfed/FederationMetadata/2007-06/FederationMetadata.xml')
|
134
|
+
@instance.wsfed_metadata
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context '.authorization_url' do
|
139
|
+
let(:redirect_url) { 'http://redirect.com' }
|
140
|
+
it { expect(@instance).to respond_to(:authorization_url) }
|
141
|
+
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}")
|
144
|
+
end
|
145
|
+
let(:additional_parameters) { { additional_parameters: { aparam1: 'test1' } } }
|
146
|
+
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")
|
149
|
+
end
|
150
|
+
let(:state) { { state: 'state1' } }
|
151
|
+
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")
|
154
|
+
end
|
155
|
+
it { expect { @instance.authorization_url('', '') }.to raise_error 'Must supply a valid redirect_uri' }
|
156
|
+
end
|
157
|
+
context '.token_info' do
|
158
|
+
it { expect(@instance).to respond_to(:token_info) }
|
159
|
+
it 'is expected to make post to /tokeinfo' do
|
160
|
+
expect(@instance).to receive(:post).with('/tokeninfo', id_token: 'SomerandomToken')
|
161
|
+
@instance.token_info('SomerandomToken')
|
16
162
|
end
|
163
|
+
it { expect { @instance.token_info('') }.to raise_error 'Must supply a valid id_token' }
|
17
164
|
end
|
18
165
|
|
19
|
-
context
|
20
|
-
it {expect(@instance).to respond_to(:
|
166
|
+
context '.refresh_delegation' do
|
167
|
+
it { expect(@instance).to respond_to(:refresh_delegation) }
|
21
168
|
it "is expected to make post request to '/delegation'" do
|
22
|
-
expect(@instance).to receive(:post).with(
|
23
|
-
|
169
|
+
expect(@instance).to receive(:post).with(
|
170
|
+
'/delegation',
|
171
|
+
client_id: nil,
|
172
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
173
|
+
refresh_token: 'id_token', target: '', api_type: '', scope: '',
|
174
|
+
additional_parameter: 'parameter')
|
175
|
+
@instance.refresh_delegation('id_token', '', '', '', additional_parameter: 'parameter')
|
24
176
|
end
|
25
|
-
it
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
177
|
+
it { expect { @instance.refresh_delegation('', '', '', '') }.to raise_error 'Must supply a valid token to refresh' }
|
178
|
+
end
|
179
|
+
|
180
|
+
context '.delegation' do
|
181
|
+
it { expect(@instance).to respond_to(:delegation) }
|
182
|
+
it "is expected to make post request to '/delegation'" do
|
183
|
+
expect(@instance).to receive(:post).with(
|
184
|
+
'/delegation',
|
185
|
+
client_id: nil,
|
186
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
187
|
+
id_token: 'token',
|
188
|
+
target: 'target',
|
189
|
+
scope: '',
|
190
|
+
api_type: 'app')
|
191
|
+
@instance.delegation('token', 'target', '')
|
30
192
|
end
|
31
|
-
it "
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
193
|
+
it "is expected to make post request to '/delegation'
|
194
|
+
with specified api_type" do
|
195
|
+
expect(@instance).to receive(:post).with(
|
196
|
+
'/delegation',
|
197
|
+
client_id: nil,
|
198
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
199
|
+
id_token: 'id_token', target: '', scope: '',
|
200
|
+
api_type: 'salesforce_api')
|
201
|
+
@instance.delegation('id_token', '', '', 'salesforce_api')
|
36
202
|
end
|
203
|
+
it 'allows to pass extra parameters' do
|
204
|
+
expect(@instance).to receive(:post).with(
|
205
|
+
'/delegation',
|
206
|
+
client_id: nil,
|
207
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
208
|
+
id_token: 'id_token', target: '', scope: '', api_type: '',
|
209
|
+
community_name: 'test-community', community_url: 'test-url')
|
210
|
+
@instance.delegation(
|
211
|
+
'id_token', '', '', '',
|
212
|
+
community_name: 'test-community', community_url: 'test-url')
|
213
|
+
end
|
214
|
+
it { expect { @instance.delegation('', nil, nil, nil) }.to raise_error 'Must supply a valid id_token' }
|
37
215
|
end
|
38
216
|
|
39
|
-
context
|
40
|
-
let(:user_id) {
|
41
|
-
let(:app_client_id) {
|
42
|
-
let(:impersonator_id) {
|
217
|
+
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' }
|
43
221
|
|
44
|
-
it {expect(@instance).to respond_to(:impersonate)}
|
222
|
+
it { expect(@instance).to respond_to(:impersonate) }
|
45
223
|
it "is expected to make post request to '/users/{user_id}/impersonate'" do
|
46
|
-
expect(@instance).to receive(:post).with(
|
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: '' })
|
47
231
|
@instance.impersonate(user_id, app_client_id, impersonator_id, {})
|
48
232
|
end
|
233
|
+
it { expect { @instance.impersonate('', '', '', '') }.to raise_error 'Must supply a valid user_id' }
|
49
234
|
end
|
50
235
|
|
51
|
-
context
|
52
|
-
it {expect(@instance).to respond_to(:
|
53
|
-
it
|
54
|
-
expect(@instance).to receive(:post).with(
|
55
|
-
@instance.
|
236
|
+
context '.unlink_user' do
|
237
|
+
it { expect(@instance).to respond_to(:unlink_user) }
|
238
|
+
it 'is expected to make post to /unlink' do
|
239
|
+
expect(@instance).to receive(:post).with('/unlink', access_token: 'access-token', user_id: 'user-id')
|
240
|
+
@instance.unlink_user('access-token', 'user-id')
|
56
241
|
end
|
242
|
+
it { expect { @instance.unlink_user('', '') }.to raise_error 'Must supply a valid access_token' }
|
243
|
+
it { expect { @instance.unlink_user('token', '') }.to raise_error 'Must supply a valid user_id' }
|
57
244
|
end
|
58
|
-
|
59
|
-
|
60
|
-
it
|
61
|
-
|
62
|
-
@instance.
|
245
|
+
|
246
|
+
context '.user_info' do
|
247
|
+
it { expect(@instance).to respond_to(:user_info) }
|
248
|
+
it 'is expected to make post to /userinfo' do
|
249
|
+
expect(@instance).to receive(:get).with('/userinfo')
|
250
|
+
@instance.user_info
|
63
251
|
end
|
64
252
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
253
|
+
|
254
|
+
context '.logout_url' do
|
255
|
+
let(:return_to) { 'http://returnto.com' }
|
256
|
+
it { expect(@instance).to respond_to(:logout_url) }
|
257
|
+
it 'is expected to return a logout url' do
|
258
|
+
expect(@instance.logout_url(return_to).to_s).to eq(
|
259
|
+
"https://#{@instance.domain}/logout?returnTo=#{return_to}")
|
70
260
|
end
|
71
261
|
end
|
72
262
|
|
73
|
-
context
|
74
|
-
it {expect(@instance).to respond_to(:
|
75
|
-
it
|
76
|
-
expect(@instance).to
|
77
|
-
|
263
|
+
context '.samlp_url' do
|
264
|
+
it { expect(@instance).to respond_to(:samlp_url) }
|
265
|
+
it 'is expected to get the samlp url' do
|
266
|
+
expect(@instance.samlp_url.to_s).to eq(
|
267
|
+
"https://#{@instance.domain}/samlp/?connection=Username-Password-Authentication")
|
268
|
+
end
|
269
|
+
it 'is expected to get the samlp url with fb connection' do
|
270
|
+
expect(@instance.samlp_url('facebook').to_s).to eq(
|
271
|
+
"https://#{@instance.domain}/samlp/?connection=facebook")
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context '.wsfed_url' do
|
276
|
+
it { expect(@instance).to respond_to(:wsfed_url) }
|
277
|
+
it 'is expected to get the wsfed url' do
|
278
|
+
expect(@instance.wsfed_url.to_s).to eq(
|
279
|
+
"https://#{@instance.domain}/wsfed/?whr=Username-Password-Authentication")
|
280
|
+
end
|
281
|
+
it 'is expected to get the wsfed url with fb connection' do
|
282
|
+
expect(@instance.wsfed_url('facebook').to_s).to eq(
|
283
|
+
"https://#{@instance.domain}/wsfed/?whr=facebook")
|
78
284
|
end
|
79
285
|
end
|
80
286
|
end
|