auth0 5.0.1 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,5 +59,60 @@ describe Auth0::Api::V2::Tickets do
59
59
  new_password: nil)
60
60
  expect {@instance.post_password_change}.not_to raise_error
61
61
  end
62
+
63
+ it 'expect client to accept organization_id' do
64
+ expect(@instance).to receive(:post).with('/api/v2/tickets/password-change',
65
+ result_url: nil,
66
+ user_id: nil,
67
+ connection_id: nil,
68
+ email: nil,
69
+ ttl_sec: nil,
70
+ mark_email_as_verified: nil,
71
+ includeEmailInRedirect: nil,
72
+ new_password: nil,
73
+ client_id: '123',
74
+ organization_id: '999'
75
+ )
76
+ expect {
77
+ @instance.post_password_change(
78
+ result_url: nil,
79
+ user_id: nil,
80
+ connection_id: nil,
81
+ email: nil,
82
+ ttl_sec: nil,
83
+ mark_email_as_verified: nil,
84
+ includeEmailInRedirect: nil,
85
+ new_password: nil,
86
+ client_id: '123',
87
+ organization_id: '999')
88
+ }.not_to raise_error
89
+ end
90
+
91
+ it 'expect client to accept client_id' do
92
+ expect(@instance).to receive(:post).with('/api/v2/tickets/password-change',
93
+ result_url: nil,
94
+ user_id: nil,
95
+ connection_id: nil,
96
+ email: nil,
97
+ ttl_sec: nil,
98
+ mark_email_as_verified: nil,
99
+ includeEmailInRedirect: nil,
100
+ new_password: nil,
101
+ client_id: '123'
102
+ )
103
+ expect {
104
+ @instance.post_password_change(
105
+ result_url: nil,
106
+ user_id: nil,
107
+ connection_id: nil,
108
+ email: nil,
109
+ ttl_sec: nil,
110
+ mark_email_as_verified: nil,
111
+ includeEmailInRedirect: nil,
112
+ new_password: nil,
113
+ client_id: '123'
114
+ )
115
+ }.not_to raise_error
116
+ end
62
117
  end
63
118
  end
@@ -549,4 +549,23 @@ describe Auth0::Api::V2::Users do
549
549
  end.not_to raise_error
550
550
  end
551
551
  end
552
+
553
+ context '.get_user_organizations' do
554
+ it 'is expected to respond to a get_user_organizations method' do
555
+ expect(@instance).to respond_to(:get_user_organizations)
556
+ end
557
+
558
+ it 'is expected to raise an exception when the user ID is empty' do
559
+ expect { @instance.get_user_organizations(nil) }.to raise_exception(Auth0::MissingUserId)
560
+ end
561
+
562
+ it 'is expected to get users organizations' do
563
+ expect(@instance).to receive(:get).with(
564
+ '/api/v2/users/USER_ID/organizations'
565
+ )
566
+ expect do
567
+ @instance.get_user_organizations('USER_ID')
568
+ end.not_to raise_error
569
+ end
570
+ end
552
571
  end
@@ -29,7 +29,7 @@ describe Auth0::Client do
29
29
  let(:client_id) { '__test_client_id__' }
30
30
  let(:client_secret) { '__test_client_secret__' }
31
31
  let(:access_token) { '__test_access_token__' }
32
- let(:audience) { "https://#{domain}/api/v2/" }
32
+ let(:organization) { '__test_organization__'}
33
33
 
34
34
  describe 'V2 client with token' do
35
35
 
@@ -84,13 +84,12 @@ describe Auth0::Client do
84
84
  it_should_behave_like 'Authentication API client'
85
85
  end
86
86
 
87
- context 'with token, audience, and client_secret' do
87
+ context 'with token and client_secret' do
88
88
  let(:subject) do
89
89
  Auth0::Client.new(
90
90
  token: access_token,
91
91
  domain: domain,
92
92
  client_secret: client_secret,
93
- audience: audience
94
93
  )
95
94
  end
96
95
  it_should_behave_like 'v2 API client'
@@ -99,19 +98,53 @@ describe Auth0::Client do
99
98
  end
100
99
 
101
100
  describe 'V2 client without token' do
101
+ context 'should try to get an API token' do
102
+ before do
103
+ stub_api_token
104
+ end
102
105
 
103
- before do
104
- stub_api_token
106
+ let(:subject) do
107
+ Auth0::Client.new(
108
+ domain: domain,
109
+ client_id: client_id,
110
+ client_secret: client_secret,
111
+ )
112
+ end
113
+ it_should_behave_like 'v2 API client'
114
+ it_should_behave_like 'Authentication API client'
105
115
  end
106
116
 
107
- context 'should try to get an API token' do
117
+ context 'when try to get an API tokenwith api_identifier' do
118
+ let(:api_identifier) { 'https://samples.api_identifier/api/v2/' }
119
+
120
+ before do
121
+ stub_api_token_with_api_identifier
122
+ end
108
123
 
109
124
  let(:subject) do
110
125
  Auth0::Client.new(
111
126
  domain: domain,
112
127
  client_id: client_id,
113
128
  client_secret: client_secret,
114
- audience: audience
129
+ api_identifier: api_identifier
130
+ )
131
+ end
132
+
133
+ it_should_behave_like 'v2 API client'
134
+ it_should_behave_like 'Authentication API client'
135
+ end
136
+
137
+ context 'when try to get an API tokenwith organization' do
138
+ before do
139
+ stub_api_token_with_organization
140
+ end
141
+
142
+ let(:subject) do
143
+ Auth0::Client.new(
144
+ domain: domain,
145
+ client_id: client_id,
146
+ client_secret: client_secret,
147
+ organization: organization
115
148
  )
116
149
  end
117
150
  it_should_behave_like 'v2 API client'
@@ -125,7 +158,6 @@ describe Auth0::Client do
125
158
  Auth0::Client.new(
126
159
  domain: domain,
127
160
  client_id: client_id,
128
- audience: audience
129
161
  )
130
162
  end.to raise_error('Must supply a valid API token')
131
163
  end
@@ -140,7 +172,45 @@ describe Auth0::Client do
140
172
  grant_type: 'client_credentials',
141
173
  client_id: client_id,
142
174
  client_secret: client_secret,
143
- audience: audience
175
+ audience: "https://#{domain}/api/v2/"
176
+ }
177
+ )
178
+ )
179
+ .to_return(
180
+ headers: { 'Content-Type' => 'application/json' },
181
+ body: '{"access_token":"__test_access_token__"}',
182
+ status: 200
183
+ )
184
+ end
185
+
186
+ def stub_api_token_with_api_identifier
187
+ stub_request(:post, "https://#{domain}/oauth/token")
188
+ .with(
189
+ body: hash_including(
190
+ {
191
+ grant_type: 'client_credentials',
192
+ client_id: client_id,
193
+ client_secret: client_secret,
194
+ audience: api_identifier
195
+ }
196
+ )
197
+ )
198
+ .to_return(
199
+ headers: { 'Content-Type' => 'application/json' },
200
+ body: '{"access_token":"__test_access_token__"}',
201
+ status: 200
202
+ )
203
+ end
204
+
205
+ def stub_api_token_with_organization
206
+ stub_request(:post, "https://#{domain}/oauth/token")
207
+ .with(
208
+ body: hash_including(
209
+ {
210
+ grant_type: 'client_credentials',
211
+ client_id: client_id,
212
+ client_secret: client_secret,
213
+ organization: organization
144
214
  }
145
215
  )
146
216
  )
@@ -143,6 +143,12 @@ describe Auth0::Mixins::Validation::IdTokenValidator do
143
143
  expect { instance.validate(token) }.to raise_exception('Must supply a valid nonce')
144
144
  end
145
145
 
146
+ it 'is expected to raise an error with an empty organization' do
147
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: '' }))
148
+
149
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid organization')
150
+ end
151
+
146
152
  it 'is expected to raise an error with an empty issuer' do
147
153
  instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ issuer: '' }))
148
154
 
@@ -277,6 +283,32 @@ describe Auth0::Mixins::Validation::IdTokenValidator do
277
283
 
278
284
  expect { instance.validate(token) }.to raise_exception("Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time \"#{clock}\" is after last auth at \"#{auth_time}\"")
279
285
  end
286
+
287
+ it 'is expected not to raise an error when org_id exsist in the token, but not required' do
288
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE3ODgxLCJpYXQiOjE2MTY0NDUwODEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTQ4MSwib3JnX2lkIjoidGVzdE9yZyJ9.AOafUKUNgaxUXpSRYFCeJERcwrQZ4q2NZlutwGXnh9I'
289
+ expect { @instance.validate(token) }.not_to raise_exception
290
+ end
291
+
292
+ it 'is expected to raise an error with a missing but required organization' do
293
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE4MTg1LCJpYXQiOjE2MTY0NDUzODUsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTc4NX0.UMo5pmgceXO9lIKzbk7X0ZhE5DOe0IP2LfMKdUj03zQ'
294
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: 'a1b2c3d4e5' }))
295
+
296
+ expect { instance.validate(token) }.to raise_exception('Organization Id (org_id) claim must be a string present in the ID token')
297
+ end
298
+
299
+ it 'is expected to raise an error with an invalid organization' do
300
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE3ODgxLCJpYXQiOjE2MTY0NDUwODEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTQ4MSwib3JnX2lkIjoidGVzdE9yZyJ9.AOafUKUNgaxUXpSRYFCeJERcwrQZ4q2NZlutwGXnh9I'
301
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: 'a1b2c3d4e5' }))
302
+
303
+ expect { instance.validate(token) }.to raise_exception('Organization Id (org_id) claim value mismatch in the ID token; expected "a1b2c3d4e5", found "testOrg"')
304
+ end
305
+
306
+ it 'is expected to NOT raise an error with a valid organization' do
307
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE3ODgxLCJpYXQiOjE2MTY0NDUwODEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTQ4MSwib3JnX2lkIjoidGVzdE9yZyJ9.AOafUKUNgaxUXpSRYFCeJERcwrQZ4q2NZlutwGXnh9I'
308
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: 'testOrg' }))
309
+
310
+ expect { instance.validate(token) }.not_to raise_exception
311
+ end
280
312
  end
281
313
  end
282
314
 
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.0.1
4
+ version: 5.1.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: 2021-02-05 00:00:00.000000000 Z
14
+ date: 2021-04-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client
@@ -362,6 +362,7 @@ files:
362
362
  - lib/auth0/api/v2.rb
363
363
  - lib/auth0/api/v2/anomaly.rb
364
364
  - lib/auth0/api/v2/blacklists.rb
365
+ - lib/auth0/api/v2/branding.rb
365
366
  - lib/auth0/api/v2/client_grants.rb
366
367
  - lib/auth0/api/v2/clients.rb
367
368
  - lib/auth0/api/v2/connections.rb
@@ -371,6 +372,7 @@ files:
371
372
  - lib/auth0/api/v2/jobs.rb
372
373
  - lib/auth0/api/v2/log_streams.rb
373
374
  - lib/auth0/api/v2/logs.rb
375
+ - lib/auth0/api/v2/organizations.rb
374
376
  - lib/auth0/api/v2/prompts.rb
375
377
  - lib/auth0/api/v2/resource_servers.rb
376
378
  - lib/auth0/api/v2/roles.rb
@@ -583,6 +585,7 @@ files:
583
585
  - spec/integration/lib/auth0/auth0_client_spec.rb
584
586
  - spec/lib/auth0/api/v2/anomaly_spec.rb
585
587
  - spec/lib/auth0/api/v2/blacklists_spec.rb
588
+ - spec/lib/auth0/api/v2/branding_spec.rb
586
589
  - spec/lib/auth0/api/v2/client_grants_spec.rb
587
590
  - spec/lib/auth0/api/v2/clients_spec.rb
588
591
  - spec/lib/auth0/api/v2/connections_spec.rb
@@ -592,6 +595,7 @@ files:
592
595
  - spec/lib/auth0/api/v2/jobs_spec.rb
593
596
  - spec/lib/auth0/api/v2/log_streams_spec.rb
594
597
  - spec/lib/auth0/api/v2/logs_spec.rb
598
+ - spec/lib/auth0/api/v2/organizations_spec.rb
595
599
  - spec/lib/auth0/api/v2/prompts_spec.rb
596
600
  - spec/lib/auth0/api/v2/resource_servers_spec.rb
597
601
  - spec/lib/auth0/api/v2/roles_spec.rb
@@ -632,7 +636,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
632
636
  - !ruby/object:Gem::Version
633
637
  version: '0'
634
638
  requirements: []
635
- rubygems_version: 3.0.9
639
+ rubygems_version: 3.1.4
636
640
  signing_key:
637
641
  specification_version: 4
638
642
  summary: Auth0 API Client
@@ -826,6 +830,7 @@ test_files:
826
830
  - spec/integration/lib/auth0/auth0_client_spec.rb
827
831
  - spec/lib/auth0/api/v2/anomaly_spec.rb
828
832
  - spec/lib/auth0/api/v2/blacklists_spec.rb
833
+ - spec/lib/auth0/api/v2/branding_spec.rb
829
834
  - spec/lib/auth0/api/v2/client_grants_spec.rb
830
835
  - spec/lib/auth0/api/v2/clients_spec.rb
831
836
  - spec/lib/auth0/api/v2/connections_spec.rb
@@ -835,6 +840,7 @@ test_files:
835
840
  - spec/lib/auth0/api/v2/jobs_spec.rb
836
841
  - spec/lib/auth0/api/v2/log_streams_spec.rb
837
842
  - spec/lib/auth0/api/v2/logs_spec.rb
843
+ - spec/lib/auth0/api/v2/organizations_spec.rb
838
844
  - spec/lib/auth0/api/v2/prompts_spec.rb
839
845
  - spec/lib/auth0/api/v2/resource_servers_spec.rb
840
846
  - spec/lib/auth0/api/v2/roles_spec.rb