auth0 4.4.0 → 4.5.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.
@@ -7,10 +7,15 @@ module Auth0
7
7
 
8
8
  # Retrieves a list of all client grants.
9
9
  # @see https://auth0.com/docs/api/management/v2#!/client_grants/get_client_grants
10
- #
10
+ # @param page [int] Page number to get, 0-based.
11
+ # @param per_page [int] Results per page if also passing a page number.
11
12
  # @return [json] Returns the client grants.
12
- def client_grants
13
- get(client_grants_path)
13
+ def client_grants (page: nil, per_page: nil)
14
+ request_params = {
15
+ page: page,
16
+ per_page: per_page
17
+ }
18
+ get(client_grants_path, request_params)
14
19
  end
15
20
  alias get_all_client_grants client_grants
16
21
 
@@ -6,16 +6,19 @@ module Auth0
6
6
  attr_reader :clients_path
7
7
 
8
8
  # Retrieves a list of all client applications. Accepts a list of fields to include or exclude.
9
- # @see https://auth0.com/docs/api/v2#!/clients/get_clients
10
- # @param fields [string] A comma separated list of fields to include or exclude from the result.
9
+ # @see https://auth0.com/docs/api/management/v2#!/Clients/get_clients
10
+ # @param fields [string|Array] A comma separated list or an array of fields.
11
11
  # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
12
- #
12
+ # @param page [int] Page number to get, 0-based.
13
+ # @param per_page [int] Results per page if also passing a page number.
13
14
  # @return [json] Returns the clients applications.
14
- def clients(fields: nil, include_fields: nil)
15
+ def clients(fields: nil, include_fields: nil, page: nil, per_page: nil)
15
16
  include_fields = true if !fields.nil? && include_fields.nil?
16
17
  request_params = {
17
- fields: fields,
18
- include_fields: include_fields
18
+ fields: fields.is_a?(Array) ? fields.join(',') : fields,
19
+ include_fields: include_fields,
20
+ page: !page.nil? ? page.to_i : nil,
21
+ per_page: !page.nil? && !per_page.nil? ? per_page.to_i : nil
19
22
  }
20
23
  get(clients_path, request_params)
21
24
  end
@@ -7,18 +7,27 @@ module Auth0
7
7
 
8
8
  # Retrieves every connection matching the specified strategy. All connections are retrieved if no strategy is
9
9
  # being specified. Accepts a list of fields to include or exclude in the resulting list of connection objects.
10
- # @see https://auth0.com/docs/api/v2#!/Connections/get_connections
11
- # @param strategy [string] Provide a type of strategy to only retrieve connections with that strategy (e.g. 'ad',
12
- # 'facebook', 'twitter').
10
+ # @see https://auth0.com/docs/api/management/v2#!/Connections/get_connections
11
+ # @param strategy [string] Strategy to filter connection results.
13
12
  # @param fields [string] A comma separated list of fields to include or exclude from the result.
14
13
  # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
15
- #
14
+ # @param page [int] Page number to get, 0-based.
15
+ # @param per_page [int] Results per page if also passing a page number.
16
16
  # @return [json] Returns the existing connections matching the strategy.
17
- def connections(strategy: nil, fields: nil, include_fields: true)
17
+ def connections(
18
+ strategy: nil,
19
+ fields: nil,
20
+ include_fields: nil,
21
+ page: nil,
22
+ per_page: nil
23
+ )
24
+ include_fields = true if !fields.nil? && include_fields.nil?
18
25
  request_params = {
19
26
  strategy: strategy,
20
- fields: fields,
21
- include_fields: include_fields
27
+ fields: fields.is_a?(Array) ? fields.join(',') : fields,
28
+ include_fields: include_fields,
29
+ page: !page.nil? ? page.to_i : nil,
30
+ per_page: !page.nil? && !per_page.nil? ? per_page.to_i : nil
22
31
  }
23
32
  get(connections_path, request_params)
24
33
  end
@@ -14,14 +14,18 @@ module Auth0
14
14
  # @param fields [string] A comma separated list of fields to include or exclude from the result.
15
15
  # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
16
16
  # @param stage [string] Retrieves rules that match the execution stage (defaults to login_success).
17
+ # @param page [int] Page number to get, 0-based.
18
+ # @param per_page [int] Results per page if also passing a page number.
17
19
  #
18
20
  # @return [json] Returns the existing rules.
19
- def rules(enabled: nil, fields: nil, include_fields: nil, stage: nil)
21
+ def rules(enabled: nil, fields: nil, include_fields: nil, stage: nil, page: nil, per_page: nil)
20
22
  request_params = {
21
23
  enabled: enabled,
22
24
  fields: fields,
23
25
  include_fields: include_fields,
24
- stage: stage
26
+ stage: stage,
27
+ page: page,
28
+ per_page: per_page
25
29
  }
26
30
  get(rules_path, request_params)
27
31
  end
@@ -5,18 +5,21 @@ module Auth0
5
5
  module Users
6
6
  attr_reader :users_path
7
7
 
8
- # Retrieves a list of existing users.
9
- # @see https://auth0.com/docs/api/v2#!/Users/get_users
10
- # @param per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
11
- # @param page [integer] The page number. Zero based.
12
- # @param include_totals [boolean] True if a query summary must be included in the result.
13
- # @param sort [string] The field to use for sorting. 1 == ascending and -1 == descending.
14
- # @param connection [string] Connection filter.
15
- # @param fields [string] A comma separated list of fields to include or exclude from the result.
16
- # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
17
- # @param q [string] Query in Lucene query string syntax. Only fields in app_metadata, user_metadata or the
18
- # normalized user profile are searchable.
19
- #
8
+ # Retrieves a list of Auth0 users.
9
+ # @see https://auth0.com/docs/api/management/v2#!/Users/get_users
10
+ # @param options - The Hash options used to refine the User results.
11
+ # :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
12
+ # :page [integer] The page number. Zero based.
13
+ # :include_totals [boolean] True if a query summary must be included in the result.
14
+ # :sort [string] The field to use for sorting. 1 == ascending and -1 == descending.
15
+ # :connection [string] Connection to filter results by.
16
+ # :fields [string] A comma separated list of result fields.
17
+ # :include_fields [boolean] True to include :fields, false to exclude.
18
+ # :q [string] Query in Lucene query string syntax.
19
+ # :search_engine [string] User search engine version.
20
+ # - Will default to v2 if no value is passed.
21
+ # - Default will change to v3 on 11/13/2018
22
+ # - See https://auth0.com/docs/users/search/v3#migrate-from-search-engine-v2-to-v3
20
23
  # @return [json] Returns the list of existing users.
21
24
  def users(options = {})
22
25
  request_params = {
@@ -27,9 +30,9 @@ module Auth0
27
30
  connection: options.fetch(:connection, nil),
28
31
  fields: options.fetch(:fields, nil),
29
32
  include_fields: options.fetch(:include_fields, nil),
30
- q: options.fetch(:q, nil)
33
+ q: options.fetch(:q, nil),
34
+ search_engine: options.fetch(:search_engine, nil)
31
35
  }
32
- request_params[:search_engine] = :v2 if request_params[:q]
33
36
  get(users_path, request_params)
34
37
  end
35
38
  alias get_users users
@@ -1,4 +1,4 @@
1
1
  # current version of gem
2
2
  module Auth0
3
- VERSION = '4.4.0'.freeze
3
+ VERSION = '4.5.0'.freeze
4
4
  end
@@ -1,78 +1,61 @@
1
1
  require 'spec_helper'
2
2
  describe Auth0::Api::AuthenticationEndpoints do
3
- attr_reader :client, :impersonate_user, :impersonator_user, :global_client, :password
3
+ attr_reader :client,
4
+ :impersonate_user,
5
+ :global_client,
6
+ :password
4
7
 
5
8
  before(:all) do
6
9
  @client = Auth0Client.new(Credentials.v2_creds)
7
- impersonate_username = Faker::Internet.user_name
8
- impersonate_email = "#{entity_suffix}#{Faker::Internet.safe_email(impersonate_username)}"
9
- @password = Faker::Internet.password
10
- @impersonate_user = client.create_user(impersonate_username, 'email' => impersonate_email,
11
- 'password' => password,
12
- 'email_verified' => true,
13
- 'connection' =>
14
- Auth0::Api::AuthenticationEndpoints::UP_AUTH,
15
- 'app_metadata' => {})
16
-
17
- impersonator_username = Faker::Internet.user_name
18
- impersonator_email = "#{entity_suffix}#{Faker::Internet.safe_email(impersonator_username)}"
19
- @impersonator_user = client.create_user(impersonator_username, 'email' => impersonator_email,
20
- 'password' => password,
21
- 'email_verified' => true,
22
- 'connection' =>
23
- Auth0::Api::AuthenticationEndpoints::UP_AUTH,
24
- 'app_metadata' => {})
25
-
26
10
  @global_client = Auth0Client.new(v1_global_creds)
27
- end
28
11
 
29
- after(:all) do
30
- client.delete_user(impersonate_user['user_id'])
31
- client.delete_user(impersonator_user['user_id'])
12
+ impersonate_username = Faker::Internet.user_name
13
+ impersonate_email = "#{entity_suffix}" \
14
+ "#{Faker::Internet.safe_email(impersonate_username)}"
15
+ @password = Faker::Internet.password
16
+ @impersonate_user = client.create_user(
17
+ impersonate_username,
18
+ 'email' => impersonate_email,
19
+ 'password' => password,
20
+ 'email_verified' => true,
21
+ 'connection' =>
22
+ Auth0::Api::AuthenticationEndpoints::UP_AUTH,
23
+ 'app_metadata' => {}
24
+ )
32
25
  end
33
26
 
34
27
  describe '.obtain_access_token' do
35
- let(:acces_token) { global_client.obtain_access_token }
28
+ let(:acces_token) { @global_client.obtain_access_token }
36
29
  it { expect(acces_token).to_not be_nil }
37
30
  end
38
31
 
39
32
  describe '.signup' do
40
33
  let(:signup_username) { Faker::Internet.user_name }
41
- let(:signup_email) { "#{entity_suffix}#{Faker::Internet.safe_email(signup_username)}" }
42
- let(:signup) { global_client.signup(signup_email, password) }
34
+ let(:signup_email) {
35
+ "#{entity_suffix}#{Faker::Internet.safe_email(signup_username)}"
36
+ }
37
+ let(:signup) { @global_client.signup(signup_email, @password) }
43
38
  it { expect(signup).to(include('_id', 'email')) }
44
39
  it { expect(signup['email']).to eq signup_email }
45
40
  end
46
41
 
47
42
  describe '.change_password' do
48
43
  let(:change_password) do
49
- global_client.change_password(impersonate_user['user_id'], '')
44
+ @global_client.change_password(@impersonate_user['user_id'], '')
50
45
  end
51
- it { expect(change_password).to(include('We\'ve just sent you an email to reset your password.')) }
52
- end
53
-
54
- skip '.start_passwordless_email_flow' do
55
- let(:start_passwordless_email_flow) do
56
- global_client.start_passwordless_email_flow(impersonate_user['email'])
46
+ it do
47
+ expect(@global_client.change_password(@impersonate_user['user_id'], ''))
48
+ .to(include('We\'ve just sent you an email to reset your password.'))
57
49
  end
58
- it { expect(start_passwordless_email_flow['email']).to eq impersonate_user['email'] }
59
- it { expect(start_passwordless_email_flow).to(include('_id', 'email')) }
60
- end
61
-
62
- skip '.start_passwordless_sms_flow' do
63
- let(:phone_number) { '+19143686854' }
64
- let(:start_passwordless_sms_flow) { global_client.start_passwordless_sms_flow(phone_number) }
65
- it { expect(start_passwordless_sms_flow['phone_number']).to eq phone_number }
66
- it { expect(start_passwordless_sms_flow).to(include('_id', 'phone_number', 'request_language')) }
67
50
  end
68
51
 
69
52
  describe '.saml_metadata' do
70
- let(:saml_metadata) { global_client.saml_metadata }
53
+ let(:saml_metadata) { @global_client.saml_metadata }
71
54
  it { expect(saml_metadata).to(include('<EntityDescriptor')) }
72
55
  end
73
56
 
74
57
  describe '.wsfed_metadata' do
75
- let(:wsfed_metadata) { global_client.wsfed_metadata }
58
+ let(:wsfed_metadata) { @global_client.wsfed_metadata }
76
59
  it { expect(wsfed_metadata).to(include('<EntityDescriptor')) }
77
60
  end
78
61
  end
@@ -5,45 +5,49 @@ describe Auth0::Api::V2::ClientGrants do
5
5
  before(:all) do
6
6
  @client = Auth0Client.new(v2_creds)
7
7
  @client_id = v2_creds[:client_id]
8
- sleep 1
9
- @existing_client = client.create_client("client#{entity_suffix}")
10
- sleep 1
8
+ @existing_client = client.create_client("client-grant-test-#{entity_suffix}")
11
9
  @audience = "https://#{client.clients[0]['tenant']}.auth0.com/api/v2/"
12
10
  @scope = [Faker::Lorem.word]
13
- sleep 1
14
- @existing_grant = client.create_client_grant('client_id' => existing_client['client_id'],
15
- 'audience' => audience,
16
- 'scope' => scope)
11
+ @existing_grant = client.create_client_grant(
12
+ 'client_id' => existing_client['client_id'],
13
+ 'audience' => audience,
14
+ 'scope' => scope
15
+ )
17
16
  end
18
17
 
19
18
  after(:all) do
20
19
  grants = client.client_grants
21
20
  grants.each do |grant|
22
- sleep 1
23
21
  client.delete_client_grant(grant['id'])
24
22
  end
25
23
  end
26
24
 
27
25
  describe '.client_grants' do
28
26
  let(:client_grants) do
29
- sleep 1
30
27
  client.client_grants
31
28
  end
32
29
 
33
- it do
34
- sleep 1
30
+ it 'is expected to have a result' do
35
31
  expect(client_grants.size).to be > 0
36
32
  end
37
- it do
38
- sleep 1
33
+
34
+ it 'is expected to match the created grant' do
39
35
  expect(client_grants).to include(existing_grant)
40
36
  end
37
+
38
+ it 'is expected to return the first page of one result' do
39
+ results = client.client_grants(
40
+ page: 0,
41
+ per_page: 1
42
+ )
43
+ expect(results.first).to equal(results.last)
44
+ expect(results.first).to eq(existing_grant)
45
+ end
41
46
  end
42
47
 
43
48
  describe '.patch_client_grant' do
44
49
  let(:new_scope) { [Faker::Lorem.word] }
45
50
  it do
46
- sleep 1
47
51
  expect(
48
52
  client.patch_client_grant(
49
53
  existing_grant['id'],
@@ -55,7 +59,6 @@ describe Auth0::Api::V2::ClientGrants do
55
59
 
56
60
  describe '.delete_client_grant' do
57
61
  it do
58
- sleep 1
59
62
  expect { client.delete_client_grant(existing_grant['id']) }.to_not raise_error
60
63
  end
61
64
  end
@@ -26,15 +26,31 @@ describe Auth0::Api::V2::Clients do
26
26
  context '#filters' do
27
27
  it do
28
28
  sleep 1
29
- expect(client.clients(fields: [:name, :callbacks].join(',')).first).to(include('name', 'callbacks'))
29
+ expect(client.clients(
30
+ fields: [:name, :callbacks].join(',')
31
+ ).first).to(include('name', 'callbacks'))
30
32
  end
31
33
  it do
32
34
  sleep 1
33
- expect(client.clients(fields: [:callbacks].join(',')).first).to_not(include('name'))
35
+ expect(client.clients(
36
+ fields: [:callbacks].join(',')).first
37
+ ).to_not(include('name'))
34
38
  end
35
39
  it do
36
40
  sleep 1
37
- expect(client.clients(fields: [:callbacks].join(','), include_fields: false).first).to_not(include('callbacks'))
41
+ expect(client.clients(
42
+ fields: [:callbacks].join(','),
43
+ include_fields: false
44
+ ).first).to_not(include('callbacks'))
45
+ end
46
+ it do
47
+ sleep 1
48
+ results = client.clients(
49
+ fields: :name,
50
+ page: 0,
51
+ per_page: 1
52
+ )
53
+ expect(results.first).to equal(results.last)
38
54
  end
39
55
  end
40
56
  end
@@ -16,47 +16,52 @@ describe Auth0::Api::V2::Rules do
16
16
  after(:all) do
17
17
  rules = client.rules
18
18
  rules.each do |rule|
19
- sleep 1
20
19
  client.delete_rule(rule['id'])
21
20
  end
22
21
  end
23
22
 
24
23
  describe '.rules' do
25
24
  let(:rules) do
26
- sleep 1
27
25
  client.rules
28
26
  end
29
27
 
30
28
  it do
31
- sleep 1
32
29
  expect(rules.size).to be > 0
33
30
  end
34
31
 
35
32
  context '#filters' do
36
33
  it do
37
- sleep 1
34
+ sleep 0.5
38
35
  expect(client.rules(enabled: true).size).to be >= 1
39
36
  end
40
37
 
41
38
  it do
42
- sleep 1
39
+ sleep 0.5
43
40
  expect(client.rules(enabled: false).size).to be >= 1
44
41
  end
45
42
 
46
43
  it do
47
- sleep 1
44
+ sleep 0.5
48
45
  expect(client.rules(enabled: true, fields: [:script, :order].join(',')).first).to(include('script', 'order'))
49
46
  end
47
+
50
48
  it do
51
- sleep 1
49
+ sleep 0.5
52
50
  expect(client.rules(enabled: true, fields: [:script].join(',')).first).to_not(include('order', 'name'))
53
51
  end
52
+
53
+ it do
54
+ sleep 0.5
55
+ rule_1 = client.rules(fields: :name, page: 0, per_page: 2)
56
+ sleep 0.5
57
+ rule_2 = client.rules(fields: :name, page: 1, per_page: 1)
58
+ expect(rule_1.last).to eq(rule_2.first)
59
+ end
54
60
  end
55
61
  end
56
62
 
57
63
  describe '.rule' do
58
64
  it do
59
- sleep 1
60
65
  expect(client.rule(enabled_rule['id'])).to(
61
66
  include('stage' => enabled_rule['stage'], 'order' => enabled_rule['order'], 'script' => enabled_rule['script'])
62
67
  )
@@ -64,21 +69,17 @@ describe Auth0::Api::V2::Rules do
64
69
 
65
70
  context '#filters' do
66
71
  let(:rule_include) do
67
- sleep 1
68
72
  client.rule(enabled_rule['id'], fields: [:stage, :order, :script].join(','))
69
73
  end
70
74
  let(:rule_not_include) do
71
- sleep 1
72
75
  client.rule(enabled_rule['id'], fields: :stage, include_fields: false)
73
76
  end
74
77
 
75
78
  it do
76
- sleep 1
77
79
  expect(rule_include).to(include('stage', 'order', 'script'))
78
80
  end
79
81
 
80
82
  it do
81
- sleep 1
82
83
  expect(rule_not_include).to(include('order', 'script'))
83
84
  expect(rule_not_include).to_not(include('stage'))
84
85
  end
@@ -91,29 +92,24 @@ describe Auth0::Api::V2::Rules do
91
92
  let(:script) { 'function(test)' }
92
93
  let(:enabled) { false }
93
94
  let!(:rule) do
94
- sleep 1
95
95
  client.create_rule(name, script, nil, enabled, stage)
96
96
  end
97
97
  it do
98
- sleep 1
99
98
  expect(rule).to include('name' => name, 'stage' => stage, 'script' => script)
100
99
  end
101
100
  end
102
101
 
103
102
  describe '.delete_rule' do
104
103
  it do
105
- sleep 1
106
104
  expect { client.delete_rule(enabled_rule['id']) }.to_not raise_error
107
105
  end
108
106
  it do
109
- sleep 1
110
107
  expect { client.delete_rule '' }.to raise_error(Auth0::InvalidParameter)
111
108
  end
112
109
  end
113
110
 
114
111
  describe '.update_rule' do
115
112
  it do
116
- sleep 1
117
113
  expect(client.update_rule(disabled_rule['id'], enabled: true)).to(include('enabled' => true))
118
114
  end
119
115
  end