auth0 5.9.0 → 5.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -3
  3. data/.devcontainer/Dockerfile +19 -0
  4. data/.devcontainer/devcontainer.json +37 -0
  5. data/CHANGELOG.md +11 -0
  6. data/Gemfile +1 -0
  7. data/Gemfile.lock +28 -24
  8. data/auth0.gemspec +2 -2
  9. data/examples/ruby-api/Gemfile +3 -2
  10. data/examples/ruby-api/Gemfile.lock +32 -0
  11. data/examples/ruby-api/README.md +2 -2
  12. data/lib/auth0/api/v2/jobs.rb +15 -4
  13. data/lib/auth0/api/v2/organizations.rb +1 -1
  14. data/lib/auth0/mixins/httpproxy.rb +11 -12
  15. data/lib/auth0/mixins/token_management.rb +1 -1
  16. data/lib/auth0/version.rb +1 -1
  17. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_patch_client/should_update_the_client_with_the_correct_attributes.yml +2 -1
  18. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_update_connection/should_update_the_connection.yml +1 -1
  19. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_update_rule/should_update_the_disabled_rule_to_be_enabled.yml +1 -1
  20. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_revert_the_tenant_name.yml +1 -1
  21. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_update_the_tenant_settings_with_a_new_tenant_name.yml +1 -1
  22. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_roles/should_add_a_Role_to_a_User_successfully.yml +1 -1
  23. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_the_User_successfully.yml +1 -1
  24. data/spec/lib/auth0/api/v2/jobs_spec.rb +18 -0
  25. data/spec/lib/auth0/mixins/httpproxy_spec.rb +53 -17
  26. data/spec/lib/auth0/mixins/token_management_spec.rb +2 -7
  27. data/spec/spec_helper.rb +4 -0
  28. metadata +9 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d736435ce7655dc7910482e66b43a316a198b6b48ffa0b620830b7b55329dcb
4
- data.tar.gz: 1b653fb372276036ecc11df764317d5b2dbc08249dd5eaf78181b0982c8d1d84
3
+ metadata.gz: 40aab484c4f3864d285e116a837151c8e57872a9f879485bdf2433a926b4f668
4
+ data.tar.gz: 7affd4b6a58f93b73bfa66c8aea85c8064e14a0c74e692e8952223dfda8947a3
5
5
  SHA512:
6
- metadata.gz: 84c07d47e830c171210764f6cdf392f0a513b78a0996a9e9763d4a4aa069b8a56f4dab5930330e84efcefc68b16125d68e00c65c71cabbf82bc27bd0e5e56a56
7
- data.tar.gz: 27e7dce713e1859455806f9d1a90d86e9b3f9b2fdee1872ff1d1295924e162815995e9299b2d0e111d81622d6884b32b916d02b44ceff65ce13429963c87c336
6
+ metadata.gz: 68da74cb1dac1f68810babc29ceef1ea51d5ef16db4f462d728feb904e2734aae58882cf8a2e945710ccdd796d0c2957a378a42e36b2d3aeb0a286dd52604eae
7
+ data.tar.gz: 16a91e8033143986d95d8857c66f2642640df6b8416ab7e88f0478668336447c95fbf30fda20a058656cea7936ae1b36d376f99ade14953b10e25faa458de4bb
data/.circleci/config.yml CHANGED
@@ -6,9 +6,9 @@ orbs:
6
6
  matrix_ruby_versions: &matrix_ruby_versions
7
7
  matrix:
8
8
  parameters:
9
- ruby_version: ["2.5", "2.6", "2.7", "3.0"]
9
+ ruby_version: ["2.7", "3.0", "3.1"]
10
10
  # Default version of ruby to use for lint and publishing
11
- default_ruby_version: &default_ruby_version "2.7"
11
+ default_ruby_version: &default_ruby_version "3.1"
12
12
 
13
13
  executors:
14
14
  ruby-image:
@@ -30,7 +30,7 @@ jobs:
30
30
  ruby_version: << parameters.ruby_version >>
31
31
  steps:
32
32
  - checkout
33
- - run: gem install bundler:1.17.2
33
+ - run: gem install bundler:2.3.22
34
34
  - run: rm Gemfile.lock
35
35
  - restore_cache:
36
36
  key: gems-v2-{{ checksum "Gemfile.lock" }}
@@ -0,0 +1,19 @@
1
+ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ruby/.devcontainer/base.Dockerfile
2
+
3
+ # [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster
4
+ ARG VARIANT="3.1-bullseye"
5
+ FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
6
+
7
+ # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
8
+ ARG NODE_VERSION="none"
9
+ RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
10
+
11
+ # [Optional] Uncomment this section to install additional OS packages.
12
+ # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
13
+ # && apt-get -y install --no-install-recommends <your-package-list-here>
14
+
15
+ # [Optional] Uncomment this line to install additional gems.
16
+ # RUN gem install <your-gem-names-here>
17
+
18
+ # [Optional] Uncomment this line to install global node packages.
19
+ # RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
@@ -0,0 +1,37 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2
+ // https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/ruby
3
+ {
4
+ "name": "Ruby",
5
+ "build": {
6
+ "dockerfile": "Dockerfile",
7
+ "args": {
8
+ // Update 'VARIANT' to pick a Ruby version: 3, 3.1, 3.0, 2, 2.7
9
+ // Append -bullseye or -buster to pin to an OS version.
10
+ // Use -bullseye variants on local on arm64/Apple Silicon.
11
+ "VARIANT": "3.1",
12
+ // Options
13
+ "NODE_VERSION": "lts/*"
14
+ }
15
+ },
16
+
17
+ // Configure tool-specific properties.
18
+ "customizations": {
19
+ // Configure properties specific to VS Code.
20
+ "vscode": {
21
+ // Add the IDs of extensions you want installed when the container is created.
22
+ "extensions": [
23
+ "rebornix.Ruby"
24
+ ]
25
+ }
26
+ },
27
+
28
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
29
+ // "forwardPorts": [],
30
+
31
+ // Use 'postCreateCommand' to run commands after the container is created.
32
+ // "postCreateCommand": "ruby --version",
33
+
34
+ // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
35
+ "remoteUser": "vscode"
36
+
37
+ }
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Change Log
2
2
 
3
+ ## [v5.10.0](https://github.com/auth0/ruby-auth0/tree/v5.10.0) (2022-10-10)
4
+ [Full Changelog](https://github.com/auth0/ruby-auth0/compare/v5.9.0...v5.10.0)
5
+
6
+ **Changed**
7
+ - Update jwt ~2.5 [\#384](https://github.com/auth0/ruby-auth0/pull/384) ([stevehobbsdev](https://github.com/stevehobbsdev))
8
+
9
+ **Fixed**
10
+ - Stop :get, :delete parameters from bleeding into subsequent requests [\#388](https://github.com/auth0/ruby-auth0/pull/388) ([stevehobbsdev](https://github.com/stevehobbsdev))
11
+ - Support complex field names in export_users [\#387](https://github.com/auth0/ruby-auth0/pull/387) ([stevehobbsdev](https://github.com/stevehobbsdev))
12
+ - Reconfigure rate limiting exponential backoff [\#386](https://github.com/auth0/ruby-auth0/pull/386) ([stevehobbsdev](https://github.com/stevehobbsdev))
13
+
3
14
  ## [v5.9.0](https://github.com/auth0/ruby-auth0/tree/v5.9.0) (2022-08-24)
4
15
  [Full Changelog](https://github.com/auth0/ruby-auth0/compare/v5.8.1...v5.9.0)
5
16
 
data/Gemfile CHANGED
@@ -16,4 +16,5 @@ group :test do
16
16
  gem 'vcr', require: false
17
17
  gem 'simplecov-cobertura'
18
18
  gem 'timecop', require: false
19
+ gem 'pp'
19
20
  end
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- auth0 (5.9.0)
4
+ auth0 (5.10.0)
5
5
  addressable (~> 2.8)
6
- jwt (~> 2.3.0)
6
+ jwt (~> 2.5)
7
7
  rest-client (~> 2.1)
8
8
  retryable (~> 3.0)
9
9
  zache (~> 0.12)
@@ -11,20 +11,20 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- actionpack (7.0.3.1)
15
- actionview (= 7.0.3.1)
16
- activesupport (= 7.0.3.1)
14
+ actionpack (7.0.4)
15
+ actionview (= 7.0.4)
16
+ activesupport (= 7.0.4)
17
17
  rack (~> 2.0, >= 2.2.0)
18
18
  rack-test (>= 0.6.3)
19
19
  rails-dom-testing (~> 2.0)
20
20
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
21
- actionview (7.0.3.1)
22
- activesupport (= 7.0.3.1)
21
+ actionview (7.0.4)
22
+ activesupport (= 7.0.4)
23
23
  builder (~> 3.1)
24
24
  erubi (~> 1.4)
25
25
  rails-dom-testing (~> 2.0)
26
26
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
27
- activesupport (7.0.3.1)
27
+ activesupport (7.0.4)
28
28
  concurrent-ruby (~> 1.0, >= 1.0.2)
29
29
  i18n (>= 1.6, < 2)
30
30
  minitest (>= 5.1)
@@ -53,7 +53,7 @@ GEM
53
53
  dotenv (= 2.8.1)
54
54
  railties (>= 3.2)
55
55
  erubi (1.11.0)
56
- faker (2.22.0)
56
+ faker (2.23.0)
57
57
  i18n (>= 1.8.11, < 2)
58
58
  fuubar (2.5.1)
59
59
  rspec-core (~> 3.0)
@@ -66,11 +66,11 @@ GEM
66
66
  i18n (1.12.0)
67
67
  concurrent-ruby (~> 1.0)
68
68
  io-console (0.5.11)
69
- irb (1.4.1)
69
+ irb (1.4.2)
70
70
  reline (>= 0.3.0)
71
71
  json (2.6.2)
72
- jwt (2.3.0)
73
- loofah (2.18.0)
72
+ jwt (2.5.0)
73
+ loofah (2.19.0)
74
74
  crass (~> 1.0.2)
75
75
  nokogiri (>= 1.5.9)
76
76
  method_source (0.9.2)
@@ -85,6 +85,9 @@ GEM
85
85
  parallel (1.22.1)
86
86
  parser (3.1.2.1)
87
87
  ast (~> 2.4.1)
88
+ pp (0.3.0)
89
+ prettyprint
90
+ prettyprint (0.1.1)
88
91
  pry (0.12.2)
89
92
  coderay (~> 1.1.0)
90
93
  method_source (~> 0.9.0)
@@ -100,16 +103,16 @@ GEM
100
103
  nokogiri (>= 1.6)
101
104
  rails-html-sanitizer (1.4.3)
102
105
  loofah (~> 2.3)
103
- railties (7.0.3.1)
104
- actionpack (= 7.0.3.1)
105
- activesupport (= 7.0.3.1)
106
+ railties (7.0.4)
107
+ actionpack (= 7.0.4)
108
+ activesupport (= 7.0.4)
106
109
  method_source
107
110
  rake (>= 12.2)
108
111
  thor (~> 1.0)
109
112
  zeitwerk (~> 2.5)
110
113
  rainbow (3.1.1)
111
114
  rake (13.0.6)
112
- regexp_parser (2.5.0)
115
+ regexp_parser (2.6.0)
113
116
  reline (0.3.1)
114
117
  io-console (~> 0.5)
115
118
  rest-client (2.1.0)
@@ -125,14 +128,14 @@ GEM
125
128
  rspec-mocks (~> 3.11.0)
126
129
  rspec-core (3.11.0)
127
130
  rspec-support (~> 3.11.0)
128
- rspec-expectations (3.11.0)
131
+ rspec-expectations (3.11.1)
129
132
  diff-lcs (>= 1.2.0, < 2.0)
130
133
  rspec-support (~> 3.11.0)
131
134
  rspec-mocks (3.11.1)
132
135
  diff-lcs (>= 1.2.0, < 2.0)
133
136
  rspec-support (~> 3.11.0)
134
- rspec-support (3.11.0)
135
- rubocop (1.35.1)
137
+ rspec-support (3.11.1)
138
+ rubocop (1.36.0)
136
139
  json (~> 2.3)
137
140
  parallel (~> 1.10)
138
141
  parser (>= 3.1.2.1)
@@ -144,10 +147,10 @@ GEM
144
147
  unicode-display_width (>= 1.4.0, < 3.0)
145
148
  rubocop-ast (1.21.0)
146
149
  parser (>= 3.1.1.0)
147
- rubocop-rails (2.15.2)
150
+ rubocop-rails (2.16.1)
148
151
  activesupport (>= 4.2.0)
149
152
  rack (>= 1.1)
150
- rubocop (>= 1.7.0, < 2.0)
153
+ rubocop (>= 1.33.0, < 2.0)
151
154
  ruby-progressbar (1.11.0)
152
155
  simplecov (0.21.2)
153
156
  docile (~> 1.1)
@@ -170,14 +173,14 @@ GEM
170
173
  unf (0.1.4)
171
174
  unf_ext
172
175
  unf_ext (0.0.8.2)
173
- unicode-display_width (2.2.0)
176
+ unicode-display_width (2.3.0)
174
177
  vcr (6.1.0)
175
178
  webmock (3.18.1)
176
179
  addressable (>= 2.8.0)
177
180
  crack (>= 0.3.2)
178
181
  hashdiff (>= 0.4.0, < 2.0.0)
179
182
  zache (0.12.0)
180
- zeitwerk (2.6.0)
183
+ zeitwerk (2.6.1)
181
184
 
182
185
  PLATFORMS
183
186
  x86_64-linux
@@ -191,12 +194,13 @@ DEPENDENCIES
191
194
  fuubar (~> 2.0)
192
195
  gem-release (~> 0.7)
193
196
  irb
197
+ pp
194
198
  pry (~> 0.10)
195
199
  pry-nav (~> 0.2)
196
200
  rack (~> 2.1)
197
201
  rack-test (~> 0.6)
198
202
  rake (~> 13.0)
199
- rspec (~> 3.5)
203
+ rspec (~> 3.11)
200
204
  rubocop
201
205
  rubocop-rails
202
206
  simplecov (~> 0.9)
data/auth0.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ['lib']
18
18
 
19
19
  s.add_runtime_dependency 'rest-client', '~> 2.1'
20
- s.add_runtime_dependency 'jwt', '~> 2.3.0'
20
+ s.add_runtime_dependency 'jwt', '~> 2.5'
21
21
  s.add_runtime_dependency 'zache', '~> 0.12'
22
22
  s.add_runtime_dependency 'addressable', '~> 2.8'
23
23
  s.add_runtime_dependency 'retryable', '~> 3.0'
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency 'dotenv-rails', '~> 2.0'
30
30
  s.add_development_dependency 'pry', '~> 0.10'
31
31
  s.add_development_dependency 'pry-nav', '~> 0.2'
32
- s.add_development_dependency 'rspec', '~> 3.5'
32
+ s.add_development_dependency 'rspec', '~> 3.11'
33
33
  s.add_development_dependency 'rack-test', '~> 0.6'
34
34
  s.add_development_dependency 'rack', '~> 2.1'
35
35
  s.add_development_dependency 'simplecov', '~> 0.9'
@@ -3,6 +3,7 @@
3
3
  source 'http://rubygems.org'
4
4
 
5
5
  # gem "rails"
6
- gem 'sinatra', '~> 1.4'
7
- gem 'jwt', '~> 1.5'
6
+ gem 'sinatra', '~> 2.2'
7
+ gem 'jwt', '~> 2.5'
8
8
  gem 'dotenv'
9
+ gem 'puma'
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ dotenv (2.8.1)
5
+ jwt (2.5.0)
6
+ mustermann (2.0.2)
7
+ ruby2_keywords (~> 0.0.1)
8
+ nio4r (2.5.8)
9
+ puma (5.6.5)
10
+ nio4r (~> 2.0)
11
+ rack (2.2.4)
12
+ rack-protection (2.2.2)
13
+ rack
14
+ ruby2_keywords (0.0.5)
15
+ sinatra (2.2.2)
16
+ mustermann (~> 2.0)
17
+ rack (~> 2.2)
18
+ rack-protection (= 2.2.2)
19
+ tilt (~> 2.0)
20
+ tilt (2.0.11)
21
+
22
+ PLATFORMS
23
+ aarch64-linux
24
+
25
+ DEPENDENCIES
26
+ dotenv
27
+ jwt (~> 2.5)
28
+ puma
29
+ sinatra (~> 2.2)
30
+
31
+ BUNDLED WITH
32
+ 2.3.7
@@ -1,8 +1,8 @@
1
- #Auth0 + Ruby API Seed
1
+ # Auth0 + Ruby API Seed
2
2
 
3
3
  This is the seed project you need to use if you're going to create a Ruby API. You'll mostly use this API either for a SPA or a Mobile app.
4
4
 
5
- #Running the example
5
+ # Running the example
6
6
 
7
7
  In order to run the example you need to have ruby installed.
8
8
 
@@ -60,6 +60,9 @@ module Auth0
60
60
  # :format [string] The format of the file. Valid values are: "json" and "csv".
61
61
  # :limit [integer] Limit the number of users to export.
62
62
  # :fields [array] A list of fields to be included in the CSV.
63
+ # This can either be an array of strings representing field names, or an object.
64
+ # If it's a string, it is mapped to the correct { name: '<field name>' } object required by the endpoint.
65
+ # If it's an object, it is passed through as-is to the endpoint.
63
66
  # If omitted, a set of predefined fields will be exported.
64
67
  #
65
68
  # @return [json] Returns the job status and properties.
@@ -109,14 +112,22 @@ module Auth0
109
112
  @jobs_path ||= '/api/v2/jobs'
110
113
  end
111
114
 
112
- # Map array of field names for export to array of objects
113
- # @param fields [array] Field names to be included in the export
114
-
115
+ # Map array of fields for export to array of objects
116
+ # @param fields [array] Fields to be included in the export
117
+ # This can either be an array of strings representing field names, or an object.
118
+ # If it's a string, it is mapped to the correct { name: '<field name>' } object required by the endpoint.
119
+ # If it's an object, it is passed through as-is to the endpoint.
115
120
  # @return [array] Returns the fields mapped as array of objects for the export_users endpoint
116
121
  def fields_for_export(fields)
117
122
  return nil if fields.to_s.empty?
118
123
 
119
- fields.map { |field| { name: field } }
124
+ fields.map { |field|
125
+ if field.is_a? String
126
+ { name: field }
127
+ else
128
+ field
129
+ end
130
+ }
120
131
  end
121
132
  end
122
133
  end
@@ -9,7 +9,7 @@ module Auth0
9
9
 
10
10
  # Get all organizations.
11
11
  # @see https://auth0.com/docs/api/management/v2/#!/Organizations/get_organizations
12
- # @param options [hash] The Hash options used to define the paging of rersults
12
+ # @param options [hash] The Hash options used to define the paging of results
13
13
  # * :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
14
14
  # * :page [integer] The page number. Zero based.
15
15
  # * :from [string] For checkpoint pagination, the ID from which to start selection from.
@@ -8,11 +8,12 @@ module Auth0
8
8
  # for now, if you want to feel free to use your own http client
9
9
  module HTTPProxy
10
10
  attr_accessor :headers, :base_uri, :timeout, :retry_count
11
- DEAFULT_RETRIES = 3
11
+ DEFAULT_RETRIES = 3
12
12
  MAX_ALLOWED_RETRIES = 10
13
13
  MAX_REQUEST_RETRY_JITTER = 250
14
14
  MAX_REQUEST_RETRY_DELAY = 1000
15
- MIN_REQUEST_RETRY_DELAY = 100
15
+ MIN_REQUEST_RETRY_DELAY = 250
16
+ BASE_DELAY = 100
16
17
 
17
18
  # proxying requests from instance methods to HTTP class methods
18
19
  %i(get post post_file put patch delete delete_with_body).each do |method|
@@ -26,14 +27,14 @@ module Auth0
26
27
 
27
28
  def retry_options
28
29
  sleep_timer = lambda do |attempt|
29
- wait = 1000 * 2**attempt # Exponential delay with each subsequent request attempt.
30
- wait += rand(wait..wait+MAX_REQUEST_RETRY_JITTER) # Add jitter to the delay window.
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.
31
32
  wait = [MAX_REQUEST_RETRY_DELAY, wait].min # Cap delay at MAX_REQUEST_RETRY_DELAY.
32
33
  wait = [MIN_REQUEST_RETRY_DELAY, wait].max # Ensure delay is no less than MIN_REQUEST_RETRY_DELAY.
33
34
  wait / 1000.to_f.round(2) # convert ms to seconds
34
35
  end
35
36
 
36
- tries = 1 + [Integer(retry_count || DEAFULT_RETRIES), MAX_ALLOWED_RETRIES].min # Cap retries at MAX_ALLOWED_RETRIES
37
+ tries = 1 + [Integer(retry_count || DEFAULT_RETRIES), MAX_ALLOWED_RETRIES].min # Cap retries at MAX_ALLOWED_RETRIES
37
38
 
38
39
  {
39
40
  tries: tries,
@@ -72,15 +73,13 @@ module Auth0
72
73
 
73
74
  def request(method, uri, body = {}, extra_headers = {})
74
75
  result = if method == :get
75
- # Mutate the headers property to add parameters.
76
- add_headers({params: body})
77
- # Merge custom headers into existing ones for this req.
78
- # This prevents future calls from using them.
79
- get_headers = headers.merge extra_headers
80
- # Make the call with extra_headers, if provided.
76
+ @headers ||= {}
77
+ get_headers = @headers.merge({params: body}).merge(extra_headers)
81
78
  call(:get, encode_uri(uri), timeout, get_headers)
82
79
  elsif method == :delete
83
- call(:delete, encode_uri(uri), timeout, add_headers({params: body}))
80
+ @headers ||= {}
81
+ delete_headers = @headers.merge({ params: body })
82
+ call(:delete, encode_uri(uri), timeout, delete_headers)
84
83
  elsif method == :delete_with_body
85
84
  call(:delete, encode_uri(uri), timeout, headers, body.to_json)
86
85
  elsif method == :post_file
@@ -6,7 +6,6 @@ module Auth0
6
6
 
7
7
  def initialize_token(options)
8
8
  @token = options[:access_token] || options[:token]
9
-
10
9
  # default expiry to an hour if a token was given but no expires_at
11
10
  @token_expires_at = @token ? options[:token_expires_at] || Time.now.to_i + 3600 : nil
12
11
 
@@ -15,6 +14,7 @@ module Auth0
15
14
  end
16
15
 
17
16
  def get_token
17
+ # pp @token_expires_at
18
18
  has_expired = @token && @token_expires_at ? @token_expires_at < (Time.now.to_i + 10) : false
19
19
 
20
20
  if (@token.nil? || has_expired) && @client_id && @client_secret
data/lib/auth0/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # current version of gem
2
2
  module Auth0
3
- VERSION = '5.9.0'.freeze
3
+ VERSION = '5.10.0'.freeze
4
4
  end
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: patch
5
- uri: https://auth0-sdk-tests.auth0.com/api/v2/clients/SftKo9ySyHnMPezQUFd0C70GBoNFM21F?fields=jwt_configuration&include_fields=false
5
+ uri: https://auth0-sdk-tests.auth0.com/api/v2/clients/SftKo9ySyHnMPezQUFd0C70GBoNFM21F
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"custom_login_page_on":false,"sso":true}'
@@ -12,6 +12,7 @@ http_interactions:
12
12
  User-Agent:
13
13
  - rest-client/2.1.0 (darwin19.6.0 x86_64) ruby/2.7.0p0
14
14
  Content-Type:
15
+
15
16
  - application/json
16
17
  Auth0-Client:
17
18
  - eyJuYW1lIjoicnVieS1hdXRoMCIsInZlcnNpb24iOiI1LjUuMCIsImVudiI6eyJydWJ5IjoiMi43LjAifX0=
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: patch
5
- uri: https://auth0-sdk-tests.auth0.com/api/v2/connections/con_WltM0fv20JCnxOuY?email=rubytest-210908-rubytest-210908-username@auth0.com
5
+ uri: https://auth0-sdk-tests.auth0.com/api/v2/connections/con_WltM0fv20JCnxOuY
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"options":{"mfa":{"active":true,"return_enroll_settings":true},"passwordPolicy":"excellent","strategy_version":2,"brute_force_protection":true}}'
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: patch
5
- uri: https://auth0-sdk-tests.auth0.com/api/v2/rules/rul_bsg64xEPZz4WOkXz?fields=stage&include_fields=false
5
+ uri: https://auth0-sdk-tests.auth0.com/api/v2/rules/rul_bsg64xEPZz4WOkXz
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"enabled":true}'
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: patch
5
- uri: https://auth0-sdk-tests.auth0.com/api/v2/tenants/settings?fields=support_email&include_fields=true
5
+ uri: https://auth0-sdk-tests.auth0.com/api/v2/tenants/settings
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"friendly_name":"Auth0"}'
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: patch
5
- uri: https://auth0-sdk-tests.auth0.com/api/v2/tenants/settings?fields=support_email&include_fields=true
5
+ uri: https://auth0-sdk-tests.auth0.com/api/v2/tenants/settings
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"friendly_name":"Auth0-CHANGED"}'
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: https://auth0-sdk-tests.auth0.com/api/v2/users/auth0%7C613282adac819400692c0dd9/roles?per_page=2
5
+ uri: https://auth0-sdk-tests.auth0.com/api/v2/users/auth0%7C613282adac819400692c0dd9/roles
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"roles":["rol_2VZOCes8HgBar3Tp"]}'
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: patch
5
- uri: https://auth0-sdk-tests.auth0.com/api/v2/users/auth0%7C613282adac819400692c0dd9?fields=email&include_fields=true
5
+ uri: https://auth0-sdk-tests.auth0.com/api/v2/users/auth0%7C613282adac819400692c0dd9
6
6
  body:
7
7
  encoding: UTF-8
8
8
  string: '{"email_verified":true,"user_metadata":{"addresses":{"home_address":"742
@@ -67,6 +67,7 @@ describe Auth0::Api::V2::Jobs do
67
67
  format: 'csv',
68
68
  limit: 10
69
69
  })
70
+
70
71
  @instance.export_users(
71
72
  fields: ['author'],
72
73
  connection_id: 'test-connection',
@@ -74,6 +75,23 @@ describe Auth0::Api::V2::Jobs do
74
75
  limit: 10
75
76
  )
76
77
  end
78
+
79
+ it 'sends post to /api/v2/jobs/users-exports with export_as field' do
80
+ expect(@instance).to receive(:post).with(
81
+ '/api/v2/jobs/users-exports', {
82
+ fields: [{ name: 'author', export_as: 'writer' }],
83
+ connection_id: 'test-connection',
84
+ format: 'csv',
85
+ limit: 10
86
+ })
87
+
88
+ @instance.export_users(
89
+ fields: [{ name: 'author', export_as: 'writer' }],
90
+ connection_id: 'test-connection',
91
+ format: 'csv',
92
+ limit: 10
93
+ )
94
+ end
77
95
  end
78
96
 
79
97
  context '.send_verification_email' do
@@ -494,12 +494,13 @@ describe Auth0::Mixins::HTTPProxy do
494
494
  end
495
495
 
496
496
  context "Renewing tokens" do
497
- before :each do
498
- @token_instance = DummyClassForTokens.new(
497
+ let(:httpproxy_instance) {
498
+ DummyClassForTokens.new(
499
499
  client_id: 'test-client-id',
500
500
  client_secret: 'test-client-secret',
501
- domain: 'auth0.com')
502
- end
501
+ domain: 'auth0.com',
502
+ )
503
+ }
503
504
 
504
505
  %i(get delete).each do |http_method|
505
506
  context "for #{http_method}" do
@@ -507,7 +508,7 @@ describe Auth0::Mixins::HTTPProxy do
507
508
  expect(RestClient::Request).to receive(:execute).with(hash_including(
508
509
  method: :post,
509
510
  url: 'https://auth0.com/oauth/token',
510
- ) ).and_return(StubResponse.new({
511
+ )).and_return(StubResponse.new({
511
512
  "access_token" => "access_token",
512
513
  "expires_in" => 86400},
513
514
  true,
@@ -515,11 +516,10 @@ describe Auth0::Mixins::HTTPProxy do
515
516
 
516
517
  expect(RestClient::Request).to receive(:execute).with(hash_including(
517
518
  method: http_method,
518
- url: 'https://auth0.com/test',
519
- headers: { params: {}, "Authorization" => "Bearer access_token" }
519
+ url: 'https://auth0.com/test'
520
520
  )).and_return(StubResponse.new('Some random text here', true, 200))
521
521
 
522
- expect { @token_instance.send(http_method, '/test') }.not_to raise_error
522
+ expect { httpproxy_instance.send(http_method, '/test') }.not_to raise_error
523
523
  end
524
524
  end
525
525
  end
@@ -539,24 +539,24 @@ describe Auth0::Mixins::HTTPProxy do
539
539
  expect(RestClient::Request).to receive(:execute).with(hash_including(
540
540
  method: http_method,
541
541
  url: 'https://auth0.com/test',
542
- headers: { "Authorization" => "Bearer access_token" }
542
+ headers: hash_including( "Authorization" => "Bearer access_token")
543
543
  )).and_return(StubResponse.new('Some random text here', true, 200))
544
544
 
545
- expect { @token_instance.send(http_method, '/test') }.not_to raise_error
545
+ expect { httpproxy_instance.send(http_method, '/test') }.not_to raise_error
546
546
  end
547
547
  end
548
548
  end
549
549
  end
550
550
 
551
551
  context "Using cached tokens" do
552
- before :each do
553
- @token_instance = DummyClassForTokens.new(
552
+ let(:httpproxy_instance) {
553
+ DummyClassForTokens.new(
554
554
  client_id: 'test-client-id',
555
555
  client_secret: 'test-client-secret',
556
556
  domain: 'auth0.com',
557
557
  token: 'access_token',
558
558
  token_expires_at: Time.now.to_i + 86400)
559
- end
559
+ }
560
560
 
561
561
  %i(get delete).each do |http_method|
562
562
  context "for #{http_method}" do
@@ -569,10 +569,10 @@ describe Auth0::Mixins::HTTPProxy do
569
569
  expect(RestClient::Request).to receive(:execute).with(hash_including(
570
570
  method: http_method,
571
571
  url: 'https://auth0.com/test',
572
- headers: { params: {}, "Authorization" => "Bearer access_token" }
572
+ headers: hash_including(params: {}, "Authorization" => "Bearer access_token")
573
573
  )).and_return(StubResponse.new('Some random text here', true, 200))
574
574
 
575
- expect { @token_instance.send(http_method, '/test') }.not_to raise_error
575
+ expect { httpproxy_instance.send(http_method, '/test') }.not_to raise_error
576
576
  end
577
577
  end
578
578
  end
@@ -588,10 +588,46 @@ describe Auth0::Mixins::HTTPProxy do
588
588
  expect(RestClient::Request).to receive(:execute).with(hash_including(
589
589
  method: http_method,
590
590
  url: 'https://auth0.com/test',
591
- headers: { "Authorization" => "Bearer access_token" }
591
+ headers: hash_including("Authorization" => "Bearer access_token")
592
592
  )).and_return(StubResponse.new('Some random text here', true, 200))
593
593
 
594
- expect { @token_instance.send(http_method, '/test') }.not_to raise_error
594
+ expect { httpproxy_instance.send(http_method, '/test') }.not_to raise_error
595
+ end
596
+ end
597
+ end
598
+ end
599
+
600
+ context 'Normal operation' do
601
+ let(:httpproxy_instance) {
602
+ DummyClassForTokens.new(
603
+ client_id: 'test-client-id',
604
+ client_secret: 'test-client-secret',
605
+ domain: 'auth0.com',
606
+ token: 'access_token',
607
+ token_expires_at: Time.now.to_i + 86400)
608
+ }
609
+
610
+ # This sets up a test matrix to verify that both :get and :delete calls (the only two HTTP methods in the proxy that mutated headers)
611
+ # don't bleed query params into subsequent calls to :post :patch and :put.
612
+ %i(get delete).each do |http_get_delete|
613
+ %i(post patch put).each do |http_ppp|
614
+ it "should not bleed :#{http_get_delete} headers/parameters to the subsequent :#{http_ppp} request" do
615
+ expect(RestClient::Request).to receive(:execute).with(hash_including(
616
+ method: http_get_delete,
617
+ url: "https://auth0.com/test-#{http_get_delete}",
618
+ headers: hash_including(params: { email: 'test@test.com' })
619
+ )).and_return(StubResponse.new('OK', true, 200))
620
+
621
+ # email: parameter that is sent in the GET request should not appear
622
+ # as a parameter in the `headers` hash for the subsequent PATCH request.
623
+ expect(RestClient::Request).to receive(:execute).with(hash_including(
624
+ method: http_ppp,
625
+ url: "https://auth0.com/test-#{http_ppp}",
626
+ headers: hash_not_including(:params)
627
+ )).and_return(StubResponse.new('OK', true, 200))
628
+
629
+ expect { httpproxy_instance.send(http_get_delete, "/test-#{http_get_delete}", { email: 'test@test.com' }) }.not_to raise_error
630
+ expect { httpproxy_instance.send(http_ppp, "/test-#{http_ppp}") }.not_to raise_error
595
631
  end
596
632
  end
597
633
  end
@@ -110,16 +110,11 @@ describe Auth0::Mixins::TokenManagement do
110
110
 
111
111
  it 'does not renew existing token if no token_expires_at' do
112
112
  params[:token] = 'test-token'
113
+ instance.instance_variable_set '@token_expires_at', nil
113
114
 
114
- expect(RestClient::Request).not_to receive(:execute).with(hash_including(
115
- method: :post,
116
- url: 'https://samples.auth0.com/oauth/token',
117
- ))
115
+ expect(RestClient::Request).not_to receive(:execute)
118
116
 
119
117
  instance.send(:get_token)
120
-
121
- expect(instance.instance_variable_get('@token')).to eq('test-token')
122
- expect(instance.instance_variable_get('@token_expires_at')).to be_nil
123
118
  end
124
119
  end
125
120
  end
data/spec/spec_helper.rb CHANGED
@@ -51,6 +51,10 @@ RSpec.configure do |config|
51
51
  config.filter_run focus: true
52
52
  config.run_all_when_everything_filtered = true
53
53
  config.include Credentials
54
+
55
+ config.expect_with :rspec do |c|
56
+ c.max_formatted_output_length = 1000000
57
+ end
54
58
  end
55
59
 
56
60
  def wait(time, increment = 5, elapsed_time = 0, &block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auth0
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.9.0
4
+ version: 5.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Auth0
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2022-08-24 00:00:00.000000000 Z
14
+ date: 2022-10-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client
@@ -33,14 +33,14 @@ dependencies:
33
33
  requirements:
34
34
  - - "~>"
35
35
  - !ruby/object:Gem::Version
36
- version: 2.3.0
36
+ version: '2.5'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
- version: 2.3.0
43
+ version: '2.5'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: zache
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -173,14 +173,14 @@ dependencies:
173
173
  requirements:
174
174
  - - "~>"
175
175
  - !ruby/object:Gem::Version
176
- version: '3.5'
176
+ version: '3.11'
177
177
  type: :development
178
178
  prerelease: false
179
179
  version_requirements: !ruby/object:Gem::Requirement
180
180
  requirements:
181
181
  - - "~>"
182
182
  - !ruby/object:Gem::Version
183
- version: '3.5'
183
+ version: '3.11'
184
184
  - !ruby/object:Gem::Dependency
185
185
  name: rack-test
186
186
  requirement: !ruby/object:Gem::Requirement
@@ -260,6 +260,8 @@ extra_rdoc_files: []
260
260
  files:
261
261
  - ".bundle/config"
262
262
  - ".circleci/config.yml"
263
+ - ".devcontainer/Dockerfile"
264
+ - ".devcontainer/devcontainer.json"
263
265
  - ".env.example"
264
266
  - ".gemrelease"
265
267
  - ".github/CODEOWNERS"
@@ -291,6 +293,7 @@ files:
291
293
  - examples/ruby-api/.env.example
292
294
  - examples/ruby-api/.gitignore
293
295
  - examples/ruby-api/Gemfile
296
+ - examples/ruby-api/Gemfile.lock
294
297
  - examples/ruby-api/README.md
295
298
  - examples/ruby-api/config.ru
296
299
  - examples/ruby-api/main.rb