auth0 3.6.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +7 -0
  4. data/.rubocop_todo.yml +7 -0
  5. data/.travis.yml +12 -7
  6. data/CHANGELOG.md +10 -0
  7. data/Gemfile +4 -2
  8. data/Guardfile +13 -10
  9. data/LICENSE +2 -2
  10. data/README.md +9 -11
  11. data/Rakefile +33 -7
  12. data/auth0.gemspec +12 -12
  13. data/deploy_documentation.sh +29 -0
  14. data/doc_config/templates/default/fulldoc/html/css/full_list.css +79 -0
  15. data/doc_config/templates/default/fulldoc/html/css/style.css +546 -0
  16. data/doc_config/templates/default/layout/html/breadcrumb.erb +11 -0
  17. data/doc_config/templates/default/layout/html/footer.erb +115 -0
  18. data/doc_config/templates/default/layout/html/headers.erb +17 -0
  19. data/doc_config/templates/default/layout/html/layout.erb +27 -0
  20. data/lib/auth0.rb +5 -5
  21. data/lib/auth0/api/authentication_endpoints.rb +264 -46
  22. data/lib/auth0/api/v1.rb +5 -5
  23. data/lib/auth0/api/v1/clients.rb +7 -7
  24. data/lib/auth0/api/v1/connections.rb +9 -10
  25. data/lib/auth0/api/v1/logs.rb +9 -16
  26. data/lib/auth0/api/v1/rules.rb +5 -5
  27. data/lib/auth0/api/v1/users.rb +28 -27
  28. data/lib/auth0/api/v2.rb +17 -9
  29. data/lib/auth0/api/v2/blacklists.rb +30 -9
  30. data/lib/auth0/api/v2/clients.rb +60 -19
  31. data/lib/auth0/api/v2/connections.rb +63 -10
  32. data/lib/auth0/api/v2/emails.rb +58 -0
  33. data/lib/auth0/api/v2/jobs.rb +44 -7
  34. data/lib/auth0/api/v2/rules.rb +104 -0
  35. data/lib/auth0/api/v2/stats.rb +22 -5
  36. data/lib/auth0/api/v2/tenants.rb +39 -0
  37. data/lib/auth0/api/v2/tickets.rb +58 -0
  38. data/lib/auth0/api/v2/users.rb +128 -39
  39. data/lib/auth0/client.rb +8 -6
  40. data/lib/auth0/exception.rb +29 -23
  41. data/lib/auth0/mixins.rb +12 -10
  42. data/lib/auth0/mixins/httparty_proxy.rb +13 -10
  43. data/lib/auth0/mixins/initializer.rb +25 -27
  44. data/lib/auth0/version.rb +2 -2
  45. data/spec/integration/lib/auth0/api/v1/api_clients_spec.rb +2 -4
  46. data/spec/integration/lib/auth0/api/v1/api_users_spec.rb +25 -32
  47. data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +14 -0
  48. data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +61 -6
  49. data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +68 -42
  50. data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +71 -0
  51. data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +69 -0
  52. data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +83 -0
  53. data/spec/integration/lib/auth0/api/v2/api_stats_spec.rb +16 -0
  54. data/spec/integration/lib/auth0/api/v2/api_tenants_spec.rb +37 -0
  55. data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +33 -0
  56. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +88 -36
  57. data/spec/integration/lib/auth0/auth0_client_spec.rb +43 -35
  58. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +253 -47
  59. data/spec/lib/auth0/api/v1/clients_spec.rb +37 -38
  60. data/spec/lib/auth0/api/v1/connections_spec.rb +44 -38
  61. data/spec/lib/auth0/api/v1/logs_spec.rb +24 -24
  62. data/spec/lib/auth0/api/v1/rules_spec.rb +23 -22
  63. data/spec/lib/auth0/api/v1/users_spec.rb +153 -130
  64. data/spec/lib/auth0/api/v2/blacklists_spec.rb +12 -11
  65. data/spec/lib/auth0/api/v2/clients_spec.rb +38 -33
  66. data/spec/lib/auth0/api/v2/connections_spec.rb +59 -34
  67. data/spec/lib/auth0/api/v2/emails_spec.rb +47 -0
  68. data/spec/lib/auth0/api/v2/jobs_spec.rb +24 -10
  69. data/spec/lib/auth0/api/v2/rules_spec.rb +69 -0
  70. data/spec/lib/auth0/api/v2/stats_spec.rb +11 -11
  71. data/spec/lib/auth0/api/v2/tenants_spec.rb +25 -0
  72. data/spec/lib/auth0/api/v2/tickets_spec.rb +31 -0
  73. data/spec/lib/auth0/api/v2/users_spec.rb +101 -39
  74. data/spec/lib/auth0/client_spec.rb +46 -58
  75. data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +98 -69
  76. data/spec/lib/auth0/mixins/initializer_spec.rb +2 -2
  77. data/spec/spec_helper.rb +2 -2
  78. data/spec/spec_helper_full.rb +16 -15
  79. data/spec/spec_helper_unit.rb +5 -5
  80. data/spec/support/credentials.rb +9 -3
  81. data/spec/support/dummy_class.rb +7 -1
  82. data/spec/support/dummy_class_for_proxy.rb +2 -2
  83. data/spec/support/import_users.json +13 -0
  84. data/spec/support/stub_response.rb +1 -2
  85. metadata +78 -41
@@ -1,71 +1,160 @@
1
1
  module Auth0
2
2
  module Api
3
3
  module V2
4
- #https://auth0.com/docs/apiv2#!/users
4
+ # Methods to use the users endpoints
5
5
  module Users
6
- #https://auth0.com/docs/apiv2#!/users/get_users
7
- def users( per_page: nil, page: nil, include_totals: nil, sort: nil, connection: nil, fields: nil, q: nil )
6
+ attr_reader :users_path
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] 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
+ #
20
+ # @return [json] The list of existing users.
21
+ def users(options = {})
8
22
  request_params = {
9
- per_page: per_page,
10
- page: page,
11
- include_totals: include_totals,
12
- sort: sort,
13
- connection: connection,
14
- fields: fields,
15
- q: q
23
+ per_page: options.fetch(:per_page, nil),
24
+ page: options.fetch(:page, nil),
25
+ include_totals: options.fetch(:include_totals, nil),
26
+ sort: options.fetch(:sort, nil),
27
+ connection: options.fetch(:connection, nil),
28
+ fields: options.fetch(:fields, nil),
29
+ include_fields: options.fetch(:include_fields, nil),
30
+ q: options.fetch(:q, nil)
16
31
  }
17
-
18
- if request_params[:q]
19
- request_params[:search_engine] = :v2
20
- end
21
-
22
- path = "/api/v2/users"
23
- get(path, request_params)
32
+ request_params[:search_engine] = :v2 if request_params[:q]
33
+ get(users_path, request_params)
24
34
  end
25
- alias :get_users :users
35
+ alias_method :get_users, :users
26
36
 
27
- #https://auth0.com/docs/apiv2#!/users/post_users
28
- def create_user(name, options={})
29
- path = "/api/v2/users"
30
- request_params = Hash[options.map{|(k,v)| [k.to_sym,v]}]
37
+ # Creates a new user according to optional parameters received.
38
+ # The attribute connection is always mandatory but depending on the type of connection you are using there
39
+ # could be others too. For instance, Auth0 DB Connections require email and password.
40
+ # @see https://auth0.com/docs/api/v2#!/Users/post_users
41
+ # @param name [string] the user name
42
+ # @param connection [string] The connection the user belongs to
43
+ #
44
+ # @return [json]
45
+ def create_user(name, options = {})
46
+ request_params = Hash[options.map { |(k, v)| [k.to_sym, v] }]
31
47
  request_params[:name] = name
32
- post(path, request_params)
48
+ post(users_path, request_params)
33
49
  end
34
50
 
35
- #https://auth0.com/docs/apiv2#!/users/delete_users
51
+ # Delete all users - USE WITH CAUTION
52
+ # @see https://auth0.com/docs/api/v2#!/Users/delete_users
36
53
  def delete_users
37
- path = "/api/v2/users"
38
- delete(path)
54
+ delete(users_path)
39
55
  end
40
56
 
41
- #https://auth0.com/docs/apiv2#!/users/get_users_by_id
42
- def user(user_id, fields: nil)
43
- path = "/api/v2/users/" + user_id.to_s
57
+ # Retrieves a user given a user_id
58
+ # @see https://auth0.com/docs/api/v2#!/Users/get_users_by_id
59
+ # @param user_id [string] The user_id of the user to retrieve
60
+ # @param fields [string] A comma separated list of fields to include or exclude from the result.
61
+ # @param include_fields [boolean] if the fields specified are to be included in the result, false otherwise.
62
+ #
63
+ # @return [json] the user with the given user_id if exists
64
+ def user(user_id, fields: nil, include_fields: true)
65
+ fail Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
66
+ path = "#{users_path}/#{user_id}"
44
67
  request_params = {
45
68
  fields: fields,
69
+ include_fields: include_fields
46
70
  }
47
71
  get(path, request_params)
48
72
  end
49
73
 
50
- #https://auth0.com/docs/apiv2#!/users/delete_users_by_id
74
+ # Deletes a single user given its id
75
+ # @see https://auth0.com/docs/api/v2#!/Users/delete_users_by_id
76
+ # @param user_id [string] The user_id of the user to delete
51
77
  def delete_user(user_id)
52
- raise Auth0::MissingUserId, "Must supply a valid user_id" if user_id.nil? or user_id.to_s.empty?
53
- path = "/api/v2/users/" + user_id.to_s
78
+ fail Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
79
+ path = "#{users_path}/#{user_id}"
54
80
  delete(path)
55
81
  end
56
82
 
57
-
58
- #https://auth0.com/docs/apiv2#!/users/patch_users_by_id
59
- def patch_user(user_id, options)
60
- path = "/api/v2/users/" + user_id
61
- patch(path, options)
83
+ # Updates a user with the object's properties received in the optional parameters.
84
+ # These are the attributes that can be updated at the root level:
85
+ # blocked, email_verified, email, verify_email, password, phone_number, phone_verified,
86
+ # verify_password, user_metadata, app_metadata, username
87
+ # Some considerations:
88
+ # The properties of the new object will replace the old ones.
89
+ # The metadata fields are an exception to this rule (user_metadata and app_metadata). These properties are
90
+ # merged instead of being replaced but be careful, the merge only occurs on the first level.
91
+ # If you are updating email_verified, phone_verified, username or password you need to specify the connection
92
+ # property too.
93
+ # If your are updating email or phone_number you need to specify the connection and the client_id properties.
94
+ # @see https://auth0.com/docs/api/v2#!/Users/patch_users_by_id
95
+ # @param user_id [string] The user_id of the user to update.
96
+ # @param body [hash] The optional parametes to update
97
+ #
98
+ # @return [json] the updated user
99
+ def patch_user(user_id, body)
100
+ fail Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
101
+ fail Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
102
+ path = "#{users_path}/#{user_id}"
103
+ patch(path, body)
62
104
  end
63
105
 
64
- #https://auth0.com/docs/apiv2#!/users/delete_multifactor_by_provider
106
+ # Delete a user's multifactor provider
107
+ # @see https://auth0.com/docs/api/v2#!/Users/delete_multifactor_by_provider
108
+ # @param user_id [string] The user_id of the user to delete
109
+ # @param provider_name [string] The multifactor provider. Supported values 'duo' or 'google-authenticator'
65
110
  def delete_user_provider(user_id, provider_name)
66
- path = "/api/v2/users/#{user_id}/multifactor/#{provider_name}"
111
+ fail Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
112
+ fail Auth0::InvalidParameter, 'Must supply a valid provider name' if provider_name.to_s.empty?
113
+ path = "#{users_path}/#{user_id}/multifactor/#{provider_name}"
67
114
  delete(path)
68
115
  end
116
+
117
+ # Links the account specified in the body (secondary account) to the account specified by the id param
118
+ # of the URL (primary account).
119
+ # 1. With the authenticated primary account's JWT in the Authorization header, which has the
120
+ # update:current_user_identities scope. In this case only the link_with param is required in the body,
121
+ # containing the JWT obtained upon the secondary account's authentication.
122
+ # 2. With an API V2 generated token with update:users scope. In this case you need to send provider and user_id
123
+ # in the body. Optionally you can also send the connection_id param which is suitable for identifying a
124
+ # particular database connection for the 'auth0' provider.
125
+ # @see https://auth0.com/docs/api/v2#!/Users/post_identities
126
+ # @param user_id [string] The user_id of the primary identity where you are linking the secondary account to.
127
+ # @param body [string] the options to link the account to.
128
+ #
129
+ # @return [json] the new array of the primary account identities.
130
+ def link_user_account(user_id, body)
131
+ fail Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
132
+ fail Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
133
+ path = "#{users_path}/#{user_id}/identities"
134
+ post(path, body)
135
+ end
136
+
137
+ # Unlink a user account
138
+ # @see https://auth0.com/docs/api/v2#!/Users/delete_provider_by_user_id
139
+ # @param user_id [string] The user_id of the user identity.
140
+ # @param provider [string] The type of identity provider.
141
+ # @param secondary_user_id [string] The unique identifier for the user for the identity.
142
+ #
143
+ # @return [json] the array of the unlinked account identities.
144
+ def unlink_users_account(user_id, provider, secondary_user_id)
145
+ fail Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
146
+ fail Auth0::MissingUserId, 'Must supply a valid secondary user_id' if secondary_user_id.to_s.empty?
147
+ fail Auth0::InvalidParameter, 'Must supply a valid provider' if provider.to_s.empty?
148
+ path = "#{users_path}/#{user_id}/identities/#{provider}/#{secondary_user_id}"
149
+ delete(path)
150
+ end
151
+
152
+ private
153
+
154
+ # Users API path
155
+ def users_path
156
+ @users_path ||= '/api/v2/users'
157
+ end
69
158
  end
70
159
  end
71
160
  end
@@ -1,7 +1,9 @@
1
- # Main class
2
- # All Api calls are suposed to return hashes, but delete actions return strings.
3
- class Auth0::Client
4
- include Auth0::Mixins
5
- include HTTParty
6
- base_uri "http://auth0.com"
1
+ module Auth0
2
+ # Main class
3
+ # All Api calls are suposed to return hashes, but delete actions return strings.
4
+ class Client
5
+ include Auth0::Mixins
6
+ include HTTMultiParty
7
+ base_uri 'http://auth0.com'
8
+ end
7
9
  end
@@ -2,27 +2,33 @@ module Auth0
2
2
  # Default exception in namespace of Auth0
3
3
  # if you want to catch all exceptions, then you should use this one.
4
4
  # Network exceptions are not included
5
- class Exception < StandardError; end
5
+ class Exception < StandardError; end
6
+ # exception for unauthorized requests, if you see it,
7
+ # probably Bearer Token is not set correctly
8
+ class Unauthorized < Auth0::Exception; end
9
+ # exception for not found resource, you query for an
10
+ # unexistent resource, or wrong path
11
+ class NotFound < Auth0::Exception; end
12
+ # exception for unknown error
13
+ class Unsupported < Auth0::Exception; end
14
+ # exception for server error
15
+ class ServerError < Auth0::Exception; end
16
+ # exception for incorrect request, you've sent wrong params
17
+ class BadRequest < Auth0::Exception; end
18
+ # exception for unset user_id, this might cause removal of
19
+ # all users, or other unexpected behaviour
20
+ class MissingUserId < Auth0::Exception; end
21
+ # exception for unset client_id
22
+ class MissingClientId < Auth0::Exception; end
23
+ # exception for an unset parameter
24
+ class MissingParameter < Auth0::Exception; end
25
+ # Api v2 access denied
26
+ class AccessDenied < Auth0::Exception; end
27
+ # Invalid parameter passed, e.g. empty where ID is required
28
+ class InvalidParameter < Auth0::Exception; end
29
+ # Invalid Auth0 credentials either client_id/secret for API v1
30
+ # or JWT for API v2/
31
+ class InvalidCredentials < Auth0::Exception; end
32
+ # Invalid Auth0 API namespace
33
+ class InvalidApiNamespace < Auth0::Exception; end
6
34
  end
7
- # exception for unauthorized requests, if you see it, probably Bearer Token is not set correctly
8
- class Auth0::Unauthorized < Auth0::Exception; end
9
- # exception for not found resource, you query for an unexistent resource, or wrong path
10
- class Auth0::NotFound < Auth0::Exception; end
11
- # exception for unknown error
12
- class Auth0::Unsupported < Auth0::Exception; end
13
- # exception for server error
14
- class Auth0::ServerError < Auth0::Exception; end
15
- # exception for incorrect request, you've sent wrong params
16
- class Auth0::BadRequest < Auth0::Exception; end
17
- # exception for unset user_id, this might cause removal of all users, or other unexpected bahaviour
18
- class Auth0::MissingUserId < Auth0::Exception; end
19
- # exception for an unset connection_id
20
- class Auth0::MissingConnectionId < Auth0::Exception; end
21
- # Api v2 access denied
22
- class Auth0::AccessDenied < Auth0::Exception; end
23
- # Invalid parameter passed, e.g. empty where ID is required
24
- class Auth0::InvalidParameter < Auth0::Exception; end
25
- # Invalid Auth0 credentials either client_id/secret for API v1 or JWT for API v2/
26
- class Auth0::InvalidCredentials < Auth0::Exception; end
27
- # Invalid Auth0 API namespace
28
- class Auth0::InvalidApiNamespace < Auth0::Exception; end
@@ -1,12 +1,14 @@
1
- require 'httparty'
1
+ require 'httmultiparty'
2
2
  require 'uri'
3
- require "auth0/mixins/httparty_proxy"
4
- require "auth0/mixins/initializer"
5
- require "auth0/api/authentication_endpoints"
6
- require "auth0/api/v1"
7
- require "auth0/api/v2"
8
- # Collecting dependencies here
9
- module Auth0::Mixins
10
- include Auth0::Mixins::HTTPartyProxy
11
- include Auth0::Mixins::Initializer
3
+ require 'auth0/mixins/httparty_proxy'
4
+ require 'auth0/mixins/initializer'
5
+ require 'auth0/api/authentication_endpoints'
6
+ require 'auth0/api/v1'
7
+ require 'auth0/api/v2'
8
+ module Auth0
9
+ # Collecting dependencies here
10
+ module Mixins
11
+ include Auth0::Mixins::HTTPartyProxy
12
+ include Auth0::Mixins::Initializer
13
+ end
12
14
  end
@@ -1,14 +1,17 @@
1
1
  module Auth0
2
2
  module Mixins
3
- # here's the proxy for HTTParty, we're building all request on that gem for now, if you want to feel free to use your own http client
3
+ # here's the proxy for HTTParty, we're building all request on that gem
4
+ # for now, if you want to feel free to use your own http client
4
5
  module HTTPartyProxy
5
6
  # proxying requests from instance methods to HTTParty class methods
6
- %i(get post put patch delete).each do |method|
7
- define_method(method) do |path, body={}|
7
+ %i(get post post_file put patch delete).each do |method|
8
+ define_method(method) do |path, body = {}|
8
9
  safe_path = URI.escape(path)
9
- body = body.delete_if {|k,v| v.nil? }
10
+ body = body.delete_if { |_, v| v.nil? }
10
11
  if method == :get
11
12
  result = self.class.send(method, safe_path, query: body)
13
+ elsif method == :post_file
14
+ result = self.class.send(:post, safe_path, body: body, detect_mime_type: true)
12
15
  else
13
16
  result = self.class.send(method, safe_path, body: body.to_json)
14
17
  end
@@ -20,13 +23,13 @@ module Auth0
20
23
  end
21
24
  case result.code
22
25
  when 200...226 then response_body
23
- when 400 then raise Auth0::BadRequest, response_body
24
- when 401 then raise Auth0::Unauthorized, response_body
25
- when 403 then raise Auth0::AccessDenied, response_body
26
- when 404 then raise Auth0::NotFound, response_body
27
- when 500 then raise Auth0::ServerError, response_body
26
+ when 400 then fail Auth0::BadRequest, response_body
27
+ when 401 then fail Auth0::Unauthorized, response_body
28
+ when 403 then fail Auth0::AccessDenied, response_body
29
+ when 404 then fail Auth0::NotFound, response_body
30
+ when 500 then fail Auth0::ServerError, response_body
28
31
  else
29
- raise Auth0::Unsupported, response_body
32
+ fail Auth0::Unsupported, response_body
30
33
  end
31
34
  end
32
35
  end
@@ -6,19 +6,14 @@ module Auth0
6
6
  # accepts hash as parameter
7
7
  # you can get all required fields from here: https://auth0.com/docs/auth-api
8
8
  #
9
- # To run using api v2, pass api_version: 2 when creating a client
9
+ # By Default API v2
10
10
  def initialize(config)
11
- options = Hash[config.map{|(k,v)| [k.to_sym,v]}]
12
- domain = api_domain options
13
- raise InvalidApiNamespace, "Api namespace must supply an API domain" if domain.nil?
14
- self.class.base_uri "https://#{domain}"
11
+ options = Hash[config.map { |(k, v)| [k.to_sym, v] }]
12
+ self.class.base_uri base_url(options)
15
13
  self.class.headers client_headers(config)
16
- self.extend Auth0::Api::AuthenticationEndpoints
17
- @client_id = options[:client_id]
18
- initialize_v2(options) if api_v2?(options)
19
- initialize_v1(options) if api_v1?(options)
20
- raise InvalidCredentials, "Must supply a valid API token" if @token.nil?
21
- self.class.headers "Authorization" => "Bearer #{@token}"
14
+ extend Auth0::Api::AuthenticationEndpoints
15
+ @client_id = options[:client_id]
16
+ initialize_api(options)
22
17
  end
23
18
 
24
19
  # including initializer in top of klass
@@ -28,14 +23,26 @@ module Auth0
28
23
 
29
24
  private
30
25
 
26
+ def initialize_api(options)
27
+ api_v1?(options) ? initialize_v1(options) : initialize_v2(options)
28
+ fail InvalidCredentials, 'Must supply a valid API token' if @token.nil?
29
+ self.class.headers 'Authorization' => "Bearer #{@token}"
30
+ end
31
+
32
+ def base_url(options)
33
+ @domain = options[:domain] || options[:namespace]
34
+ fail InvalidApiNamespace, 'Api namespace must supply an API domain' if @domain.to_s.empty?
35
+ "https://#{@domain}"
36
+ end
37
+
31
38
  def client_headers(config)
32
- client_info = JSON.dump({name: 'ruby-auth0', version: Auth0::VERSION})
39
+ client_info = JSON.dump(name: 'ruby-auth0', version: Auth0::VERSION)
33
40
 
34
41
  headers = {
35
42
  'Content-Type' => 'application/json'
36
43
  }
37
44
 
38
- if !config[:opt_out_sdk_info]
45
+ unless config[:opt_out_sdk_info]
39
46
  headers['User-Agent'] = "Ruby/#{RUBY_VERSION}"
40
47
  headers['Auth0-Client'] = Base64.urlsafe_encode64(client_info)
41
48
  end
@@ -43,32 +50,23 @@ module Auth0
43
50
  headers
44
51
  end
45
52
 
46
- def api_domain(options)
47
- options[:domain] || options[:namespace]
48
- end
49
-
50
53
  def initialize_v2(options)
51
- self.extend Auth0::Api::V2
54
+ extend Auth0::Api::V2
52
55
  @token = options[:access_token] || options[:token]
53
56
  end
54
57
 
55
58
  def initialize_v1(options)
56
- self.extend Auth0::Api::V1
57
- @client_secret = options[:client_secret]
58
- raise InvalidCredentials, "Invalid API v1 client_id and client_secret" if @client_id.nil? or @client_secret.nil?
59
+ extend Auth0::Api::V1
60
+ @client_secret = options[:client_secret]
61
+ fail InvalidCredentials, 'Invalid API v1 client_id and client_secret' if @client_id.nil? || @client_secret.nil?
59
62
  @token = obtain_access_token
60
63
  end
61
64
 
62
- def api_v2?(options)
63
- options[:protocols].to_s.include?("v2") or options[:api_version] === 2
64
- end
65
-
66
65
  def api_v1?(options)
67
66
  version = options[:api_version] || 1
68
67
  protocol = options[:protocols].to_s
69
- not protocol.include?("v2") and (protocol.include?("v1") or version === 1)
68
+ !protocol.include?('v2') && (protocol.include?('v1') || version == 1)
70
69
  end
71
-
72
70
  end
73
71
  end
74
72
  end
@@ -1,4 +1,4 @@
1
+ # current version of gem
1
2
  module Auth0
2
- # current version of gem
3
- VERSION = "3.6.1"
3
+ VERSION = '4.0.0'
4
4
  end
@@ -1,14 +1,12 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
  describe Auth0::Api::V1::Clients do
3
-
4
3
  let(:client) { Auth0Client.new(v1_creds) }
5
4
  let(:global_client) { Auth0Client.new(v1_global_creds) }
6
5
  let(:client_name) { "client#{entity_suffix}" }
7
6
 
8
7
  it { expect(client.clients).to_not be_empty }
9
8
 
10
- it { expect {client.create_client(client_name)}.to raise_error(Auth0::Unauthorized) }
9
+ it { expect { client.create_client(client_name) }.to raise_error(Auth0::Unauthorized) }
11
10
 
12
11
  it { expect(global_client.create_client(client_name)).to_not be_nil }
13
-
14
12
  end