Skip to content

Commit 79f2487

Browse files
authored
Merge branch 'master' into dependabot/bundler/examples/ruby-api/sinatra-4.2.0
2 parents 7f7409c + bbc60b4 commit 79f2487

4 files changed

Lines changed: 148 additions & 70 deletions

File tree

Gemfile.lock

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ PATH
1111
GEM
1212
remote: https://rubygems.org/
1313
specs:
14-
actionpack (8.1.1)
15-
actionview (= 8.1.1)
16-
activesupport (= 8.1.1)
14+
actionpack (8.1.2)
15+
actionview (= 8.1.2)
16+
activesupport (= 8.1.2)
1717
nokogiri (>= 1.8.5)
1818
rack (>= 2.2.4)
1919
rack-session (>= 1.0.1)
2020
rack-test (>= 0.6.3)
2121
rails-dom-testing (~> 2.2)
2222
rails-html-sanitizer (~> 1.6)
2323
useragent (~> 0.16)
24-
actionview (8.1.1)
25-
activesupport (= 8.1.1)
24+
actionview (8.1.2)
25+
activesupport (= 8.1.2)
2626
builder (~> 3.1)
2727
erubi (~> 1.11)
2828
rails-dom-testing (~> 2.2)
2929
rails-html-sanitizer (~> 1.6)
30-
activesupport (8.1.1)
30+
activesupport (8.1.2)
3131
base64
3232
bigdecimal
3333
concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -44,11 +44,11 @@ GEM
4444
public_suffix (>= 2.0.2, < 8.0)
4545
ast (2.4.3)
4646
base64 (0.3.0)
47-
bigdecimal (3.3.1)
47+
bigdecimal (4.0.1)
4848
builder (3.3.0)
4949
coderay (1.1.3)
50-
concurrent-ruby (1.3.5)
51-
connection_pool (2.5.5)
50+
concurrent-ruby (1.3.6)
51+
connection_pool (3.0.2)
5252
coveralls (0.7.1)
5353
multi_json (~> 1.3)
5454
rest-client
@@ -59,7 +59,7 @@ GEM
5959
bigdecimal
6060
rexml
6161
crass (1.0.6)
62-
date (3.5.0)
62+
date (3.5.1)
6363
diff-lcs (1.6.2)
6464
docile (1.4.1)
6565
domain_name (0.6.20240107)
@@ -68,7 +68,7 @@ GEM
6868
dotenv (= 2.8.1)
6969
railties (>= 3.2)
7070
drb (2.2.3)
71-
erb (6.0.0)
71+
erb (6.0.1)
7272
erubi (1.13.0)
7373
faker (2.23.0)
7474
i18n (>= 1.8.11, < 2)
@@ -104,10 +104,10 @@ GEM
104104
http-accept (1.7.0)
105105
http-cookie (1.0.7)
106106
domain_name (~> 0.5)
107-
i18n (1.14.7)
107+
i18n (1.14.8)
108108
concurrent-ruby (~> 1.0)
109-
io-console (0.8.1)
110-
irb (1.15.3)
109+
io-console (0.8.2)
110+
irb (1.16.0)
111111
pp (>= 0.6.0)
112112
rdoc (>= 4.0.0)
113113
reline (>= 0.4.2)
@@ -130,28 +130,29 @@ GEM
130130
mime-types-data (~> 3.2015)
131131
mime-types-data (3.2024.1105)
132132
mini_portile2 (2.8.9)
133-
minitest (5.26.2)
133+
minitest (6.0.1)
134+
prism (~> 1.5)
134135
multi_json (1.15.0)
135136
nenv (0.3.0)
136137
netrc (0.11.0)
137-
nokogiri (1.18.9)
138+
nokogiri (1.19.1)
138139
mini_portile2 (~> 2.8.2)
139140
racc (~> 1.4)
140-
nokogiri (1.18.9-aarch64-linux-gnu)
141+
nokogiri (1.19.1-aarch64-linux-gnu)
141142
racc (~> 1.4)
142-
nokogiri (1.18.9-aarch64-linux-musl)
143+
nokogiri (1.19.1-aarch64-linux-musl)
143144
racc (~> 1.4)
144-
nokogiri (1.18.9-arm-linux-gnu)
145+
nokogiri (1.19.1-arm-linux-gnu)
145146
racc (~> 1.4)
146-
nokogiri (1.18.9-arm-linux-musl)
147+
nokogiri (1.19.1-arm-linux-musl)
147148
racc (~> 1.4)
148-
nokogiri (1.18.9-arm64-darwin)
149+
nokogiri (1.19.1-arm64-darwin)
149150
racc (~> 1.4)
150-
nokogiri (1.18.9-x86_64-darwin)
151+
nokogiri (1.19.1-x86_64-darwin)
151152
racc (~> 1.4)
152-
nokogiri (1.18.9-x86_64-linux-gnu)
153+
nokogiri (1.19.1-x86_64-linux-gnu)
153154
racc (~> 1.4)
154-
nokogiri (1.18.9-x86_64-linux-musl)
155+
nokogiri (1.19.1-x86_64-linux-musl)
155156
racc (~> 1.4)
156157
notiffany (0.1.3)
157158
nenv (~> 0.1)
@@ -167,12 +168,12 @@ GEM
167168
pry (0.15.0)
168169
coderay (~> 1.1)
169170
method_source (~> 1.0)
170-
psych (5.2.6)
171+
psych (5.3.1)
171172
date
172173
stringio
173174
public_suffix (7.0.0)
174175
racc (1.8.1)
175-
rack (3.2.4)
176+
rack (3.2.5)
176177
rack-session (2.1.1)
177178
base64 (>= 0.1.0)
178179
rack (>= 3.0.0)
@@ -187,9 +188,9 @@ GEM
187188
rails-html-sanitizer (1.6.0)
188189
loofah (~> 2.21)
189190
nokogiri (~> 1.14)
190-
railties (8.1.1)
191-
actionpack (= 8.1.1)
192-
activesupport (= 8.1.1)
191+
railties (8.1.2)
192+
actionpack (= 8.1.2)
193+
activesupport (= 8.1.2)
193194
irb (~> 1.13)
194195
rackup (>= 1.0.0)
195196
rake (>= 12.2)
@@ -201,7 +202,7 @@ GEM
201202
rb-fsevent (0.11.2)
202203
rb-inotify (0.11.1)
203204
ffi (~> 1.0)
204-
rdoc (6.15.1)
205+
rdoc (7.1.0)
205206
erb
206207
psych (>= 4.0.0)
207208
tsort
@@ -242,7 +243,7 @@ GEM
242243
rubocop-ast (1.49.0)
243244
parser (>= 3.3.7.2)
244245
prism (~> 1.7)
245-
rubocop-rails (2.34.1)
246+
rubocop-rails (2.34.3)
246247
activesupport (>= 4.2.0)
247248
lint_roller (~> 1.1)
248249
rack (>= 1.1)
@@ -260,7 +261,7 @@ GEM
260261
simplecov (~> 0.19)
261262
simplecov-html (0.13.1)
262263
simplecov_json_formatter (0.1.4)
263-
stringio (3.1.8)
264+
stringio (3.2.0)
264265
sync (0.5.0)
265266
term-ansicolor (1.11.2)
266267
tins (~> 1.0)
@@ -283,7 +284,7 @@ GEM
283284
addressable (>= 2.8.0)
284285
crack (>= 0.3.2)
285286
hashdiff (>= 0.4.0, < 2.0.0)
286-
zache (0.15.0)
287+
zache (0.15.2)
287288
zeitwerk (2.7.1)
288289

289290
PLATFORMS

lib/auth0/api/v2/users.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Auth0
22
module Api
33
module V2
4-
# Methods to use the users endpoints
4+
# Methods to use the users' endpoints
55
module Users
66
include Auth0::Mixins::Validation
77

@@ -94,10 +94,10 @@ def delete_user(user_id)
9494
# Some considerations:
9595
# The properties of the new object will replace the old ones.
9696
# The metadata fields are an exception to this rule (user_metadata and app_metadata). These properties are
97-
# merged instead of being replaced but be careful, the merge only occurs on the first level.
97+
# merged instead of being replaced, but be careful, the merge only occurs on the first level.
9898
# If you are updating email_verified, phone_verified, username or password you need to specify the connection
9999
# property too.
100-
# If your are updating email or phone_number you need to specify the connection and the client_id properties.
100+
# If you are updating email or phone_number you need to specify the connection and the client_id properties.
101101
# @see https://auth0.com/docs/api/v2#!/Users/patch_users_by_id
102102
# @param user_id [string] The user_id of the user to update.
103103
# @param body [hash] The optional parameters to update.
@@ -137,7 +137,7 @@ def delete_user_provider(user_id, provider_name)
137137
# update:current_user_identities scope. In this case only the link_with param is required in the body,
138138
# containing the JWT obtained upon the secondary account's authentication.
139139
# 2. With an API V2 generated token with update:users scope. In this case you need to send provider and user_id
140-
# in the body. Optionally you can also send the connection_id param which is suitable for identifying a
140+
# in the body. Optionally, you can also send the connection_id param, which is suitable for identifying a
141141
# particular database connection for the 'auth0' provider.
142142
# @see https://auth0.com/docs/api/v2#!/Users/post_identities
143143
# @param user_id [string] The user_id of the primary identity where you are linking the secondary account to.

lib/auth0/mixins/httpproxy.rb

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
require "addressable/uri"
2-
require "retryable"
3-
require_relative "../exception.rb"
1+
# frozen_string_literal: true
2+
3+
require 'addressable/uri'
4+
require 'retryable'
5+
require_relative '../exception'
46

57
module Auth0
68
module Mixins
79
# here's the proxy for Rest calls based on rest-client, we're building all request on that gem
810
# for now, if you want to feel free to use your own http client
911
module HTTPProxy
1012
attr_accessor :headers, :base_uri, :timeout, :retry_count
13+
1114
DEFAULT_RETRIES = 3
1215
MAX_ALLOWED_RETRIES = 10
1316
MAX_REQUEST_RETRY_JITTER = 250
@@ -16,19 +19,19 @@ module HTTPProxy
1619
BASE_DELAY = 100
1720

1821
# proxying requests from instance methods to HTTP class methods
19-
%i(get post post_file post_form put patch delete delete_with_body).each do |method|
22+
%i[get post post_file post_form put patch delete delete_with_body].each do |method|
2023
define_method(method) do |uri, body = {}, extra_headers = {}|
21-
body = body.delete_if { |_, v| v.nil? }
22-
token = get_token()
24+
body = safe_merge_body(body, extra_headers)
25+
token = get_token
2326
authorization_header(token) unless token.nil?
2427
request_with_retry(method, uri, body, extra_headers)
2528
end
2629
end
2730

2831
def retry_options
2932
sleep_timer = lambda do |attempt|
30-
wait = BASE_DELAY * (2**attempt-1) # Exponential delay with each subsequent request attempt.
31-
wait += rand(wait+1..wait+MAX_REQUEST_RETRY_JITTER) # Add jitter to the delay window.
33+
wait = BASE_DELAY * (2**attempt - 1) # Exponential delay with each subsequent request attempt.
34+
wait += rand(wait + 1..wait + MAX_REQUEST_RETRY_JITTER) # Add jitter to the delay window.
3235
wait = [MAX_REQUEST_RETRY_DELAY, wait].min # Cap delay at MAX_REQUEST_RETRY_DELAY.
3336
wait = [MIN_REQUEST_RETRY_DELAY, wait].max # Ensure delay is no less than MIN_REQUEST_RETRY_DELAY.
3437
wait / 1000.to_f.round(2) # convert ms to seconds
@@ -55,6 +58,7 @@ def url(path)
5558

5659
def add_headers(h = {})
5760
raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
61+
5862
@headers ||= {}
5963
@headers.merge!(h.to_hash)
6064
end
@@ -72,36 +76,38 @@ def request_with_retry(method, uri, body = {}, extra_headers = {})
7276
end
7377

7478
def request(method, uri, body = {}, extra_headers = {})
75-
result = if method == :get
76-
@headers ||= {}
77-
get_headers = @headers.merge({params: body}).merge(extra_headers)
78-
call(:get, encode_uri(uri), timeout, get_headers)
79-
elsif method == :delete
80-
@headers ||= {}
81-
delete_headers = @headers.merge({ params: body })
82-
call(:delete, encode_uri(uri), timeout, delete_headers)
83-
elsif method == :delete_with_body
84-
call(:delete, encode_uri(uri), timeout, headers, body.to_json)
85-
elsif method == :post_file
86-
body.merge!(multipart: true)
87-
# Ignore the default Content-Type headers and let the HTTP client define them
88-
post_file_headers = headers.except('Content-Type') if headers != nil
89-
# Actual call with the altered headers
90-
call(:post, encode_uri(uri), timeout, post_file_headers, body)
91-
elsif method == :post_form
92-
form_post_headers = headers.except('Content-Type') if headers != nil
93-
call(:post, encode_uri(uri), timeout, form_post_headers, body.compact)
94-
else
95-
call(method, encode_uri(uri), timeout, headers, body.to_json)
96-
end
79+
result = case method
80+
when :get
81+
@headers ||= {}
82+
get_headers = @headers.merge({ params: body }).merge(extra_headers)
83+
call(:get, encode_uri(uri), timeout, get_headers)
84+
when :delete
85+
@headers ||= {}
86+
delete_headers = @headers.merge({ params: body })
87+
call(:delete, encode_uri(uri), timeout, delete_headers)
88+
when :delete_with_body
89+
call(:delete, encode_uri(uri), timeout, headers, body.to_json)
90+
when :post_file
91+
body.merge!(multipart: true)
92+
# Ignore the default Content-Type headers and let the HTTP client define them
93+
post_file_headers = headers.except('Content-Type') unless headers.nil?
94+
# Actual call with the altered headers
95+
call(:post, encode_uri(uri), timeout, post_file_headers, body)
96+
when :post_form
97+
form_post_headers = headers.except('Content-Type') unless headers.nil?
98+
call(:post, encode_uri(uri), timeout, form_post_headers, body.compact)
99+
else
100+
call(method, encode_uri(uri), timeout, headers, body.to_json)
101+
end
97102

98103
case result.code
99104
when 200...226 then safe_parse_json(result.body)
100105
when 400 then raise Auth0::BadRequest.new(result.body, code: result.code, headers: result.headers)
101106
when 401 then raise Auth0::Unauthorized.new(result.body, code: result.code, headers: result.headers)
102107
when 403 then raise Auth0::AccessDenied.new(result.body, code: result.code, headers: result.headers)
103108
when 404 then raise Auth0::NotFound.new(result.body, code: result.code, headers: result.headers)
104-
when 429 then raise Auth0::RateLimitEncountered.new(result.body, code: result.code, headers: result.headers)
109+
when 429 then raise Auth0::RateLimitEncountered.new(result.body, code: result.code,
110+
headers: result.headers)
105111
when 500 then raise Auth0::ServerError.new(result.body, code: result.code, headers: result.headers)
106112
else raise Auth0::Unsupported.new(result.body, code: result.code, headers: result.headers)
107113
end
@@ -118,11 +124,19 @@ def call(method, url, timeout, headers, body = nil)
118124
rescue RestClient::Exception => e
119125
case e
120126
when RestClient::RequestTimeout
121-
raise Auth0::RequestTimeout.new(e.message)
127+
raise Auth0::RequestTimeout, e.message
122128
else
123-
return e.response
129+
e.response
124130
end
125131
end
132+
133+
private
134+
135+
def safe_merge_body(body, extra = {})
136+
return body unless body.is_a?(Hash)
137+
merged = extra.any? ? body.merge(extra) : body
138+
merged.compact
139+
end
126140
end
127141
end
128142
end

0 commit comments

Comments
 (0)